?
Solved

CFromview-disabling the close window

Posted on 1997-11-10
4
Medium Priority
?
252 Views
Last Modified: 2013-11-20
hello,
   i have a CFormView that my application automatically draw on it's client screen at the start of the application, this is because i specified in appwizard that i want a database view w/file support, so a form is automatically created for me, i want to disable the close window of this form, i want to disable the 'X' box at the upper right hand of the form, so that it cannot be clicked by the user at run time, and also, i want the form to be maximized when that application draws it at the start of the application, how can i do these?  please help, thanks, mallow
0
Comment
Question by:mallow
[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
4 Comments
 

Accepted Solution

by:
Chaya earned 20 total points
ID: 1309754
Since you write that the form window takes up only part of the total client area, I am going on the assumption that you are using an MDI based application.
Each AppWizard create MDI based application has a CMDIChildWnd derived class, usually called CChildFrame as one of its classes. This class forms the frame window for the MDI client, which in this case is a form/record view. All the changes to the window style of the form, have to be done within that class.

Now for the specific answers:
1. Disabling the "close window", and the 'X' box at the upper right hand of the form.
* In ClassWizard, make sure "CChildFrame" is in the class name box, and create a member function for the WM_CREATE message. This should create a CChildFrame::OnCreate message handler. Add the following two lines, as explained below:
 CMenu * sysMenu = GetSystemMenu( FALSE);
 sysMenu->EnableMenuItem(  SC_CLOSE,  MF_DISABLED | MF_BYCOMMAND | MF_GRAYED );
 These two lines get the window's system menu, and then disable the SC_CLOSE menu item, disabling the close and the 'X' in one shot.

2. Creating the form maximized
* In CChildFrame::PreCreateWindow add:
  cs.style = WS_CHILD | WS_VISIBLE | WS_OVERLAPPEDWINDOW | WS_MAXIMIZE;

before :      
return CMDIChildWnd::PreCreateWindow(cs); // Already in code - by AppWizard

this sets the window style to WS_CHILD | WS_VISIBLE | WS_OVERLAPPEDWINDOW - obligatory for MFC 2+ - otherwise you get an ASSERT (see TN019) and adds WS_MAXIMIZE - starting the window maximized.

Good Luck,
Chaya
0
 

Author Comment

by:mallow
ID: 1309755
hello, i tried the code above, i was successful in maximizing the window and graying the 'X' of the window, but it did not disable the 'close window' the 'X' can still be clicked and the it closed the window, do you know what is wrong?  please help
0
 

Expert Comment

by:Chaya
ID: 1309756
Wow! I checked it out and if the window is not maximixed, clicking the 'X' does nothing (as it should), but when maximized, it works as usual. By running Spy on the application, I discovered that when a child window is maximized the minimize, maximize and close buttons are considered bitmaps on the mainframe's window, and therefore not related to the child system menu. The roundabout that worked for me was to add a handler for OnSysCommand and having it ignore the SC_CLOSE command. The code is as follows:

void CChildFrame::OnSysCommand(UINT nID, LPARAM lParam)
{
// TODO: Add your message handler code here and/or call default
// THE FOLLOWING LINE IS WHAT I ADDED
      if (nID != SC_CLOSE )
//
            CMDIChildWnd::OnSysCommand(nID, lParam);
}

Adding this handler is a trifle tricky so I'll give you the full instructions.
* Open ClassWizard in the CChildFrame class.
* Pick the "Class Info" tab and in the "Message filter" drop-down list - choose "Window".
* Go back to the "Message maps" and in the "Messages" list box choose WM_SYSCOMMAND.

Good luck
0
 

Author Comment

by:mallow
ID: 1309757
it worked already, thanks!
0

Featured Post

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

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…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

770 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