|
-
January 12th, 2010, 11:32 PM
#1
CALLBACK errror on class
#include "stdafx.h"
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <stdio.h>
HHOOK g_hMouseHook;
class CHECK
{
public:
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
};
LRESULT CALLBACK CHECK::LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode >= 0)
{
PMSLLHOOKSTRUCT pmll = (PMSLLHOOKSTRUCT) lParam;
printf("msg: %lu, x:%ld, y:%ld\n", wParam, pmll->pt.x, pmll->pt.y);
switch (wParam)
{
case WM_MBUTTONDOWN:
ShowCursor(FALSE);
break;
case WM_MBUTTONUP:
ShowCursor(TRUE);
break;
}
}
return CallNextHookEx(g_hMouseHook, nCode, wParam, lParam);
}
int _tmain(int argc, _TCHAR* argv[])
{
MSG msg;
g_hMouseHook = SetWindowsHookEx( WH_MOUSE_LL, &CHECK::LowLevelKeyboardProc, GetModuleHandle(NULL), 0 );
if (!g_hMouseHook) printf("err: %d\n", GetLastError());
while ( GetMessage(&msg, NULL, 0, 0) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
UnhookWindowsHookEx(g_hMouseHook);
return (int) msg.wParam;
}
Here i am getting error
cannot convert parameter 2 from 'LRESULT (__stdcall CHECK::* )(int,WPARAM,LPARAM)' to 'HOOKPROC'
What may be the error, i think its callback issue
can anyone help me on implementing callback
-
January 13th, 2010, 02:00 AM
#2
Re: CALLBACK errror on class
First of all you can't use non-static member function of the class as the callback. You can use global function or static member function as the callback. And the next in SetWindowsHookEx function you should provide the address of the function, which is CHECK::LowLevelKeyboardProc without ampersand (&), in second parameter:
Code:
class CHECK
{
public:
static LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
};
and then in _tmain:
Code:
g_hMouseHook = SetWindowsHookEx( WH_MOUSE_LL, (HOOKPROC)CHECK::LowLevelKeyboardProc, GetModuleHandle(NULL), 0 );
-
January 13th, 2010, 02:33 AM
#3
Re: CALLBACK errror on class
Thanks dear...
Now working fine...
But now its working as infinite loop. I want to take control out or unload the mouse event after a single left click
-
January 13th, 2010, 03:05 AM
#4
Re: CALLBACK errror on class
You can handle WM_LBUTTONDOWN message in LowLevelKeyboardProc as below:
Code:
case WM_LBUTTONDOWN:
PostQuitMessage(0);
break;
This will allow to exit from the message loop in _tmain when left mouse button is clicked.
-
January 13th, 2010, 03:27 AM
#5
Re: CALLBACK errror on class
Thanks a lot for u r valuable help.
Now i am getting.
If u dont mind may i asl 1 more question.
How to show mouse pointer. Now i am not getting mouse pointer
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|