GetCursorPos

Discussion in 'C++' started by Andres, Jul 29, 2008.

  1. Andres

    Andres New Member

    Joined:
    Jul 22, 2008
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    0
    this is my code in C++

    #include <windows.h>
    #include <winuser.h>



    BOOL GetCursorPos (
    LPPOINT lpPoint
    );
    DWORD WINAPI GetLastError (void);

    I get some linker errors...can someone help me
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    What compiler/IDE are you using?
    What are the errors?
     
  3. Andres

    Andres New Member

    Joined:
    Jul 22, 2008
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    0
    I am using DEV-C++ 4.9.9.2 and i get
    [Linker error] undefined reference to 'WinMain@16'
    Id returned 1 exit status
     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Well if the above is all the code then yes you will get that error, it'd be the same as "undefined reference to main" in a C program if you didn't have a main() function. WinMain is the Windows entry point for the application, the equivalent of main(), and since you haven't defined WinMain you get that error.
     
  5. Andres

    Andres New Member

    Joined:
    Jul 22, 2008
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    0
    Thanks...I fixed it.
    now i have

    #include <windows.h>
    #include <winuser.h>
    #include <iostream>
    #include <iomanip>

    using namespace std;

    int main()
    {

    POINT p;
    GetCursorPos(&p);

    cout<< "The cursor x is: " << p.x << " and y is: " << p.y <<endl;

    }

    Now I was wondering if I could get the coordinates without having to close and reopen the program. For example, what the program does right now, it gives me the coordinates at a specific location and then to get another coordinates, I have to close the program and reopen it. What I want to do, is to leave the program running and get the coordinates by moving the mouse. Is there a way...a loop maybe.
     
  6. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Well you could store x and y and print the current value if it differs from the previous. Yes you will need a loop, see your favourite C++ programming book at probably chapter 2 or 3 for how to do it.
     
  7. Andres

    Andres New Member

    Joined:
    Jul 22, 2008
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    0
    Thanks i did it and it worked...now i want to set the cursor at the center position...can that be done with
    BOOL SetCursorPos(
    int X,
    int Y
    );

    If yes, can you guide me on how it works and how to see the new coordinates I set.
     
  8. Andres

    Andres New Member

    Joined:
    Jul 22, 2008
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    0
    I got it...thanks...is it possible to detect rotation with the mouse using c++?
     
  9. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Rotation of what?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice