为什么我的WH_MOUSE不可以全局??
我的MouseHook.cpp简单介绍如下:
#pragma data_seg("TestData")
HWND glhPrevTarWnd=NULL;
HWND glhHook=NULL;
HINSTANCE glhInstance=NULL;
#pragma data_seg()
void StartHook(HWND hViewHwnd, HMODULE hMod)
{
m_hViewHandle = hViewHwnd;
glhHook=(HWND)SetWindowsHookEx(WH_MOUSE,MouseProc,hMod,0);
}
LRESULT WINAPI MouseProc(int nCode,WPARAM wParam,LPARAM lParam)
{
/*
LPMOUSEHOOKSTRUCT pMouseHook=(LPMOUSEHOOKSTRUCT) lParam;
if(nCode>=0)
{
*/
HWND glhTargetWnd=pMouseHook->hwnd;
//取目标窗口句柄
HWND ParentWnd=glhTargetWnd;
while(ParentWnd !=NULL)
{
glhTargetWnd=ParentWnd;
//取应用程序主窗口句柄
ParentWnd=GetParent(glhTargetWnd);
}
if(glhTargetWnd!=glhPrevTarWnd)
{
char szCaption[100];
//取目标窗口标题
GetWindowText(glhTargetWnd,szCaption,100);
SendMessage(m_hViewHandle, WM_CAPTION_CHANGED, 0, (LPARAM)szCaption);
}
}
//继续传递消息
return CallNextHookEx((HHOOK)glhHook,nCode,wParam,lParam);
}
为什么我的程序只在本程序窗口有效,而不是全局的?
而当我把WH_MOUSE换成WH_MOUSE_LL时,将MouseProc中相应部分换成
/*
LPMSLLHOOKSTRUCT pMouseHook = (LPMSLLHOOKSTRUCT )lParam;
if (nCode >= 0) {
HWND glhTargetWnd = WindowFromPoint(pMouseHook->pt);
/*
时,其他都一样。程序却可以正常进行。为什么?好奇怪啊。
哪位大侠指点一下?