WinFuture-Forum.de: Wie Funktioniert On_message() Bzw. Event-handler? - WinFuture-Forum.de

Zum Inhalt wechseln

Nachrichten zum Thema: Entwicklung
Seite 1 von 1

Wie Funktioniert On_message() Bzw. Event-handler?


#1 Mitglied ist offline   Hans_Wurst 

  • Gruppe: Mitglieder
  • Beiträge: 4
  • Beigetreten: 26. April 08
  • Reputation: 0

geschrieben 26. April 2008 - 16:26

Hallo,

ich versuche nun seit Tagen ein Programm zu erstellen, welches mir kontinuierlich die Position eines Joysticks anzeigt. Ich kann sie erfolgreich (jedoch nur einmal) lesen und gebe die Werte (mit Visual Studio C++) an ein Fenster aus.

Kann mir jemand sagen wie ich die Positionen in meinem Programm kontinuierlich auslesen kann? Ich habe gelesen dass man da wohl „Message-Funktionen“ verwendet (welche mir sagen dass der Joystick eine neue Position hat). Ich weiß jedoch nicht wie ich sie ohne Fehlermeldung in meinem Code integrieren kann.
0

Anzeige



#2 Mitglied ist offline   ph030 

  • Gruppe: aktive Mitglieder
  • Beiträge: 5.132
  • Beigetreten: 14. Juli 04
  • Reputation: 36
  • Geschlecht:unbekannt

geschrieben 26. April 2008 - 17:05

Wie sieht denn der momentane Code aus und funktioniert es nicht, wenn du diesen immer wieder mittels einer while-Schleife abrufst?
0

#3 Mitglied ist offline   Hans_Wurst 

  • Gruppe: Mitglieder
  • Beiträge: 4
  • Beigetreten: 26. April 08
  • Reputation: 0

geschrieben 26. April 2008 - 17:18

Wenn ich eine Schleife mache, bringt er mir eine weiter Fehlermeldung. Im nachhinein gesehen ist das vielleicht auch ganz sinnvoll, da der PC sonst ununterbrochen diese Schleife durchlaufen würde und nichts anderes mehr machen können. Ein Ereignis-gesteuertes Programm ist da wohl ganz gut.
0

#4 Mitglied ist offline   Hans_Wurst 

  • Gruppe: Mitglieder
  • Beiträge: 4
  • Beigetreten: 26. April 08
  • Reputation: 0

geschrieben 26. April 2008 - 17:26

Hallo ph030,

da ich in C++ noch recht unerfahren bin und sicher oft nicht weiß was eigentlich wirklich die Problemstelle ist, habe ich mal den Code mit angehängt. Vielleicht ist es dann leichter mir zu helfen. (wofür ich wirklich sehr dankbar wäre)

#include <windows.h>			// enthält die Joystick-Funktionen
#include <mmSystem.h>			// enthält auch Joystick-Funktionen?
#include <iostream>
#include "Joystick.h"
//#include <afxmsg_.h>			// für	ON_MESSAGE() ?
using namespace std;

#pragma once
#pragma comment(lib,"winmm.lib")	// fügt die Libary winmm.lib mit ein. Benötigt für Joystick-Funktionen


long CALLBACK WndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, char* szCommandLine, int nShowMode)
{
    return 0;
}

long CALLBACK WndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
        return DefWindowProc(hWnd, nMsg, wParam, lParam);
}


