PDA

View Full Version : GetCursorPos problem


speedy_rudolf
06-22-2010, 08:24 AM
Hi. Iave thefolowing ode segment:


#include "stdafx.h"
#include<iostream>
#include<conio.h>
#include<Windows.h>
using namespace std;

#define WM_MOUSEMOVE 0x0200

void main(){
typedef struct tagPOINT {
LONG x;
LONG y;
} POINT, *PPOINT;

case WM_MOUSEMOVE:
POINT pos;
GetCursorPos(&pos);
// here is your coordinates
wcout<<"x: "<<pos.x<<"\n";
wcout<<"y: "<<pos.y<<"\n";


The problem is, it give me an error essage at the line with "GetCursorPos(&pos);", sayin "error C2664: 'GetCursorPos' : cannot convert parameter 1 from 'POINT *' to 'LPPOINT'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast"

Does anyone kno what the prolem might be? Thanks. Bye.

BrickInTheWall
06-22-2010, 12:21 PM
If all fails, to get the mouse coordinates, use the LOWORD of lParam for the x coordinate, and the HIWORD of lParam for y, and fill the struct in yourself.

oracleguy
06-22-2010, 03:58 PM
The reason is that you are creating your own point data structure and the one in the Windows API is expecting theirs. Get rid of yours and it will work.

speedy_rudolf
06-22-2010, 04:05 PM
The reason is that you are creating your own point data structure and the one in the Windows API is expecting theirs. Get rid of yours and it will work.
Thanks. That works. But now I have another problem.

char wParam, msg;
switch(msg){
case WM_KEYDOWN:
switch(wParam){
bla bla bla

Errors: warning C4700: uninitialized local variable 'msg' used
and
warning C4700: uninitialized local variable 'wParam' used

Any suggestions? Thanks again.

BrickInTheWall
06-22-2010, 06:10 PM
Um, the parameters msg, lParam, wParam and hWnd should all be passed to your WndProc function.
I suggest you look at these tutorials:
http://www.winprog.org/tutorial/

Programming with the win32 API is a little weird at first, but not hard once you get used to it.

speedy_rudolf
06-22-2010, 06:29 PM
Um, the parameters msg, lParam, wParam and hWnd should all be passed to your WndProc function.
I suggest you look at these tutorials:
http://www.winprog.org/tutorial/

Programming with the win32 API is a little weird at first, but not hard once you get used to it.
Thank you very much. This looks like exactly what I needed.