News:

MyKidsDiary.in :: Capture your kids magical moment and create your Online Private Diary for your kids

Main Menu

Window's Showing State

Started by sukishan, Jul 12, 2009, 05:26 PM

Previous topic - Next topic

sukishan

Window's Showing State

WM_SHOWWINDOW: After creating a window, it needs to be displayed. Also, if the window was previously hidden, you can decide to show it. On the other hand, if a window is displaying, you may want to hide it, for any reason you judge necessary. To take any of these actions, that is, to show or hide a window, you must send the ON_WM_SHOWWINDOW message. The syntax of this message is:

afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);When using this message, bShow, a boolean argument, determines what state to apply to the window. If it is TRUE, the window needs to be displayed. If it is FALSE, the window must be hidden.

nStatus is a positive integer that can have one of the following values:

SW_PARENTCLOSING: If the window that sent this message is a frame, the window is being minimized. If the window that sent this message is hosted by another window, the window is being hidden.
SW_PARENTOPENING: If the window that sent this message is a frame, the window is being restored. If the window that sent this message is hosted by another window, the window is displaying.
0: The message was sent from a CWnd::ShowWindow() method.
Practical Learning: Showing a Window
To maximize the window at startup, change the program as follows:  Collapse Copy Code#include <AFXWIN.H>

class CMainFrame : public CFrameWnd
{
public:
    CMainFrame ();

protected:
    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
    afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
    DECLARE_MESSAGE_MAP()
};

CMainFrame::CMainFrame()
{
    // Create the window's frame
    Create(NULL, "Windows Application", WS_OVERLAPPEDWINDOW,
           CRect(120, 100, 700, 480), NULL);
}

class CExerciseApp: public CWinApp
{
public:
    BOOL InitInstance();
};

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
    ON_WM_CREATE()
    ON_WM_SHOWWINDOW()
END_MESSAGE_MAP()

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    // Call the base class to create the window
    if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
        return -1;
    return 0;
}

void CMainFrame::OnShowWindow(BOOL bShow, UINT nStatus)
{
    CFrameWnd::OnShowWindow(bShow, nStatus);
   
    // TODO: Add your message handler code here
    ShowWindow(SW_MAXIMIZE);
}

BOOL CExerciseApp::InitInstance()
{
    m_pMainWnd = new CMainFrame ;
    m_pMainWnd->ShowWindow(SW_SHOW);
    m_pMainWnd->UpdateWindow();

    return TRUE;
}

CExerciseApp theApp;Test the program and return to MSVC.
A good beginning makes a good ending