?
Solved

Removing/disabling close box on CEditView

Posted on 1997-04-04
5
Medium Priority
?
272 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
[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
  • 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 140 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

741 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