1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

GetCursorPos

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

  1. Andres

    Andres New Member

    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

    What compiler/IDE are you using?
    What are the errors?
     
  3. Andres

    Andres New Member

    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

    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

    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

    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

    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

    I got it...thanks...is it possible to detect rotation with the mouse using c++?
     
  9. xpi0t0s

    xpi0t0s Mentor

    Rotation of what?
     

Share This Page