Solved

Removing/disabling close box on CEditView

Posted on 1997-04-04
5
263 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
Comment Utility
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
Comment Utility
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
Comment Utility
I know, I'm working on it (next monday)!

0
 
LVL 11

Accepted Solution

by:
mikeblas earned 70 total points
Comment Utility
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
Comment Utility
Then the only way to totally remove the close box is to disable the system menu?
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
This video discusses moving either the default database or any database to a new volume.

762 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

9 Experts available now in Live!

Get 1:1 Help Now