Q: How to disbale a dialog from being moved?
A: There are two possibilites when moving a dialog, by click and drag the caption area of the dialog or by using the system menu "move" item and then move the dialog. I will describe how to disable both.
To disable the user from click and drag on the caption of the dialog, you have to handle the WM_NCHITTEST message. You call the base class and check the return value of the CDialog::OnNcHitTest(point) function:
Regarding the system menu, you can either disble the "Move" item or completely remove it.Code:LRESULT CYourDlg::OnNcHitTest(CPoint point) { LRESULT res = CDialog::OnNcHitTest(point); if( res == HTCAPTION) res = HTNOWHERE; return res; }
To disable it, handle the WM_INITMENUPOPUP message in your dialog:
To remove the "Move" item from the system menu, add the following at the end of your OnInitDialog function:Code:void CYourDlg::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu) { CDialog::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu); if ( bSysMenu ) { pPopupMenu->EnableMenuItem( SC_MOVE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED ); } }
Code:CMenu *pMenu = GetSystemMenu(FALSE); pMenu->DeleteMenu(SC_MOVE,MF_BYCOMMAND);


Reply With Quote
Bookmarks