[C++] Mauscursor mit PostMessage verschieben

MagicSword

Cadet 4th Year
Registriert
Sep. 2001
Beiträge
111
Hi
Ich möchte den Mauscursor mit einer PostMessage verschieben. Dazu habe ich eine kleine Funktion geschrieben, die leider nicht funktioniert. Sie wird zwar fehlerlos ausgeführt aber es passiert nichts. Kann mir jemand von euch sagen was daran falsch ist.

Code:
void mousemove()
{
    POINT Position;
    LPARAM pos;

    Position.x=50;
    Position.y=50;

    pos = MAKELPARAM (Position.x, Position.y);		
    PostMessage(HWND_BROADCAST, WM_MOUSEMOVE, NULL, pos);
}


Gruß MS
 
Hmm... weißt du, was du da machst? :-)
Du sagst allen Fenstern, dass sich der Cursor
an diese Stelle bewegt hat, mehr nicht!

Benutz doch einfach SetCursorPos ;)
 
Ich versuche mal zu erklären was ich machen will.
Ich möchte in einer 3D-Engine den Mousecursur mit einem Eye-Tracker steuern. Dazu wollte ich die Eyetrackerkoordinaten einfach den Mauscursor übergeben. Dafür hatte ich auch SetCursorPos genommen. Das funktionierte prima. Allerdings nur auf der Windowsoberfläche. In der Engine wird das SetCursorPos einfach ignoriert.
Da die Engine nun mit Messages arbeitet dachte ich mir ein PostMessage zu senden.
Aber das geht anscheind auch nicht.
Nun weiß ich nicht mehr weiter. :confused_alt:
 
Hmm.... das macht es schwierig, denn du bewegst den Cursor ja garnicht. Außerdem sollte der HWND_BROADCAST fehl am Platze sein, denn es bekommen ja auch nie alle Fenster die Nachricht, wenn sich der Cursor bewegt. Kannst du dir den entsprechenden Fensterhandle besorgen, über FindWindow/FindWindowEx oder so? Außerdem werden dir höchstwahrscheinlich die ständigen WM_NCHITTEST Messages Ärger machen, die Windows in ziemlich kurzen Zeitabständen an das Fenster unter dem Cursor sendet. Bietet diese Engine denn keine anderen Möglichkeiten?
 
Ihe setze mich gerade mit dem Entwicker der Engine in Verbindung. Vielleicht weiß er was.
Mal noch eine andere Frage. Kann man nicht einen Treiber schreiben, der mit dem Maustreiber kommuniziert? Und somit auf unterster Ebene den Cursor verändert?
Wenn ja, wie stellt man das an?

MS
 
Hi,

The mouse_event function synthesizes mouse motion and button clicks.

VOID mouse_event(

DWORD dwFlags, // flags specifying various motion/click variants
DWORD dx, // horizontal mouse position or position change
DWORD dy, // vertical mouse position or position change
DWORD cButtons, // unused, reserved for future use, set to zero
DWORD dwExtraInfo // 32 bits of application-defined information
);
Parameters

dwFlags

A set of flag bits that specify various aspects of mouse motion and button clicking. The bits in this parameter can be any reasonable combination of the following values:

Value Meaning
MOUSEEVENTF_ABSOLUTE Specifies that the dx and dy parameters contain normalized absolute coordinates. If not set, those parameters contain relative data: the change in position since the last reported position. This flag can be set, or not set, regardless of what kind of mouse or mouse-like device, if any, is connected to the system. For further information about relative mouse motion, see the following Remarks section.
MOUSEEVENTF_MOVE Specifies that movement occurred.
MOUSEEVENTF_LEFTDOWN Specifies that the left button changed to down.
MOUSEEVENTF_LEFTUP Specifies that the left button changed to up.
MOUSEEVENTF_RIGHTDOWN Specifies that the right button changed to down.
MOUSEEVENTF_RIGHTUP Specifies that the right button changed to up.
MOUSEEVENTF_MIDDLEDOWN Specifies that the middle button changed to down.
MOUSEEVENTF_MIDDLEUP Specifies that the middle button changed to up.
The flag bits that specify mouse button status are set to indicate changes in status, not ongoing conditions. For example, if the left mouse button is pressed and held down, MOUSEEVENTF_LEFTDOWN is set when the left button is first pressed, but not for subsequent motions. Similarly, MOUSEEVENTF_LEFTUP is set only when the button is first released.

dx

Specifies the mouse's absolute position along the x-axis or its amount of motion since the last mouse event was generated, depending on the setting of MOUSEEVENTF_ABSOLUTE. Absolute data is given as the mouse's actual x-coordinate; relative data is given as the number of mickeys moved.

