Solved

Removing/disabling close box on CEditView

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ORA-01403: no data found 43 106
if loop in java 3 153
EvenOdd challenge 10 127
Work with App store 7 68
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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 a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

829 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