Trapping the minimzing or maximizing of a Form

When the minimize or maximize option is performed, Windows will send your Form the WM_SYSCOMMAND message.  The goal here, is to examine the WM_SYSCOMMAND message and look for the minimize/maximize flags. 

KEYWORDS: WM_SYSCOMMAND, SC_MINIMIZE, SC_MAXIMIZE 


 

// in Form's header...
  void __fastcall WMSysCommand(TMessage &Msg); 

BEGIN_MESSAGE_MAP 
    MESSAGE_HANDLER(WM_SYSCOMMAND, TMessage, WMSysCommand) 
END_MESSAGE_MAP(TForm) 

 


 
 

//---------------------------------------------------------------------------
// in Form's source...

void __fastcall TForm1::WMSysCommand(TMessage &Msg)
{
    unsignedint sys_code = Msg.WParam & 0xFFF0;
    switch (sys_code)
    {
        case SC_MINIMIZE:
        {
            // minimize command requested
            // TO TRAP: comment out the following two lines,
            // and remove the break line.
            // Msg.Result = 0;
            // return;
            break;
        }
        case SC_MAXIMIZE:
        {
            // maximize command requested
            // TO TRAP: comment out the following two lines,
            // and remove the break line.
            // Msg.Result = 0;
            // return;
            break;
        }
    }
    TForm::Dispatch(&Msg);
}