代碼如下:
CLaunchDLLApp theApp;
HHOOK Hook;
LRESULT CALLBACK LauncherHook(int nCode,WPARAM wParam,LPARAM lParam);
void SaveLog(char* c);
DllExport void WINAPI InstallLaunchEv()
{
Hook=(HHOOK)SetWindowsHookEx(WH_MOUSE,
(HOOKPROC)LauncherHook,
theApp.m_hInstance,
0);
} LRESULT CALLBACK LauncherHook(int nCode,WPARAM wParam,LPARAM lParam)
{
LRESULT Result=CallNextHookEx(Hook,nCode,wParam,lParam);
if(nCode==HC_ACTION)
{
if(wParam==WM_RBUTTONDOWN)
AfxMessageBox("WM_RBUTTONDOWN");
}
return Result;
}
在單文檔應用程式中加入InstallLaunchEv(),程式運行時,多點擊mouse右鍵幾次,會引起程式羿常或系統當機,大家幫看看,問題出在哪里呢?
CLaunchDLLApp theApp;
HHOOK Hook;
LRESULT CALLBACK LauncherHook(int nCode,WPARAM wParam,LPARAM lParam);
void SaveLog(char* c);
DllExport void WINAPI InstallLaunchEv()
{
Hook=(HHOOK)SetWindowsHookEx(WH_MOUSE,
(HOOKPROC)LauncherHook,
theApp.m_hInstance,
0);
} LRESULT CALLBACK LauncherHook(int nCode,WPARAM wParam,LPARAM lParam)
{
LRESULT Result=CallNextHookEx(Hook,nCode,wParam,lParam);
if(nCode==HC_ACTION)
{
if(wParam==WM_RBUTTONDOWN)
AfxMessageBox("WM_RBUTTONDOWN");
}
return Result;
}
在單文檔應用程式中加入InstallLaunchEv(),程式運行時,多點擊mouse右鍵幾次,會引起程式羿常或系統當機,大家幫看看,問題出在哪里呢?
解决方案 »
- raw 套接字的udp包
- 有关WINAPI线程操作
- camera capture的preview的窗口是属于什么控件呢?谢谢
- 如何在List Control 中高亮显示查询到的行?
- delete 内存出错
- 为什么我对256x256的图片二值化可以,对别的尺寸的就不可以??
- 哪位有更改ip地址的方法和源代码啊?
- 怎样才能将我的从CView继承的类改成从CWnd继承的类??高分求解
- 请问各位高手:怎样实现窗口的分屏?谢谢~
- MSDN...........................?
- 怎么把vc里面默认得按钮上面的字体改一下,默认得太难看了(vc6)
- 我在使用CSocket的Send(buffer,100);时出现错误,提示“***内存readonly”之类的错误,请问该怎么办?谢谢!
在mhs中检测一下鼠标点到哪里了,比如
if(mhs->wHitTestCode!=HTCLIENT)
{...........}
还有
Hook=(HHOOK)SetWindowsHookEx(WH_MOUSE,
(HOOKPROC)LauncherHook,
theApp.m_hInstance,
0);
改成
Hook=(HHOOK)SetWindowsHookEx(WH_MOUSE,
(HOOKPROC)LauncherHook,
NULL,
::GetCurrentThreadId());
试试
我已經改了,但是程式對MOUSE毫無反映,如下:LRESULT __declspec(dllexport)__stdcall CALLBACK KeyboardProc(
int nCode,
WPARAM wParam,
LPARAM lParam)
{
MOUSEHOOKSTRUCT *mhs = (MOUSEHOOKSTRUCT*) lParam; if(HC_ACTION==nCode)
{
if(wParam==WM_RBUTTONUP)
if(mhs->wHitTestCode!=HTCLIENT)
MessageBox(NULL,"hello","ok",MB_OK);
}
}
BOOL __declspec(dllexport)__stdcall installhook()
{//hkb=SetWindowsHookEx(WH_MOUSE,(HOOKPROC)KeyboardProc,hins,0);
hkb=SetWindowsHookEx(WH_MOUSE,(HOOKPROC)KeyboardProc,NULL,::GetCurrentThreadId());
return TRUE;
}
还有KeyboardProc中没有反回值
如果都改对了还不行,再把这句去掉试试if(HC_ACTION==nCode)
我是這樣做的,但是會當機,如下:
LRESULT __declspec(dllexport)__stdcall CALLBACK KeyboardProc(
int nCode,
WPARAM wParam,
LPARAM lParam)
{
if(nCode == HC_ACTION)
{
// get a pointer to the mouse hook struct.
PMOUSEHOOKSTRUCT mhs = (PMOUSEHOOKSTRUCT) lParam;
// intercept messages for left button down and up
switch(wParam)
{
case WM_NCLBUTTONDOWN:
{
// get the pointer to the main window
CWnd *pWnd = AfxGetMainWnd();
if((mhs->hwnd == pWnd->GetSafeHwnd())
&& (mhs->wHitTestCode == HTCAPTION))
{
MessageBox(NULL,"NcRButtonDown","ok",0);
Sleep(100);
}
}
break; case WM_NCLBUTTONUP:
{
bNcLButtonDown = FALSE;
MessageBox(NULL,"NcLButtonUp","ok",0);
}
break; case WM_LBUTTONUP:
{
// get the pointer to the main window
CWnd *pWnd = AfxGetMainWnd();
if((mhs->hwnd == pWnd->GetSafeHwnd())
&& (bNcLButtonDown == TRUE))
{
pWnd->PostMessage(WM_NCLBUTTONUP, HTCAPTION, MAKELONG(mhs->pt.x, mhs->pt.y));
MessageBox(NULL,"LButtonUp","ok",0);
// reset non-client left button down
bNcLButtonDown = FALSE;
}
}
break; default:
break;
}
}
LRESULT RetVal = CallNextHookEx( hkb, nCode, wParam, lParam ); return RetVal;
}
謝謝!