Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,
how to disabled close button in a simple dialog?

Thanks
Vivek chauhan
Posted
Updated 7-Dec-18 12:56pm
v2

Here is an example for you that will enable/disable the close button in runtime:
C++
BOOL bEnable = FALSE;     // TRUE to enable and FALSE to disable

//.....

UINT nMenuf = bEnable ? (MF_BYCOMMAND) : (MF_BYCOMMAND | MF_GRAYED | MF_DISABLED);

CMenu* pSysMenu = GetSystemMenu(FALSE);
if(pSysMenu)
{
  pSysMenu->EnableMenuItem(SC_CLOSE, nMenuf);
}


You will need to place this code in appropriate place (i.e. in OnInitDialog) of your dialog class. :)
 
Share this answer
 
v2
Add CS_NOCLOSE to it's class style.
 
Share this answer
 
You can use
closebutton.EnableWindow(0);
where closebutton is the variable name of the control.
 
Share this answer
 
Pretty Simple
C++
WNDCLASSA WindClass = { 0 };

WindClass.hbrBackground = (HBRUSH__*)COLOR_WINDOW;
WindClass.hCursor = LoadCursorA((HINSTANCE)NULL, (LPCSTR)IDC_ARROW);
WindClass.hInstance = hInstance;
WindClass.lpszClassName = "WindowClass";
WindClass.lpfnWndProc = WindowProcedure;
WindClass.style = CS_NOCLOSE; /* This line here */
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900