GetCursorPos

Andres's Avatar, Join Date: Jul 2008
Go4Expert 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
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
What compiler/IDE are you using?
What are the errors?
0
Andres's Avatar, Join Date: Jul 2008
Go4Expert 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
0
xpi0t0s's Avatar, Join Date: Aug 2004
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.
0
Andres's Avatar, Join Date: Jul 2008
Go4Expert 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.
0
xpi0t0s's Avatar, Join Date: Aug 2004
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.
0
Andres's Avatar, Join Date: Jul 2008
Go4Expert 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.
0
Andres's Avatar, Join Date: Jul 2008
Go4Expert Member
I got it...thanks...is it possible to detect rotation with the mouse using c++?
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Rotation of what?