?
Solved

Disable the [X] "close" in an window

Posted on 1999-01-26
2
Medium Priority
?
241 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

649 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