namespace carcontrol {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Zusammenfassung für Form1
	///
	/// Warnung: Wenn Sie den Namen dieser Klasse ändern, müssen Sie auch
	///          die Ressourcendateiname-Eigenschaft für das Tool zur Kompilierung verwalteter Ressourcen ändern,
	///          das allen RESX-Dateien zugewiesen ist, von denen diese Klasse abhängt.
	///          Anderenfalls können die Designer nicht korrekt mit den lokalisierten Ressourcen
	///          arbeiten, die diesem Formular zugewiesen sind.
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Konstruktorcode hier hinzufügen.
			//
		}

	protected:
		/// <summary>
		/// Verwendete Ressourcen bereinigen.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::GroupBox^  groupBox1;
	private: System::Windows::Forms::LinkLabel^  linkLabelButtonNumber;


	private: System::Windows::Forms::TextBox^  textBoxButtonNumber;

	private: System::Windows::Forms::LinkLabel^  linkLabelZPosition;
	private: System::Windows::Forms::LinkLabel^  linkLabelYPosition;
	private: System::Windows::Forms::LinkLabel^  linkLabelXPosition;
	private: System::Windows::Forms::LinkLabel^  linkLabelVPosition;
	private: System::Windows::Forms::LinkLabel^  linkLabelUPosition;
	private: System::Windows::Forms::LinkLabel^  linkLabelRuderPosition;
	private: System::Windows::Forms::LinkLabel^  linkLabelPointOfView;
	private: System::Windows::Forms::LinkLabel^  linkLabelButtons;
	private: System::Windows::Forms::TextBox^  textBoxZPosition;

	private: System::Windows::Forms::TextBox^  textBoxYPosition;

	private: System::Windows::Forms::TextBox^  textBoxXPosition;

	private: System::Windows::Forms::TextBox^  textBoxVPosition;

	private: System::Windows::Forms::TextBox^  textBoxUPosition;

	private: System::Windows::Forms::TextBox^  textBoxRudderPosition;

	private: System::Windows::Forms::TextBox^  textBoxPointOfView;

	private: System::Windows::Forms::TextBox^  textBoxButtons;
	private: System::Windows::Forms::Button^  btnEvent;

	private: System::Windows::Forms::Button^  btnEnde;



	protected: 

	private:
		/// <summary>
		/// Erforderliche Designervariable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Erforderliche Methode für die Designerunterstützung.
		/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
		/// </summary>
		void InitializeComponent(void)
		{
			this->groupBox1 = (gcnew System::Windows::Forms::GroupBox());
			this->linkLabelZPosition = (gcnew System::Windows::Forms::LinkLabel());
			this->linkLabelYPosition = (gcnew System::Windows::Forms::LinkLabel());
			this->linkLabelXPosition = (gcnew System::Windows::Forms::LinkLabel());
			this->linkLabelVPosition = (gcnew System::Windows::Forms::LinkLabel());
			this->linkLabelUPosition = (gcnew System::Windows::Forms::LinkLabel());
			this->linkLabelRuderPosition = (gcnew System::Windows::Forms::LinkLabel());
			this->linkLabelPointOfView = (gcnew System::Windows::Forms::LinkLabel());
			this->linkLabelButtons = (gcnew System::Windows::Forms::LinkLabel());
			this->linkLabelButtonNumber = (gcnew System::Windows::Forms::LinkLabel());
			this->textBoxZPosition = (gcnew System::Windows::Forms::TextBox());
			this->textBoxYPosition = (gcnew System::Windows::Forms::TextBox());
			this->textBoxXPosition = (gcnew System::Windows::Forms::TextBox());
			this->textBoxVPosition = (gcnew System::Windows::Forms::TextBox());
			this->textBoxUPosition = (gcnew System::Windows::Forms::TextBox());
			this->textBoxRudderPosition = (gcnew System::Windows::Forms::TextBox());
			this->textBoxPointOfView = (gcnew System::Windows::Forms::TextBox());
			this->textBoxButtons = (gcnew System::Windows::Forms::TextBox());
			this->textBoxButtonNumber = (gcnew System::Windows::Forms::TextBox());
			this->btnEvent = (gcnew System::Windows::Forms::Button());
			this->btnEnde = (gcnew System::Windows::Forms::Button());
			this->groupBox1->SuspendLayout();
			this->SuspendLayout();
			// 
			// groupBox1
			// 
			this->groupBox1->Controls->Add(this->linkLabelZPosition);
			this->groupBox1->Controls->Add(this->linkLabelYPosition);
			this->groupBox1->Controls->Add(this->linkLabelXPosition);
			this->groupBox1->Controls->Add(this->linkLabelVPosition);
			this->groupBox1->Controls->Add(this->linkLabelUPosition);
			this->groupBox1->Controls->Add(this->linkLabelRuderPosition);
			this->groupBox1->Controls->Add(this->linkLabelPointOfView);
			this->groupBox1->Controls->Add(this->linkLabelButtons);
			this->groupBox1->Controls->Add(this->linkLabelButtonNumber);
			this->groupBox1->Controls->Add(this->textBoxZPosition);
			this->groupBox1->Controls->Add(this->textBoxYPosition);
			this->groupBox1->Controls->Add(this->textBoxXPosition);
			this->groupBox1->Controls->Add(this->textBoxVPosition);
			this->groupBox1->Controls->Add(this->textBoxUPosition);
			this->groupBox1->Controls->Add(this->textBoxRudderPosition);
			this->groupBox1->Controls->Add(this->textBoxPointOfView);
			this->groupBox1->Controls->Add(this->textBoxButtons);
			this->groupBox1->Controls->Add(this->textBoxButtonNumber);
			this->groupBox1->Location = System::Drawing::Point(12, 12);
			this->groupBox1->Name = L"groupBox1";
			this->groupBox1->Size = System::Drawing::Size(756, 68);
			this->groupBox1->TabIndex = 0;
			this->groupBox1->TabStop = false;
			this->groupBox1->Text = L"groupBox1";
			// 
			// linkLabelZPosition
			// 
			this->linkLabelZPosition->AutoSize = true;
			this->linkLabelZPosition->Location = System::Drawing::Point(668, 23);
			this->linkLabelZPosition->Name = L"linkLabelZPosition";
			this->linkLabelZPosition->Size = System::Drawing::Size(54, 13);
			this->linkLabelZPosition->TabIndex = 1;
			this->linkLabelZPosition->TabStop = true;
			this->linkLabelZPosition->Text = L"Z Position";
			// 
			// linkLabelYPosition
			// 
			this->linkLabelYPosition->AutoSize = true;
			this->linkLabelYPosition->Location = System::Drawing::Point(585, 23);
			this->linkLabelYPosition->Name = L"linkLabelYPosition";
			this->linkLabelYPosition->Size = System::Drawing::Size(54, 13);
			this->linkLabelYPosition->TabIndex = 1;
			this->linkLabelYPosition->TabStop = true;
			this->linkLabelYPosition->Text = L"Y Position";
			// 
			// linkLabelXPosition
			// 
			this->linkLabelXPosition->AutoSize = true;
			this->linkLabelXPosition->Location = System::Drawing::Point(502, 23);
			this->linkLabelXPosition->Name = L"linkLabelXPosition";
			this->linkLabelXPosition->Size = System::Drawing::Size(54, 13);
			this->linkLabelXPosition->TabIndex = 1;
			this->linkLabelXPosition->TabStop = true;
			this->linkLabelXPosition->Text = L"X Position";
			// 
			// linkLabelVPosition
			// 
			this->linkLabelVPosition->AutoSize = true;
			this->linkLabelVPosition->Location = System::Drawing::Point(419, 23);
			this->linkLabelVPosition->Name = L"linkLabelVPosition";
			this->linkLabelVPosition->Size = System::Drawing::Size(54, 13);
			this->linkLabelVPosition->TabIndex = 1;
			this->linkLabelVPosition->TabStop = true;
			this->linkLabelVPosition->Text = L"V Position";
			// 
			// linkLabelUPosition
			// 
			this->linkLabelUPosition->AutoSize = true;
			this->linkLabelUPosition->Location = System::Drawing::Point(336, 23);
			this->linkLabelUPosition->Name = L"linkLabelUPosition";
			this->linkLabelUPosition->Size = System::Drawing::Size(55, 13);
			this->linkLabelUPosition->TabIndex = 1;
			this->linkLabelUPosition->TabStop = true;
			this->linkLabelUPosition->Text = L"U Position";
			// 
			// linkLabelRuderPosition
			// 
			this->linkLabelRuderPosition->AutoSize = true;
			this->linkLabelRuderPosition->Location = System::Drawing::Point(253, 23);
			this->linkLabelRuderPosition->Name = L"linkLabelRuderPosition";
			this->linkLabelRuderPosition->Size = System::Drawing::Size(82, 13);
			this->linkLabelRuderPosition->TabIndex = 1;
			this->linkLabelRuderPosition->TabStop = true;
			this->linkLabelRuderPosition->Text = L"Rudder Position";
			// 
			// linkLabelPointOfView
			// 
			this->linkLabelPointOfView->AutoSize = true;
			this->linkLabelPointOfView->Location = System::Drawing::Point(170, 23);
			this->linkLabelPointOfView->Name = L"linkLabelPointOfView";
			this->linkLabelPointOfView->Size = System::Drawing::Size(69, 13);
			this->linkLabelPointOfView->TabIndex = 1;
			this->linkLabelPointOfView->TabStop = true;
			this->linkLabelPointOfView->Text = L"Point of View";
			// 
			// linkLabelButtons
			// 
			this->linkLabelButtons->AutoSize = true;
			this->linkLabelButtons->Location = System::Drawing::Point(87, 23);
			this->linkLabelButtons->Name = L"linkLabelButtons";
			this->linkLabelButtons->Size = System::Drawing::Size(43, 13);
			this->linkLabelButtons->TabIndex = 1;
			this->linkLabelButtons->TabStop = true;
			this->linkLabelButtons->Text = L"Buttons";
			// 
			// linkLabelButtonNumber
			// 
			this->linkLabelButtonNumber->AutoSize = true;
			this->linkLabelButtonNumber->Location = System::Drawing::Point(6, 23);
			this->linkLabelButtonNumber->Name = L"linkLabelButtonNumber";
			this->linkLabelButtonNumber->Size = System::Drawing::Size(78, 13);
			this->linkLabelButtonNumber->TabIndex = 1;
			this->linkLabelButtonNumber->TabStop = true;
			this->linkLabelButtonNumber->Text = L"Button Number";
			// 
			// textBoxZPosition
			// 
			this->textBoxZPosition->Location = System::Drawing::Point(671, 39);
			this->textBoxZPosition->Name = L"textBoxZPosition";
			this->textBoxZPosition->Size = System::Drawing::Size(77, 20);
			this->textBoxZPosition->TabIndex = 0;
			this->textBoxZPosition->TextChanged += gcnew System::EventHandler(this, &Form1::textBoxZPosition_TextChanged);
			// 
			// textBoxYPosition
			// 
			this->textBoxYPosition->Location = System::Drawing::Point(588, 39);
			this->textBoxYPosition->Name = L"textBoxYPosition";
			this->textBoxYPosition->Size = System::Drawing::Size(77, 20);
			this->textBoxYPosition->TabIndex = 0;
			this->textBoxYPosition->TextChanged += gcnew System::EventHandler(this, &Form1::textBoxYPosition_TextChanged);
			// 
			// textBoxXPosition
			// 
			this->textBoxXPosition->Location = System::Drawing::Point(505, 39);
			this->textBoxXPosition->Name = L"textBoxXPosition";
			this->textBoxXPosition->Size = System::Drawing::Size(77, 20);
			this->textBoxXPosition->TabIndex = 0;
			this->textBoxXPosition->TextChanged += gcnew System::EventHandler(this, &Form1::textBoxXPosition_TextChanged);
			// 
			// textBoxVPosition
			// 
			this->textBoxVPosition->Location = System::Drawing::Point(422, 39);
			this->textBoxVPosition->Name = L"textBoxVPosition";
			this->textBoxVPosition->Size = System::Drawing::Size(77, 20);
			this->textBoxVPosition->TabIndex = 0;
			this->textBoxVPosition->TextChanged += gcnew System::EventHandler(this, &Form1::textBoxVPosition_TextChanged);
			// 
			// textBoxUPosition
			// 
			this->textBoxUPosition->Location = System::Drawing::Point(339, 39);
			this->textBoxUPosition->Name = L"textBoxUPosition";
			this->textBoxUPosition->Size = System::Drawing::Size(77, 20);
			this->textBoxUPosition->TabIndex = 0;
			this->textBoxUPosition->TextChanged += gcnew System::EventHandler(this, &Form1::textBoxUPosition_TextChanged);
			// 
			// textBoxRudderPosition
			// 
			this->textBoxRudderPosition->Location = System::Drawing::Point(256, 39);
			this->textBoxRudderPosition->Name = L"textBoxRudderPosition";
			this->textBoxRudderPosition->Size = System::Drawing::Size(77, 20);
			this->textBoxRudderPosition->TabIndex = 0;
			this->textBoxRudderPosition->TextChanged += gcnew System::EventHandler(this, &Form1::textBoxRudderPosition_TextChanged);
			// 
			// textBoxPointOfView
			// 
			this->textBoxPointOfView->Location = System::Drawing::Point(173, 39);
			this->textBoxPointOfView->Name = L"textBoxPointOfView";
			this->textBoxPointOfView->Size = System::Drawing::Size(77, 20);
			this->textBoxPointOfView->TabIndex = 0;
			this->textBoxPointOfView->TextChanged += gcnew System::EventHandler(this, &Form1::textBoxPointOfView_TextChanged);
			// 
			// textBoxButtons
			// 
			this->textBoxButtons->Location = System::Drawing::Point(90, 39);
			this->textBoxButtons->Name = L"textBoxButtons";
			this->textBoxButtons->Size = System::Drawing::Size(77, 20);
			this->textBoxButtons->TabIndex = 0;
			this->textBoxButtons->TextChanged += gcnew System::EventHandler(this, &Form1::textBoxButtons_TextChanged);
			// 
			// textBoxButtonNumber
			// 
			this->textBoxButtonNumber->Location = System::Drawing::Point(7, 39);
			this->textBoxButtonNumber->Name = L"textBoxButtonNumber";
			this->textBoxButtonNumber->Size = System::Drawing::Size(77, 20);
			this->textBoxButtonNumber->TabIndex = 0;
			this->textBoxButtonNumber->TextChanged += gcnew System::EventHandler(this, &Form1::textBoxButtonNumber_TextChanged);
			// 
			// btnEvent
			// 
			this->btnEvent->Location = System::Drawing::Point(685, 316);
			this->btnEvent->Name = L"btnEvent";
			this->btnEvent->Size = System::Drawing::Size(75, 23);
			this->btnEvent->TabIndex = 1;
			this->btnEvent->Text = L"buttonEvent";
			this->btnEvent->UseVisualStyleBackColor = true;
			this->btnEvent->Click += gcnew System::EventHandler(this, &Form1::buttonEvent_Click);
			// 
			// btnEnde
			// 
			this->btnEnde->Location = System::Drawing::Point(685, 351);
			this->btnEnde->Name = L"btnEnde";
			this->btnEnde->Size = System::Drawing::Size(75, 23);
			this->btnEnde->TabIndex = 1;
			this->btnEnde->Text = L"Ende";
			this->btnEnde->UseVisualStyleBackColor = true;
			this->btnEnde->Click += gcnew System::EventHandler(this, &Form1::buttonEvent_Click);
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(781, 386);
			this->Controls->Add(this->btnEnde);
			this->Controls->Add(this->btnEvent);
			this->Controls->Add(this->groupBox1);
			this->Name = L"Form1";
			this->Text = L"Form1";
			this->groupBox1->ResumeLayout(false);
			this->groupBox1->PerformLayout();
			this->ResumeLayout(false);

		}
