我想拦截某一文本窗口的WM_CHAR消息,代码如下,StartHook挂钩后,按理g_hHwnd应该为我挂钩的窗口够本,但在钩子过程中显示g_hHwnd为0,不知道怎么回事,大家帮忙看看#include "windows.h"
#include "stdio.h"HINSTANCE g_hInstance = NULL; // 模块实例句柄
HHOOK g_hHook = NULL; // 钩子句柄
HWND g_hHwnd = NULL; // 要挂钩的窗口句柄// DLL 入口函数
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
// 保存模块实例句柄
g_hInstance = (HINSTANCE)hModule;

// 在进程结束或线程结束时卸载钩子
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_PROCESS_DETACH: case DLL_THREAD_DETACH:
if (g_hHook != NULL) UnhookWindowsHookEx(g_hHook);
break;
}
    return TRUE;
}LRESULT CALLBACK HookProc(
  int nCode,      // hook code
  WPARAM wParam,  // current-process flag
  LPARAM lParam   // address of structure with message data
)
{
//MessageBox(NULL,"开始调用钩子","提示",MB_OK);
PCWPSTRUCT pcs = NULL;
pcs=(PCWPSTRUCT)lParam;
char szChar[100];
sprintf(szChar,"收到消息,原始句柄:%X",g_hHwnd);
if (pcs && pcs->hwnd==g_hHwnd)
{
//if (pcs->message==WM_CHAR)
MessageBox(pcs->hwnd,szChar,"提示",MB_OK);
}
else
MessageBox(NULL,szChar,"提示",MB_OK);
return CallNextHookEx(g_hHook,nCode,wParam,lParam);
}BOOL WINAPI StartHook(HWND hwnd)
{
if (g_hHook!=NULL ||hwnd==NULL) return FALSE;
g_hHwnd=hwnd;
g_hHook=SetWindowsHookEx(WH_CALLWNDPROC,HookProc,g_hInstance,GetWindowThreadProcessId(g_hHwnd,NULL));
if (g_hHook==NULL) return FALSE;
return TRUE;
}BOOL WINAPI StopHook()
{
if (UnhookWindowsHookEx(g_hHook)==0) return FALSE;
g_hHook = NULL;
return TRUE;
}