Solved

Removing/disabling close box on CEditView

Posted on 1997-04-04
5
265 Views
Last Modified: 2013-11-20
I am trying to remove the close box (X box in upper right hand corner) on a CEditView window which is an MDI child window.  Since I have not been able to figure this out I have also tried handling the WM_CLOSE message for this window, intending on calling ShowWindow(SW_MINIMIZE) from the OnClose handler.  Apparently the WM_CLOSE message is being handled by the edit control because it never gets to the window.  I have tried PreTranslateMessage and DefWndProc  as well.
0
Comment
Question by:glee
  • 2
  • 2
5 Comments
 
LVL 1

Expert Comment

by:MarkusLoibl
ID: 1300833
I know how to remove the close-box:
Do not use the WS_SYSMENU-style-bit in
your Child Frame, e.g:
BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
{
      cs.style = WS_CHILD | WS_VISIBLE | WS_OVERLAPPED | WS_CAPTION
            | FWS_ADDTOTITLE | WS_THICKFRAME | WS_MAXIMIZEBOX | WS_MINIMIZEBOX;
      return CMDIChildWnd::PreCreateWindow(cs);
}

The problem with this code is, that you also loose your system-menu of your mdi-window and, who knows why?, you do not see the minimize or maximize buttons


0
 

Author Comment

by:glee
ID: 1300834
You partially helped me by indirectly pointing out that I need to be handling the messages at the frame window level, and not at the CEditView level.  So, I can now get access to the WM_CLOSE message that I was trying to trap as one of my alternate solutions.

However, your suggestion of turning off the WS_SYSMENU bit does not work well.  It grays the close box and leave the min/max buttons on the title bar when the child window is not maximized.  However, if you maximize the window you lose access to the min/max buttons so you can't restore the window.  You have to select window, tile (or cascade, etc...) to get resize the window at all.  This is not acceptable.
0
 
LVL 1

Expert Comment

by:MarkusLoibl
ID: 1300835
I know, I'm working on it (next monday)!

0
 
LVL 11

Accepted Solution

by:
mikeblas earned 70 total points
ID: 1300836
In the frame, write a handler for WM_SYSCOMMAND.  If it is sent to you and nID is SC_CLOSE , just ignore it.  Otherwise, call the base calss implementation.

Maybe, if you have an MDI application, the code will look like this:

void CChildFrame::OnSysCommand( UINT nID, LPARAM lParam )
{
   if ((0xFFF0 & nID) == SC_CLOSE)
      return;
   else
      CMDIChildWnd::OnSysCommand(nID, lParam);
}

This'll leave the "X" button enabled and the "Close" choice in the system menu.  If you want to remove the Close command and have the button become gray, you can modify the system menu at the time your frame window is created:

int CChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
   if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
      return -1;

   CMenu* pMenu = GetSystemMenu(FALSE);
   pMenu->DeleteMenu(SC_CLOSE, MF_BYCOMMAND);
   pMenu->DeleteMenu(5, MF_BYPOSITION);
   return 0;
}

.B ekiM


0
 

Author Comment

by:glee
ID: 1300837
Then the only way to totally remove the close box is to disable the system menu?
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sumDigits challenge 9 154
Prevent this page from creating additional dialogs. 3 537
Not needed 13 113
Increment column based of a FK 8 23
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

831 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