首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

关于Hook拦截不到WM_WM_KILLFOCUS消息。该怎么解决

2012-02-25 
关于Hook拦截不到WM_WM_KILLFOCUS消息。LRESULT CALLBACK GetMsgProc(int code,// hook codeWPARAM wParam,

关于Hook拦截不到WM_WM_KILLFOCUS消息。
LRESULT CALLBACK GetMsgProc( int code, // hook code
  WPARAM wParam, // current-process flag  
  LPARAM lParam // message data
)

SetWindowsHookEx(WH_GETMESSAGE,GetMsgProc,GetModuleHandle("HookDll"),NULL);

现在钩子可以设置成功,也进入了GetMsgProc函数。,但就是拦截不到指定的消息, 
大概就是这些,具体代码如下:

dll def文件:

C/C++ code
LIBRARY HookDllEXPORTSSetHook


dll cpp文件:
C/C++ code
#include <windows.h>#pragma data_seg("MyHookEx")HHOOK hhgm=NULL;#pragma data_seg()#pragma comment(linker,"/section:MyHookEx,RWS")LRESULT CALLBACK GetMsgProc(  int code,      // hook code  WPARAM wParam,  // current-process flag    LPARAM lParam   // message data){    if(code==HC_ACTION)    {        MSG *msg = (MSG*)lParam;        if(code == HCBT_ACTIVATE)        {            if(msg->message==WM_KILLFOCUS)            {                MessageBox(0,0,0,0);            }        }        return 0;    }else if(code<0)    {        return CallNextHookEx(hhgm,code,wParam,lParam);    }    return 0;}void SetHook(){    hhgm = SetWindowsHookEx(WH_GETMESSAGE,GetMsgProc,GetModuleHandle("HookDll"),NULL);    if(hhgm)    {        MessageBox(0,"Hook is sucess!",0,0);    }else    {        MessageBox(0,"Hook is NULL!",0,0);    }}


Exe cpp文件:
C/C++ code
#include <Windows.h>_declspec(dllimport) void SetHook();LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);HWND hb;int WINAPI WinMain(    HINSTANCE hInstance,    HINSTANCE hPrveInstance,    LPSTR lpCmdLine,    int nCmdShow){    WNDCLASSEX wcex;    wcex.cbClsExtra=0;    wcex.cbSize=sizeof(WNDCLASSEX);    wcex.cbWndExtra=0;    wcex.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);    wcex.hCursor=LoadCursor(NULL,IDC_ARROW);    wcex.hIcon=LoadIcon(NULL,IDI_APPLICATION);    wcex.hIconSm=LoadIcon(NULL,IDI_APPLICATION);    wcex.hInstance=hInstance;    wcex.lpfnWndProc=WndProc;    wcex.lpszClassName="ClassName";    wcex.lpszMenuName=NULL;    wcex.style=CS_HREDRAW|CS_VREDRAW;    RegisterClassEx(&wcex);    HWND hwnd=CreateWindow(wcex.lpszClassName,"Title",WS_OVERLAPPEDWINDOW+WS_VISIBLE,CW_USEDEFAULT,CW_USEDEFAULT,350,250,NULL,NULL,hInstance,NULL);    hb=CreateWindow("Button","Title",WS_CHILDWINDOW+WS_VISIBLE,0,0,100,50,hwnd,NULL,hInstance,NULL);    MSG msg;    while(GetMessage(&msg,NULL,0,0))    {        TranslateMessage(&msg);        DispatchMessage(&msg);    }    return (int) msg.wParam;}LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam){    switch(message)    {    case WM_CREATE:        break;    case WM_COMMAND:        if((HWND)lParam==hb)        {            SetHook();        }        break;    case WM_DESTROY:        PostQuitMessage(0);        break;    default:        return DefWindowProc(hWnd,message,wParam,lParam);        break;    }    return 0;}



[解决办法]
结贴z
[解决办法]
飘过啊,拦截不到WM_KILLFOCUS,别的消息能拦截到不

热点排行