我想编写一程序,能够监测一特定进程,截获、处理此进程的消息。
那位能给我一个例子,注意,不是系统钩子。
谢谢!

解决方案 »

  1.   

    http://www.codeproject.com/shell/sweeptheminesweeper.asp
      

  2.   

    不用那么高级,我只要Hook进程-〉截获进程产生/退出消息
      

  3.   

    LRESULT __declspec(dllexport)__stdcall  CALLBACK CallWndProc(int nCode,WPARAM wParam,LPARAM lParam)
    {
    AFX_MANAGE_STATE(AfxGetStaticModuleState());
    PCWPSTRUCT pcw=(PCWPSTRUCT) lParam;
    if(nCode>=0 && pcw && pcw->hwnd)
    {
                 CString strApplication;
    CString strCommand=GetCommandLine();
    int nnum=strCommand.ReverseFind('\\');
    if(nnum!=-1)
    {
    strApplication=strCommand.Mid(nnum+1);
    strApplication.TrimRight();
    strApplication.TrimRight("\"");
    }
             if(strApplication == "xxx.exe")
            {
       if(pcw->message==WM_CREATE)
       {
                     ...
                 }
                 if(pcw->message ==WM_DESTROY)
                 {
                     ...
                  }
            }
    }
      

  4.   

    //安装钩子
    BOOL __declspec(dllexport)__stdcall installhook()
    {
    //install CallwndHook
    callwndHook=SetWindowsHookEx(WH_CALLWNDPROC,(HOOKPROC)CallWndProc,hins,0);
    return TRUE;
    }
    //卸载钩子
    BOOL __declspec(dllexport)__stdcall  UnHook()
    {
        //uninstall hook
    UnhookWindowsHookEx(callwndHook);
    return TRUE;

    //you may change it to thread hook, not global hook