已经有一程序A用全屏运行在屏幕上,并且为前台。我现在想写一程序B,让它开机长驻内存,然后捕捉鼠标事件,只要是鼠标右键双击就将B程序变为前台,并且占满屏幕。

解决方案 »

  1.   

    B程序可以HOOK message//DLL代码如下:
    library HookDLL;
    uses
      Windows,Messages;
    var
      GetMsgHook: HHook;
    function HookGetMsg(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
    begin
      //如果是右键双击
      if  PMsg(lParam).message=WM_RBUTTONDBLCLK then
        Messagebox(0,'你双击了右键!','提示',0);
      Result:= CallNextHookEx(GetMsgHook, nCode, wParam, lParam);
    end;procedure BeginHook;
    begin
      GetMsgHook := SetWindowsHookEx(WH_GETMESSAGE, @HookGetMsg, HInstance, 0);
    end;//脱钩
    procedure EndHook;
    begin
      UnHookWindowsHookEx(GetMsgHook);
    end;exports
      BeginHook, EndHook;beginend.//exe中调用下面两个函数即可.
    procedure  BeginHook;  external 'HookGame.dll';
    procedure  EndHook;  external 'HookGame.dll';
      

  2.   

    对了,B程序中BeginHook可以传递参数,如
    procedure BeginHook(H:THandle);
    如:把exe主窗口的handle传递过去,然后在dll里发消息给handle