Hi,
how can I get the global (screen) position of the mouse cursor? I tried GetCursorPos, it gives those screen coordinates but only inside the active window.
Any help would be highly appreciated!
Printable View
Hi,
how can I get the global (screen) position of the mouse cursor? I tried GetCursorPos, it gives those screen coordinates but only inside the active window.
Any help would be highly appreciated!
How could you achive it?:confused:
It always specified in screen coordinates! See MSDN article GetCursorPos Function:Quote:
Remarks
The cursor position is always specified in screen coordinates and is not affected by the mapping mode of the window that contains the cursor.
The calling process must have WINSTA_READATTRIBUTES access to the window station.
The input desktop must be the current desktop when you call GetCursorPos. Call OpenInputDesktop to determine whether the current desktop is the input desktop. If it is not, call SetThreadDesktop with the HDESK returned by OpenInputDesktop to switch to that desktop.
Maybe you have to use SetCapture() funtion.
Maybe you can tell others how you solved your problem?
Hm.. you don't need to capture mouse to get cursor position. Am curious how you got it to not working. For e.g. this simple app does it all without having focus or anything
Code:int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
POINT pt;
while(1)
{
GetCursorPos(&pt);
std::wstringstream streamss;
streamss << pt.x << "\t" << pt.y;
OutputDebugStringW(streamss.str().c_str());
Sleep(100);
}
return 0;
}