Disable Move
-
Congratulations!!! Good question. I wasted two hours of my life today doing this s..t for you. Below is a solution of the problem:
BOOL CYourDlg::PreTranslateMessage(MSG* pMsg)
{
if((pMsg->message==WM_NCLBUTTONDOWN && SendMessage(WM_NCHITTEST,0,pMsg->lParam)==HTSYSMENU) ||
(pMsg->message==WM_NCRBUTTONDOWN && SendMessage(WM_NCHITTEST,0,pMsg->lParam)==HTCAPTION))
{
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
if(GetStyle()&WS_THICKFRAME)
pSysMenu->EnableMenuItem(SC_SIZE,MF_BYCOMMAND|MF_ENABLED);
else
pSysMenu->EnableMenuItem(SC_SIZE,MF_BYCOMMAND|MF_GRAYED);
if(GetStyle()&WS_MINIMIZEBOX||GetStyle()&WS_MAXIMIZEBOX)
{
if(GetStyle()&WS_MINIMIZEBOX)
{
if(IsIconic())
{
pSysMenu->EnableMenuItem(SC_MINIMIZE,MF_BYCOMMAND|MF_GRAYED);
pSysMenu->EnableMenuItem(SC_RESTORE,MF_BYCOMMAND|MF_ENABLED);
}
else
{
pSysMenu->EnableMenuItem(SC_MINIMIZE,MF_BYCOMMAND|MF_ENABLED);
pSysMenu->EnableMenuItem(SC_RESTORE,MF_BYCOMMAND|MF_GRAYED);
}
}
else
pSysMenu->EnableMenuItem(SC_MINIMIZE,MF_BYCOMMAND|MF_GRAYED);
if(GetStyle()&WS_MAXIMIZEBOX)
{
if(IsZoomed())
{
pSysMenu->EnableMenuItem(SC_MAXIMIZE,MF_BYCOMMAND|MF_GRAYED);
pSysMenu->EnableMenuItem(SC_RESTORE,MF_BYCOMMAND|MF_ENABLED);
}
else
{
pSysMenu->EnableMenuItem(SC_MAXIMIZE,MF_BYCOMMAND|MF_ENABLED);
pSysMenu->EnableMenuItem(SC_RESTORE,MF_BYCOMMAND|MF_GRAYED);
}
}
else
pSysMenu->EnableMenuItem(SC_MAXIMIZE,MF_BYCOMMAND|MF_GRAYED);
}pSysMenu->EnableMenuItem(SC_MOVE,MF_BYCOMMAND|MF_GRAYED); // gray MOVE item
int nRet = pSysMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON|TPM_RETURNCMD, LOWORD(pMsg->lParam), HIWORD(pMsg->lParam), this);
PostMessage(WM_SYSCOMMAND,nRet,pMsg->lParam);
return 1;
}
}
return CDialog::PreTranslateMessage(pMsg);
}Regards, Andrzej Markowski
My Latest ArticlesCCustomBitmapButton: An owner-draw button and a frame for the caption bar, in one class. CCustomTabCtrl: A clone of the Excel tab sheet control.