Re: Detect mouse click and coordinates (C++)





"Ron Francis" wrote:

Here is a very brief outline of what you would have to do, but I don't think
this would help you much in a console program.
You may get something from it though.

In the Windows SDK you set up something similar to your main() function like
this ...
int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow )

In that you set up your window by filling out a structure
WNDCLASS wndclass (or WNDCLASSEX) , where the member
"wndclass.lpfnWndProc " is a pointer to your callback function that
receives messages

then you create a window using
hWnd = CreateWindow( szAppName, szAppName, dwStyle, CW_USEDEFAULT, 0,
xScreen, yScreen , NULL, NULL, hInstance, NULL) ;
(Excuse my variables, I just wanted to show you what the function looked
like.)

After creating your window, you have a message loop which directs Windows
messages to your callback function
while( GetMessage( &msg, NULL, 0, 0 ) ) {
TranslateMessage( &msg );
DispatchMessage( &msg );
}

Only after all that can you start catching messages and your callback
function it would look a little like this ...
LRESULT CALLBACK MainWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
lParam ){
switch (uMsg) {
case WM_MOUSEMOVE:
//do stuff here
// the coordinates of the mouse are given to you in the LPARAM
parameter.
}
return 1;
}

You should be able to download the Platform SDK from the Microsoft site.
I know nothing of DevC++ though, so I don't know what is applicable to you.

Hope some of this helps.

Regards,
Ron Francis
www.RonaldFrancis.com



This really helps Ron, thanks once more :)
If I can't get even that to happen (God forbid) perhaps I can get the mouse
Coordinates this way..

POINT pos;
GetCursorPos(&pos);
int x = pos.x; x = x / 8
int y = pos.y; y = y / 12
cout << "Mouse Coordinates: " << x << ", " << y << endl;
system("pause");

Of course, how much I divide x and y for depends on the current size setting
of each letter on DOS, in this case 8 wide by 12 high.
.