CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Capture mouse position

  1. #1
    Join Date
    Apr 2010
    Posts
    3

    Capture mouse position

    Hey. I am trying to capture the mouse position in a c++ command app, it's important that it's mousepos relative to the screen and not the command app itself. Here's some of my code:

    Code:
    #include <iostream>
    #include <windows.h>
    
    int main()
    {
    cout << "Please move your mouse to the pixel of your selection";
    system("pause")
    
    "Get mouse position on the screen (preferably which pixel it's at)"
    
    cout << mousepos_pixel_x << " " << mousepos_pixel_y;
    system("pause")
    
    
    }
    All help is appreciated!

  2. #2
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    Re: Capture mouse position

    "It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
    Richard P. Feynman

  3. #3
    Join Date
    Jan 2009
    Posts
    1,689

    Re: Capture mouse position

    Need to know what platform, it's different for all of them.

  4. #4
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    Re: Capture mouse position

    Quote Originally Posted by ninja9578 View Post
    Need to know what platform, it's different for all of them.
    I went by this.

    Code:
    #include <windows.h>
    "It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
    Richard P. Feynman

  5. #5
    Join Date
    Jan 2009
    Posts
    1,689

    Re: Capture mouse position

    Whoops *embarrassed*

  6. #6
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    456

    Re: Capture mouse position

    Quote Originally Posted by JohnW@Wessex View Post
    This one returns the coordinates of the screen.

    how to convert these coordinates to window coordinates so that i can capture the mouse cursor location when moved on a CStatic control on a dialog box

  7. #7
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,284

    Re: Capture mouse position

    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.7.6)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)