利用WM_SIZE可以获知窗口的状态
The WM_SIZE message is sent to a window after its size has changed. WM_SIZE  
fwSizeType = wParam;      // resizing flag 
nWidth = LOWORD(lParam);  // width of client area 
nHeight = HIWORD(lParam); // height of client area 
 ParametersfwSizeTypeValue of wParam. Specifies the type of resizing requested. This parameter can be one of the following values: Value Meaning
SIZE_MAXHIDE Message is sent to all pop-up windows when some other window is maximized.
SIZE_MAXIMIZED Window has been maximized.
SIZE_MAXSHOW Message is sent to all pop-up windows when some other window has been restored to its former size.
SIZE_MINIMIZED Window has been minimized.
SIZE_RESTORED Window has been resized, but neither the SIZE_MINIMIZED nor SIZE_MAXIMIZED value applies.
 nWidthValue of the low-order word of lParam. Specifies the new width of the client area. nHeightValue of the high-order word of lParam. Specifies the new height of the client area.  Return ValuesIf an application processes this message, it should return zero. ResIf the SetScrollPos or MoveWindow function is called for a child window as a result of the WM_SIZE message, the bRedraw parameter should be nonzero to cause the window to be repainted. 
Although the width and height of a window are 32-bit values, the nWidth and nHeight parameters of the WM_SIZE message contain only the low-order 16 bits.See AlsoMoveWindow, SetScrollPos 

解决方案 »

  1.   

    这三个事件:
    procedure TForm1.FormResize(Sender: TObject);
    procedure TForm1.ApplicationEvents1Minimize(Sender: TObject);
    procedure TForm1.ApplicationEvents1Restore(Sender: TObject);
      

  2.   

    如果要判断自己的程序是否被最小化,首先定义
    protected procedure OnMin(Sender:Tobject);
    然后在TForm1.FormCreate中加一句
    application.OnMinimize:=OnMin;
    最后在OnMin中写你需要执行的代码。但如果要判断其它的程序是否被最小化,就可能要用HOOK了。
      

  3.   

    你们说得都不太好,我已经知道了用WMSysCommand就行,不过还是要谢谢你们,分照给^_^
      

  4.   

        void __fastcall OnWM_SYSCOMMAND(TMessage &Msg);
        BEGIN_MESSAGE_MAP
          MESSAGE_HANDLER(WM_SYSCOMMAND, TMessage, OnWM_SYSCOMMAND)
        END_MESSAGE_MAP(TForm)
    .................
    /*********************************************************
      当按下 窗口的系统按钮时 会产生 WM_SYSCOMMAND 消息
      WParam 为类型
        SC_RESTORE      回复窗口大小
        SC_MINIMIZE     最小化
        SC_MAXIMIZE     最大化
    *********************************************************/
    void __fastcall TForm1::OnWM_SYSCOMMAND(TMessage &Msg)
    {
      bool bDispatch= false;  switch (Msg.WParam)
      {
      case SC_MINIMIZE:
        if (ChkBoxEnableMinimize->Checked)
          bDispatch= true;
        break;
      default:
        bDispatch= true;
      }
      if (bDispatch)
        TForm::Dispatch(&Msg);
    }bcb 的代码,和delphi的大同小异了。