#pragma endregion
	private: System::Void textBoxVPosition_TextChanged(System::Object^  sender, System::EventArgs^  e) {
			 }
private: System::Void textBoxButtonNumber_TextChanged(System::Object^  sender, System::EventArgs^  e) {
			 //textBoxButtonNumber->Text = "Test-2";
		 }
private: System::Void textBoxButtons_TextChanged(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void textBoxPointOfView_TextChanged(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void buttonEvent_Click(System::Object^  sender, System::EventArgs^  e) {
			UINT JoystickID = 0;			// JoystickID hier "hart" festgelegt auf ID = 0
			JOYINFOEX JoyPositionen;
			JOYINFO Joyinfo;
			JOYCAPS Joycaps;
	
			joyGetPosEx(JoystickID, &JoyPositionen);
			textBoxButtonNumber->Text = JoyPositionen.dwButtonNumber.ToString();
			textBoxButtons->Text = JoyPositionen.dwButtons.ToString();
			textBoxPointOfView->Text = JoyPositionen.dwPOV.ToString();
			textBoxRudderPosition->Text = JoyPositionen.dwRpos.ToString();
			textBoxUPosition->Text = JoyPositionen.dwUpos.ToString();
			textBoxVPosition->Text = JoyPositionen.dwVpos.ToString();
			textBoxXPosition->Text = JoyPositionen.dwXpos.ToString();
			textBoxYPosition->Text = JoyPositionen.dwYpos.ToString();
			textBoxZPosition->Text = JoyPositionen.dwZpos.ToString();

//			ON_MESSAGE(MM_JOY1MOVE, OnMyMessage);
//			MM_JOY1MOVE;
//			fwButtons = wParam; 
//			xPos = LOWORD(lParam); 
//			yPos = HIWORD(lParam);
		 }
private: System::Void textBoxRudderPosition_TextChanged(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void textBoxUPosition_TextChanged(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void textBoxXPosition_TextChanged(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void textBoxYPosition_TextChanged(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void textBoxZPosition_TextChanged(System::Object^  sender, System::EventArgs^  e) {
		 }
};
}




Habe übrigens versucht mich auf dieses Programmbeispiel zu stützen:
http://www.thewall.d...?threadid=28366

Für alle die ebenfalls auf der Suche nach Informationen hierfür sind -> hier gibt es noch mehr Infos:
http://msdn2.microso...y/k35k2bfs.aspx

Viele Grüße,
Hans

Dieser Beitrag wurde von Hans_Wurst bearbeitet: 26. April 2008 - 17:37

0

#5 Mitglied ist offline   Hans_Wurst 

  • Gruppe: Mitglieder
  • Beiträge: 4
  • Beigetreten: 26. April 08
  • Reputation: 0

geschrieben 26. April 2008 - 17:53

Achja, ich solte vielleicht noch meine Fehlermeldung mit angeben :rolleyes:

1>.\programmname.cpp(11) : error C2373: 'WinMain': Neudefinition; unterschiedliche Modifizierer
1> C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winbase.h(2560): Siehe Deklaration von 'WinMain'

Dieser Beitrag wurde von Hans_Wurst bearbeitet: 26. April 2008 - 17:55

0

Thema verteilen:


Seite 1 von 1

1 Besucher lesen dieses Thema
Mitglieder: 0, Gäste: 1, unsichtbare Mitglieder: 0