[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 242
  • Last Modified:

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");
0
win32
Asked:
win32
1 Solution
 
_Scotch_Commented:
Dont answer a WM_CLOSE message with a "You cant do that"... As a
user the first thing I'd think is "Why give me a knob if I cant
play with it" :)

Disable it by handling the WM_SHOWWINDOW message and:
        CMenu *pSystemMenu = GetSystemMenu(FALSE);
      CString  ItemText;
      pSystemMenu->GetMenuString(SC_CLOSE, ItemText, MF_BYCOMMAND);
      pSystemMenu->ModifyMenu(SC_CLOSE, MF_BYCOMMAND|MF_STRING|MF_GRAYED,
                                        SC_CLOSE, ItemText);


This has the added benefit of disabling the "close" menu pulldown
under the doodad (er, system menu) in the upper lefthand corner.

0
 
viktornetCommented:
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
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now