-
November 13th, 2008, 07:10 AM
#1
Get Global Cursor Position
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!
-
November 13th, 2008, 08:50 AM
#2
Re: Get Global Cursor Position
How could you achive it?
It always specified in screen coordinates! See MSDN article GetCursorPos Function:
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.
Victor Nijegorodov
-
November 13th, 2008, 09:50 AM
#3
Re: Get Global Cursor Position
Originally Posted by sgergo
...I tried GetCursorPos, it gives those screen coordinates but only inside the active window.
I meant that I receive the screen coordinates of the mouse pointer IF I'm above my application window. If I leave that window the GetCursorPos won't update - it shows the last values when the pointer was inside my window.
Anyway, I managed to solve the problem
-
November 13th, 2008, 10:43 AM
#4
Re: Get Global Cursor Position
Maybe you have to use SetCapture() funtion.
My English is very bad. So tell me if Something I talked make u confuse.
My Ebook Store: www.coding.vn/book.php
-
November 13th, 2008, 01:18 PM
#5
Re: Get Global Cursor Position
Maybe you can tell others how you solved your problem?
-
November 13th, 2008, 02:14 PM
#6
Re: Get Global Cursor Position
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;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|