Link to home
Start Free TrialLog in
Avatar of win32
win32

asked on

Disable the [X] "close" in an window

I have made a window like this:
hwndBMP1 = CreateWindow ("edit", NULL, WS_CHILD| WS_CLIPSIBLINGS |WS_VISIBLE | ES_LEFT | WS_OVERLAPPEDWINDOW | SS_BITMAP | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 140, 0, 450, 200, hwnd, (HMENU) BMP1ID,((LPCREATESTRUCT) lParam) -> hInstance, NULL) ;

>How do I disable the "[X]" close in the sysmenu<, or can
i do it like this:
WM_CLOSE : MessageBox(hwnd,"Cant close that window");
ASKER CERTIFIED SOLUTION
Avatar of _Scotch_
_Scotch_

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
here is how,...

void SetCloseState(BOOL bEnabled)
{
  CMenu* hSysMenu;
  hSysMenu = GetSystemMenu(FALSE);
  if (hSysMenu != 0) {
    if(bEnabled)
      EnableMenuItem(hSysMenu, SC_CLOSE, MF_ENABLED);
    else
      EnableMenuItem(hSysMenu, SC_CLOSE, MF_DISABLED | MF_GRAYED);
  }
}

YOu can call it like this,,,,

SetCloseState(TRUE); //Enable the [X] button
SetCloseState(FALSE);  //Disable the [X] button

Hope this helps...

-Viktor
--Ivanov