The framework calls this member function when the user selects a command from the Control menu, or when the user selects the Maximize or the Minimize button.
尤其是最大化和最小化視窗的時候,比如現在軟體的流行的點關閉按鈕,不是退出而是隱藏的情況,就可以在這裡來實現,
void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == SC_CLOSE)
ShowWindow(SW_HIDE);
.....
}
注意:nID參數的低四位被Windows內部使用。當應用程式測試nID的值時,它必須用位與操作符AND將值0xFFF0與nID的值組合在一起以獲得正確的結果
就是這樣來實現的,
注意和PreTranslateMessage的區別
PreTranslateMessage是用來截獲訊息的,msdn的解釋如下
Used by class cwinapp to translate window messages before they are dispatched to the TranslateMessage and DispatchMessage Windows functions.
virtual BOOL PreTranslateMessage(
MSG* pMsg
);
nID
SC_CLOSE Close the CWnd object. //關閉
SC_MAXIMIZE (or SC_ZOOM) Maximize the CWnd object.//最大化
SC_MINIMIZE (or SC_ICON) Minimize the CWnd object.//最小化
SC_RESTORE Restore window to normal position and size.//還原
SC_SIZE Size the CWnd object. //大小
SC_MOVE Move the CWnd object.//移動