Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Chapter 5: The Document/View Architecture Visual C++ and MFC Fundamentals


BOOL CExerciseDoc::OnNewDocument()
{
return CDocument::OnNewDocument();
}

CExerciseApp theApp;


  1. Test the application. Change the content of the empty file and save it

  2. Close the application and return to MSVC.


5.3.3 SDI Improvements: The Frame.........................................................


The CWnd::OnCreate() method is used to create a window and it is usually meant to do
this using its default configured features. Therefore, anything you want to display on the
frame when the application displays, you can do so when creating the application.
Therefore, the frame is typically used to create and display the toolbar(s), dialog bar(s),
and status bar.

After the frame has been created, if you want to modified something on it, you can do so
after it has been created but before it is displayed to the user. To do this, you can use the
PreCreateWindow() method of the CWnd class. Its syntax is:

virtual void PreCreateWindow(CREATESTRUCT& cs);

This method takes a reference to CREATESTRUCT class, modifies and returns it with
the new characteristics. For example, you can use this method to remove the Minimize
and the Maximize system buttons on the title bar as follows:

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style &= ~(WS_MAXIMIZEBOX | WS_MINIMIZEBOX);

return CFrameWnd::PreCreateWindow(cs);
}

Practical Learning: Improving the Frame



  1. To use the CWnd::PreCreateWindow() virtual method, in the header file, declare it
    as follows:


class CMainFrame : public CFrameWnd
{
DECLARE_DYNCREATE(CMainFrame)

afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
DECLARE_MESSAGE_MAP()
};


  1. To modify the dimensions of the window at start up, implement the method as
    follows:

Free download pdf