Solved

Disable the [X] "close" in an window

Posted on 1999-01-26
2
233 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now