Re: Detect mouse click and coordinates (C++)
- From: Ash44455666 <Ash44455666@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 13 Feb 2007 07:32:01 -0800
"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.
.
- Follow-Ups:
- Re: Detect mouse click and coordinates (C++)
- From: Ron Francis
- Re: Detect mouse click and coordinates (C++)
- References:
- Re: Detect mouse click and coordinates (C++)
- From: Ron Francis
- Re: Detect mouse click and coordinates (C++)
- From: Ron Francis
- Re: Detect mouse click and coordinates (C++)
- Prev by Date: RE: ICON not correct
- Next by Date: Re: listview deselects items after notify
- Previous by thread: Re: Detect mouse click and coordinates (C++)
- Next by thread: Re: Detect mouse click and coordinates (C++)
- Index(es):
Relevant Pages
|