Solved

Removing/disabling close box on CEditView

Posted on 1997-04-04
5
264 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 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

27 Experts available now in Live!

Get 1:1 Help Now