Handling a Form Moving event 

If you want notification before a Form is actually moved, handle the WM_MOVING message.  If you want notification after a Form is moved, handled the WM_MOVE message.  The method presented here can also be used for notification that a Form has been moved.  However unlike for the WM_MOVE message, the information encoded as the low-order and high-order word of the long parameter (LParam) of the WM_SYSCOMMAND message can be used to determine the position of the Form before it was moved.  The WParam data member is set to 0xF012 (61458 = SC_MOVE + HTCAPTION).

KEYWORDS: WM_SYSCOMMAND, 0xf012 


 

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

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

 


 
 

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

void __fastcall TChildForm1::CatchDrag(TMessage &Msg) 

    TForm::Dispatch(&Msg); 
    if ((Msg.WParam & 0xFFF0) == SC_MOVE + HTCAPTION) 
    { 
        int Previous_MouseX_Position = LOWORD(Msg.LParam); 
        int Previous_MouseY_Position = HIWORD(Msg.LParam); 
        // process accordingly...
    } 
}