Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   GetCursorPos (http://www.go4expert.com/forums/getcursorpos-t12558/)

Andres 29Jul2008 22:38

GetCursorPos
 
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

xpi0t0s 29Jul2008 23:54

Re: GetCursorPos
 
What compiler/IDE are you using?
What are the errors?

Andres 30Jul2008 21:52

Re: GetCursorPos
 
I am using DEV-C++ 4.9.9.2 and i get
[Linker error] undefined reference to 'WinMain@16'
Id returned 1 exit status

xpi0t0s 31Jul2008 00:46

Re: GetCursorPos
 
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.

Andres 1Aug2008 01:12

Re: GetCursorPos
 
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.

xpi0t0s 1Aug2008 02:39

Re: GetCursorPos
 
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.

Andres 1Aug2008 23:09

Re: GetCursorPos
 
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.

Andres 5Aug2008 21:22

Re: GetCursorPos
 
I got it...thanks...is it possible to detect rotation with the mouse using c++?

xpi0t0s 10Aug2008 06:16

Re: GetCursorPos
 
Rotation of what?


All times are GMT +5.5. The time now is 22:03.