如何对窗口右上角的3个按钮即最大化,最小化,关闭的操作进行拦截并操作。

解决方案 »

  1.   

    重新定义wm_syscommand消息,如下procedure TForm1.WMSysCommand(var Msg:TMessage);message WM_SYSCOMMAND;
    begin
      inherited;  //如果你要废弃原有操作,这句不加
      case Msg.wParam of
        SC_MINIMIZE: ;  //当点了最小化按钮
        SC_MAXIMIZE: ;  //当点了最大化按钮
        SC_RESTORE: ;  //当点了恢复按钮
        SC_CLOSE: ;  //当点了关闭按钮
      end;
    end;
      

  2.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;type
      TForm1 = class(TForm)
      private
        { Private declarations }
        procedure WMSYSCOMMAND (var Message : TWMSYSCOMMAND); message WM_SYSCOMMAND;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.DFM}
    procedure TForm1.WMSYSCOMMAND (var Message : TWMSYSCOMMAND);
    begin
      case Message.CmdType of
      SC_MAXIMIZE : showmessage('You click Max button');
      SC_MINIMIZE : showmessage('You click Min button');
      SC_RESTORE : showmessage('You click Restore button');
      SC_CLOSE : showmessage('You click Close button');
      end;
      inherited;
    end;
      

  3.   

    procedure WMSysCommand(var Message: TWMSysCommand); message WM_SYSCOMMAND;delphi源码
    procedure TCustomForm.WMSysCommand(var Message: TWMSysCommand);
    begin
      with Message do
      begin
        if (CmdType and $FFF0 = SC_MINIMIZE) and (Application.MainForm = Self) then
          Application.WndProc(TMessage(Message))
        else if (CmdType and $FFF0 <> SC_MOVE) or (csDesigning in ComponentState) or
          (Align = alNone) or (WindowState = wsMinimized) then
          inherited;
        if ((CmdType and $FFF0 = SC_MINIMIZE) or (CmdType and $FFF0 = SC_RESTORE)) and
          not (csDesigning in ComponentState) and (Align <> alNone) then
          RequestAlign;
      end;
    end;
      

  4.   

    private
        { Private declarations }
        procedure MySyscommand(var Msg: TWMSYSCOMMAND);message WM_SYSCOMMAND;
    procedure TForm1.MySyscommand(var Msg: TWMSYSCOMMAND);
    begin     case (Msg.CmdType and $fff0) of
          SC_CLOSE: showmessage('close');
          SC_MAXIMIZE: showmessage('maximize');
          SC_MINIMIZE: showmessage('minimize');
          end;
    end;