dy

Specifies the mouse's absolute position along the y-axis or its amount of motion since the last mouse event was generated, depending on the setting of MOUSEEVENTF_ABSOLUTE. Absolute data is given as the mouse's actual y-coordinate; relative data is given as the number of mickeys moved.

cButtons

This parameter is currently unused. It is reserved for future use. It must be set to zero.

dwExtraInfo

Specifies an additional 32-bit value associated with the mouse event. An application calls GetMessageExtraInfo to obtain this extra information.

Return Value

This function has no return value.

Remarks

If the mouse has moved, indicated by MOUSEEVENTF_MOVE being set, dx and dy hold information about that motion. The information is given as absolute or relative integer values.
If MOUSEEVENTF_ABSOLUTE value is specified, dx and dy contain normalized absolute coordinates between 0 and 65,535. The event procedure maps these coordinates onto the display surface. Coordinate (0,0) maps onto the upper-left corner of the display surface, (65535,65535) maps onto the lower-right corner.

If the MOUSEEVENTF_ABSOLUTE value is not specified, dx and dy specify relative motions from when the last mouse event was generated (the last reported position). Positive values mean the mouse moved right (or down); negative values mean the mouse moved left (or up).
Relative mouse motion is subject to the effects of the mouse speed and the two mouse threshold values. An end user sets these three values with the Mouse Tracking Speed slider of Control Panel's Mouse option. An application obtains and sets these values with the SystemParametersInfo function. The operating system applies two tests to the specified relative mouse motion. If the specified distance along either the x or y axis is greater than the first mouse threshold value, and the mouse speed is not zero, the operating system doubles the distance. If the specified distance along either the x or y axis is greater than the second mouse threshold value, and the mouse speed is equal to two, the operating system doubles the distance that resulted from applying the first threshold test. It is thus possible for the operating system to multiply relatively-specified mouse motion along the x or y axis by up to four times.

The mouse_event function is used to synthesize mouse events by applications that need to do so. It is also used by applications that need to obtain more information from the mouse than its position and button state. For example, if a tablet manufacturer wants to pass pen-based information to its own applications, it can write a dynamic-link library (DLL) that communicates directly to the tablet hardware, obtains the extra information, and saves it in a queue. The DLL then calls mouse_event with the standard button and x/y position data, along with, in the dwExtraInfo parameter, some pointer or index to the queued extra information. When the application needs the extra information, it calls the DLL with the pointer or index stored in dwExtraInfo, and the DLL returns the extra information.

Vielleicht hilft dir das weiter ;)

Gruß

Toaster
 
Hey cool, mouse_event kannt ich auch nicht, nur keyb_event.
Ein Treiber wäre sonst meine nächste Idee gewesen, was ich allerdings anhand des Aufwandes für etwas gewagt halte :D
 
Danke für die Antworten.
Mit meinen sehr bescheidenen Programierkünsten habe ich versucht mit der Zeile:
Code:
mouse_event(MOUSEEVENTF_ABSOLUTE, 50, 50, NULL, NULL);
die Maus zu verschieben.
Aber es geht nicht.
Ich denke da fehlt noch was. Könnte mir jemand von euch mal in einem kleinen Beispielprogramm zeigen, wie so etwas aussehen soll?.
 
Ok
Die Maus bewegt sich.
Aber leider nicht in der 3D Engine. Vorher konnte man wenigstens mit der Maus sich in der Engine bewegen. Nur funktioniert selbst sie nicht mehr in der engine.
Vielleicht doch einen Treiber?
Aber wie macht man das?
 
erstell doch einen eigenen Mauszeiger denn du dann mit einer eigenen Funktion anzeigen lässt
 
blende den Mauszeiger aus, erstell ne Grafik für den Mauszeiger, danach fragst du die Mausposition ab und positionierst deine Grafik an entsprechender Stelle :)

ich kann dir keine Code-Samples zeigen, da ich schon lang nicht mehr C/C++ programmiere :rolleyes:

ich gehe mal davon aus die Engine arbeitet nicht mit Direct-X, damit wäre das ganze kein Problem
 
Sorry, also mit dem Treiber kann ich dir nicht weiter helfen. Ich entwickel in Delphi. (der Delphi Linker kann nicht über $80000000 linken, und genau dahin muss man Treiber linken (das 3. GB von den virtuellen 4))
Mit DirectX kenne ich mich leider nicht aus. Vom hörensagen her, soll DirectInput aber nicht ganz so schlimm sein. (D3D ist die Hölle :D)
 
Zurück
Oben