關於部落格
順子&阿芳的部落格
  • 86807

    累積人氣

  • 1

    今日人氣

    2

    追蹤人氣

『BCB』判斷使用者按下視窗的最小化、最大化、還原、關閉

動作說明:
 當使用者按下視窗的最小化按鈕,會產生SC_MINIMIZE,我就是針對這個訊息來把視窗縮小。

程式碼:
在 Unit1.h 加入紅色的文字部分
class TForm1 : public TForm
{
private: // User declarations
    TWndMethod OldFormWndProc;
    void __fastcall FormWndProc(TMessage& Message);
};

在 Unit.cpp 加入紅色的文字部分
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
    OldFormWndProc = this->WindowProc;
    this->WindowProc = FormWndProc;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormWndProc(TMessage& Message)
{
    OldFormWndProc(Message);

 

    if (Message.Msg == WM_SYSCOMMAND) { // 系統命令
        if (Message.WParam == SC_MINIMIZE) { // 最小化事件
            TrayIcon1->Minimize(); // 縮小視窗
            TrayIcon1->Visible = true; // 顯示常駐圖示
        }
        if (Message.WParam == SC_MAXIZE) { // 最大化
        }
        if (Message.WParam == SC_RESTORE) { // 還原
        }
        if (Message.WParam == SC_CLOSE) { // 關閉
        }
    }
}

相關資料:
在MSDN的說明 WM_SYSCOMMAND

WM_SYSCOMMAND Notification


A window receives this message when the user chooses a command from the Window menu (formerly known as the system or control menu) or when the user chooses the maximize button, minimize button, restore button, or close button.

Syntax

WM_SYSCOMMAND
WPARAM wParam
LPARAM lParam;

Parameters

wParam

SC_CLOSE Closes the window. 
SC_CONTEXTHELP Changes the cursor to a question mark with a pointer. If the user then clicks a control in the dialog box, the control receives a WM_HELP message. 
SC_DEFAULT Selects the default item; the user double-clicked the window menu.  
SC_HOTKEY
Activates the window associated with the application-specified hot key. The lParam parameter identifies the window to activate. 
SC_HSCROLL Scrolls horizontally. 
SC_KEYMENU Retrieves the window menu as a result of a keystroke. For more information, see the Remarks section. 
SC_MAXIMIZE Maximizes the window. 
SC_MINIMIZE Minimizes the window. 
SC_MONITORPOWER Sets the state of the display. This command supports devices that have power-saving features, such as a battery-powered personal computer.
The lParam parameter can have the following values:
1 - the display is going to low power
2 - the display is being shut off
SC_MOUSEMENU Retrieves the window menu as a result of a mouse click. 
SC_MOVE Moves the window. 
SC_NEXTWINDOW Moves to the next window. 
SC_PREVWINDOW Moves to the previous window. 
SC_RESTORE Restores the window to its normal position and size. 
SC_SCREENSAVE Executes the screen saver application specified in the [boot] section of the System.ini file. 
SC_SIZE Sizes the window. 
SC_TASKLIST Activates the Start menu. 
SC_VSCROLL Scrolls vertically.

lParam
    The low-order word specifies the horizontal position of the cursor, in screen coordinates, if a window menu command is chosen with the mouse. Otherwise, this parameter is not used.
    The high-order word specifies the vertical position of the cursor, in screen coordinates, if a window menu command is chosen with the mouse. This parameter is –1 if the command is chosen using a system accelerator, or zero if using a mnemonic.

 

 

 

 

 

 

 

相簿設定
標籤設定
相簿狀態