Hi Leute,
Ich bin gerade bei der 4. Aufgabe im Kapitel 4.9. Bei mir wird die Maus, nur dann bewegt wenn die Maus über dem Fenster ist
. Hat jemand ne Idee wie man es schaft das die Mause auch bewegt wird wenn sie nicht drüber ist?
Ich initialisiere den Joystick so:
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
if(FAILED(g_pDInput->EnumDevices(DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback,
NULL, DIEDFL_ATTACHEDONLY)))
{
MessageBox(NULL, "Es wurde kein Joystick gefunden!",
"Fehler", MB_OK | MB_ICONEXCLAMATION);
return TB_ERROR;
}
// Jetzt wird die IDirectInputDevice8-Schnittstelle für den
// Joystick erstellt.
if(FAILED(g_pDInput->CreateDevice(JoystickGUID, &g_pJoystick, NULL))) return TB_ERROR;
// Als nächstes wird das Datenformat gesetzt.
if(FAILED(g_pJoystick->SetDataFormat(&c_dfDIJoystick2))) return TB_ERROR;
// Ebene der Kooperation festlegen. Es wird ein nicht exklusiver
// Zugriff im Vordergrundbetrieb eingestellt.
if(FAILED(g_pJoystick->SetCooperativeLevel(hWnd, DISCL_EXCLUSIVE |
DISCL_BACKGROUND))) return TB_ERROR;
if(FAILED(g_pJoystick->Acquire()))
{
return TB_ERROR;
}
// Den Joystick kalibrieren
return CalibrateJoystick();
|
die EnumJoysticksCallback und CalibrateJoystick-Funktion entspricht bei mir den Funktionen aus dem Beispielen davor.
die Joystickdaten frage ich so ab:
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
DIJOYSTATE2 JoystickState; // Status des Joysticks
HRESULT r;
POINT mousePosA;
int x;
int y;
// Daten abfragen
r = g_pJoystick->Poll();
if(r == DIERR_INPUTLOST)
{
// Zugriff verloren - erneut versuchen
g_pJoystick->Acquire();
}
if(FAILED(r))
{
// Abfrage hat nicht funktioniert!
// Wahrscheinlich ist das Fenster gerade nicht aktiv.
MessageBox(NULL, "Fehler beim Abfragen der Joystickdaten", "Fehler", MB_OK | MB_ICONEXCLAMATION);
return TB_ERROR;
}
// Zustand abfragen
g_pJoystick->GetDeviceState(sizeof(DIJOYSTATE2), &JoystickState);
// Alte Mouse-Position abfragen
GetCursorPos(&mousePosA);
// Neue Mouse-Position berechnen
x = mousePosA.x + JoystickState.lX / 15;
y = mousePosA.y + JoystickState.lY / 15;
|