Solved

Disable the [X] "close" in an window

Posted on 1999-01-26
2
237 Views
Last Modified: 2008-03-10
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
Comment
Question by:win32
2 Comments
 
LVL 3

Accepted Solution

by:
_Scotch_ earned 0 total points
ID: 1185223
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
 
LVL 10

Expert Comment

by:viktornet
ID: 1185224
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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question