This is beginner level post. How we can make a Window immovable?
Roughly we’ve two methods to do this.
Method #1. Handle the NCHITTEST message and ignore while user click on the caption area (Titlebar). This method doesn’t work well in Windows 7/Vista if Aero is enabled. This method works with any type of Window having titlebar. The disadvantage of this method is , the user will still able to move using keyboard, if system menu is available.
LRESULT CMoveWindowSampleDlg::OnNcHitTest(CPoint point)
{
UINT nHitTest = CDialogEx::OnNcHitTest(point);
if( HTCAPTION == nHitTest )
nHitTest = HTNOWHERE;
return nHitTest;
}
Method #2 – Remove the Move command from System Menu (Works with windows having system menu stle (WS_SYSMENU) ). The the Move command in the system menu will be removed in this case. Windows will internally disable the movement of this kind of Windows.
BOOL CMoveWindowSampleDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
pSysMenu->RemoveMenu( SC_MOVE, MF_BYCOMMAND );
}
...
return TRUE;
}
PS: Using method 2, this is the same method we use to disable the close button of a Window. For disabling a menu/titlebar button. Call EnableMenu function with relevant parameters.

