这是DLL中的核心
HOOK,已经设置好了调用和取消HOOK的出口函数。
本意是想当用户关闭记事本时,不要关闭它,而是最小化它。可实际上执行并不成功。不知是为什么?function MessHookProc(nCode: Integer;WParam: WPARAM;LParam: LPARAM): LRESULT;stdcall;
var ms:^MSG;
    hw:HWND;
begin
  if nCode = 0 then  begin
    hw:=findwindow(nil,'未定标题 - 记事本');
    ms:=pointer(LParam);
    if ms.message = WM_SYSCOMMAND then  begin
      if (ms.wParam=SC_CLOSE) and (ms.hwnd=hw) then
        sendMessage(ms.hwnd,WM_SYSCOMMAND,SC_CLOSE,0);
    Result := 0;
    Exit;
    end;
  end;
  if nCode<0 then Result := CallNextHookEx(hk, nCode, wParam, lParam) else Result:=0;
end;

解决方案 »

  1.   

    忘了写:
    hk:= SetWindowsHookEx(WH_GETMESSAGE,@MessHookProc,Hinstance,0);
    使用的是该类型。
    TO楼上:
    我手头上分不多,如果你只是为了分而不是真诚救人与水火的话,就不应该来。
      

  2.   

    WH_GETMESSAGE是在发送给目标窗口消息后,再调用钩子
    你应该用WH_CALLWNDPROC钩子
      

  3.   

    用了wh_callwndproc之后,是可以拦截到wm_close的消息,但无法改变它。
    现在想要使它失效,该如何做???
    真的急,麻烦老大及时回复。
      

  4.   

    拦截到后不要调用CallNextHookEx 或者 把回调函数的值设成非0值,这样WM_CLOSE消息就不会继续传递了
      

  5.   

    不行。
    使用CBT可以,但无法更改它的消息
      

  6.   

    顺便问一下,单击右上角的叉发送的是什么消息?
    我截获WM_SYSCOMMAND和WM_CLOSE只能处理掉alt+f4,点那个叉照样会退出。。
      

  7.   

    type
      TForm1 = class(TForm)
      private
        { Private declarations }
        procedure WMSysCommand(var Msg: TWMSysCommand);
          message WM_SYSCOMMAND;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.DFM}procedure TForm1.WMSysCommand;
    begin
      if (Msg.CmdType = SC_MINIMIZE) or
         (Msg.CmdType = SC_MAXIMIZE) or (Msg.CmdType =SC_CLOSE)then
        MessageBeep(0) else
      inherited;
    end;end.这样就没反应了
      

  8.   

    当然,这只是处理了那个X按键,ALT+F4就要用你的了
      

  9.   

    procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    begin
        canclose:=false;
        application.Minimize;
    end;你看这样行不行,好象如果没有特别的处理的话就关不了了。
      

  10.   

    WM_SYSCOMMAND 
    uCmdType = wParam;        // type of system command requested 
    xPos = LOWORD(lParam);    // horizontal position, in screen coordinates 
    yPos = HIWORD(lParam);    // vertical position, in screen coordinates ->uCmdType 
    Specifies the type of system command requested. This parameter can be one of the following values. Value Meaning 
    SC_CLOSE Closes the window. 
      

  11.   

    SetWindowsHookEx(WH_GETMESSAGE,@MessHookProc,Hinstance,0);==>SetWindowsHookEx(WH_SHELL,@MessHookProc,Hinstance,0);
    ==========================================
    function MessHookProc(nCode: Integer;WParam: WPARAM;LParam: LPARAM): LRESULT;stdcall;
    var ms:^MSG;
        hw:HWND;
    begin
      Result := 0;
      If iCode < 0 Then
      begin
        Result := CallNextHookEx(hNextHookProc, iCode, wParam, lParam);
        Exit;
      end;
    if (nCode = HSHELL_WINDOWDESTROYED) then
    begin
        if MessageDlg('关闭本程序吗?', mtConfirmation, mbYesNoCancel, 0) = mrYes
        then Result := CallNextHookEx(hk, nCode, wParam, lParam)
                         // 允许Windows关闭
        else result:=1;  // 阻止Windows关闭
    end
    else begin
      Result := CallNextHookEx(hk, nCode, wParam, lParam);
    end;
    end;
      

  12.   

    请大家看看我的问题,谢谢
    http://community.csdn.net/Expert/topic/3504/3504457.xml?temp=.3672144