Get Global Cursor Position
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Get Global Cursor Position

  1. #1
    Join Date
    Oct 2007
    Posts
    25

    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!

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,360

    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

  3. #3
    Join Date
    Oct 2007
    Posts
    25

    Re: Get Global Cursor Position

    Quote Originally Posted by sgergo View Post
    ...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

  4. #4
    Join Date
    Oct 2008
    Posts
    116

    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

  5. #5
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,062

    Re: Get Global Cursor Position

    Maybe you can tell others how you solved your problem?

  6. #6
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center