当我运行计算器时,把标题改为test 
安装全局钩子
SetWindowsHookEx(WH_GETMESSAGE, @Proc, HInstance, 0);
想问问在proc中如何实现

解决方案 »

  1.   

    LRESULT CALLBACK GetMsgProc(    int code, // hook code
        WPARAM wParam, // removal flag
        LPARAM lParam  // address of structure with message
       );
     ParameterscodeSpecifies whether the hook procedure must process the message. If code is HC_ACTION, the hook procedure must process the message. If code is less than zero, the hook procedure must pass the message to the CallNextHookEx function without further processing and should return the value returned by 
    CallNextHookEx. wParamSpecifies whether the message has been removed from the queue. This parameter can be one of the following values: Value Meaning
    PM_NOREMOVE Specifies that the message has not been removed from the queue. (An application called the PeekMessage function, specifying the PM_NOREMOVE flag.)
    PM_REMOVE Specifies that the message has been removed from the queue. (An application called GetMessage, or it called the PeekMessage function, specifying the PM_REMOVE flag.)
     lParamPoints to an MSG structure that contains details about the message.  Return ValuesThe return value should be zero. 
      

  2.   


    var
      I:Thandle; //句柄变量
      Str:string;
    begin
      Str:='Test';
      I:=FindWindow(nil,'计算器');
      if I<>0 then
      SendMessage(I,WM_SETTEXT,10,Integer(Str))
    end;
      

  3.   


    function  Proc(Code: Integer; WParam: Longint;Msg:Longint):  LRESULT;stdcall;
    begin
     if (Code = HC_ACTION) then
        if PMsg(Msg)^.Message = WM_MOUSEWHEEL then  //鼠标滚动
        begin
          if HIWORD(PMsg(Msg)^.wParam)=120 then        // 上滚
          begin
                //做你想做的。
                ShowWindow (pmsg(msg)^.hwnd,SW_MAXIMIZE );
          end;      if HIWORD(PMsg(Msg)^.wParam)<>120 then        // 下滚
          begin
                //做你想做的。
                ShowWindow (pmsg(msg)^.hwnd,SW_RESTORE );     
          end;
          PMsg(Msg)^.Message := 0;
        end;
        Result :=CallNextHookEx(HookHandle, Code, WParam, Longint(@Msg));
    end;
      

  4.   

    钩子是一种可以让你写的代码运行在别的进程里的机制。所以,你的钩子代码会运行在几乎所有的有窗口的进程中,这是你就要有一种方法来判断当前的窗口是“计算器”。只有能准确找到目标窗口,接下来的工作才可以正常进行。对于计算器程序来说,标题极有可能是在 CreateWindow 的时候就指定好的,所以,即使你的钩子安装成功,也不会得到任何通知。当然,如果计算器程序很配合你的实验目的,是由消息设置标题的话,那么对应的消息是 WM_SETTEXT,不过很不幸的是,这个消息一般是用 SendMessage 函数发出的,你的 WH_GETMESSAGE 类型的钩子是捕获不到的,应该安装 WH_CALLWNDPROC 类型的钩子。
      

  5.   

    我表达的可能不清楚,目的是监控计算器这个程序。
    当计算器程序运行了,showmessage('ok')就可以了。
    我觉得用WH_GETMESSAGE 类型可以实现这个功能。
    如果设置个全局变量作为标志进行判断不知道行不行?
    还请大家指点一下。
      

  6.   

    监视计算器的运行恐怕没那么容易,要做全局钩挂,一般不会在用户模式下完成
    不过监视explorer.exe的CreateProcess可能会容易点
      

  7.   

    这个目的的话,可以看一下 WH_SHELL 钩子,应该更适合你。
      

  8.   

    我要做个监控程序,改标题为了测试用。
    用WH_SHELL 钩子测试成功 结帖
      

  9.   

    dandycheung 大哥不好意思,看错了,本还要给你加分的。