Click here to Skip to main content
15,884,731 members
Articles / Desktop Programming / MFC
Tip/Trick

How to load a view in maximized mode by default in MFC

Rate me:
Please Sign up or sign in to vote.
5.00/5 (5 votes)
13 Jun 2011CPOL 17.3K   4   1
Addresses the issue of opening a view in maximized mode the proper way in MFC.
Override CFrameWnd::ActivateFrame and pass SW_SHOWMAXIMIZED to the base class function.

Code:
class CChildFrame : public CMDIChildWnd
{
// ...
   // Overrides
   // ClassWizard generated virtual function overrides
   //{{AFX_VIRTUAL(CChildFrame)
   public:
   virtual void ActivateFrame(int nCmdShow = -1);
   //}}AFX_VIRTUAL
// ...
};


void CChildFrame::ActivateFrame(int nCmdShow) 
{
// TODO: Add your specialized code here and/or call the base class
    if (nCmdShow == -1)
    {
        // Show the window in maximized mode 
        // if and only if it is the very first frame
        // Otherwise, do default for user conveniences
        // The user may prefer to keep a previously created view and 
        // frame in restored (not maximized) mode
        // So, it is advisable to keep the newly created view and frame 
        // in the same state as already created views
        if(GetNextWindow() == NULL && GetNextWindow(GW_HWNDPREV) == NULL)
        {
            nCmdShow = SW_SHOWMAXIMIZED;
        }
    }   
   CMDIChildWnd::ActivateFrame(nCmdShow);
}


Thanks to http://www.codeguru.com/forum/showthread.php?t=380988[^].

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead Kotha Technologies
Bangladesh Bangladesh
If you are not in - you are out !
- Chapter 1

Comments and Discussions

 
QuestionThanks a lot Pin
sameera wijerathne23-Mar-12 0:05
sameera wijerathne23-Mar-12 0:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.