home *** CD-ROM | disk | FTP | other *** search
- // MainFrm.cpp : implementation of the CMainFrame class
- //
-
- #include "stdafx.h"
- #include "MFCIteratorDemo.h"
-
- #include "MainFrm.h"
-
- /******************************************************************************/
- // DEMO code
-
- // Include the iterator headers:
- #include "NestedMFCIterator.h"
- #include "MFCIterators.h"
-
- #include < algorithm > // std library algorithm classes header
-
- // End of DEMO code section
- /******************************************************************************/
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /******************************************************************************/
- // DEMO code
-
- using std::for_each; // We're using the std library 'for_each' algorithm
-
- namespace { // start anonymous namespace for file-scope types
-
- // Create an iterator type for all views in a CDocTemplate
- typedef NestedMFCIter < ViewIter, DocIter, CDocTemplate > DocTemplateViewIter;
-
- // Create an iterator type for all views in a CWinApp
- typedef NestedMFCIter < DocTemplateViewIter, CDocTemplateIter, CWinApp > AppViewIter;
-
-
- // Define a predicate class to set the parent frame of a view to a desired show state
- class WindowShow {
- public:
- WindowShow(int nCmdShow) : m_CmdShow(nCmdShow) {} // constructor
-
- // Predicate function
- void operator()(CView* pView) { pView->GetParentFrame()->ShowWindow(m_CmdShow); }
-
- private:
- int m_CmdShow; // Stores the desired show state
- };
-
- // An alternative predicate function that toggles the individual window's minimised state.
- // Try passing this to for_each in OnWindowToggleMinimiseAll, instead of class WindowShow.
- // Note that when passing a function, the parentheses are omitted, so the call will look
- // like this:
- //
- // for_each(AppViewIter(pApp), AppViewIter::end(), WindowShow);
- //
- void WindowShow(CView* pView)
- {
- CFrameWnd* pFrame = pView->GetParentFrame();
- pFrame->ShowWindow(pFrame->IsIconic() ? SW_RESTORE : SW_SHOWMINNOACTIVE);
- }
-
- // This may be of interest too. Try uncommenting line 2 in OnWindowToggleMinimiseAll().
- // A class to lock window updating until it goes out of scope
- class CWaitWindowUpDate {
- public:
- CWaitWindowUpDate(CWnd* pWnd) : m_pWnd(pWnd) { ASSERT(pWnd); pWnd->LockWindowUpdate(); }
- ~CWaitWindowUpDate() { m_pWnd->UnlockWindowUpdate(); }
- private:
- CWnd* m_pWnd;
- };
-
- } // end of anonymous namespace
-
- // End of DEMO code section
- /******************************************************************************/
-
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame
-
- IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
-
- BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
- //{{AFX_MSG_MAP(CMainFrame)
- ON_WM_CREATE()
- ON_COMMAND(ID_WINDOW_TOGGLE_MINIMISEALL, OnWindowToggleMinimiseAll)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- static UINT indicators[] =
- {
- ID_SEPARATOR, // status line indicator
- ID_INDICATOR_CAPS,
- ID_INDICATOR_NUM,
- ID_INDICATOR_SCRL,
- };
-
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame construction/destruction
-
- CMainFrame::CMainFrame()
- {
- // TODO: add member initialization code here
-
- }
-
- CMainFrame::~CMainFrame()
- {
- }
-
- int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
-
- if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
- | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
- !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
- {
- TRACE0("Failed to create toolbar\n");
- return -1; // fail to create
- }
-
- if (!m_wndStatusBar.Create(this) ||
- !m_wndStatusBar.SetIndicators(indicators,
- sizeof(indicators)/sizeof(UINT)))
- {
- TRACE0("Failed to create status bar\n");
- return -1; // fail to create
- }
-
- // TODO: Delete these three lines if you don't want the toolbar to
- // be dockable
- m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
- EnableDocking(CBRS_ALIGN_ANY);
- DockControlBar(&m_wndToolBar);
-
- return 0;
- }
-
- BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
- {
- if( !CMDIFrameWnd::PreCreateWindow(cs) )
- return FALSE;
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
-
- return TRUE;
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame diagnostics
-
- #ifdef _DEBUG
- void CMainFrame::AssertValid() const
- {
- CMDIFrameWnd::AssertValid();
- }
-
- void CMainFrame::Dump(CDumpContext& dc) const
- {
- CMDIFrameWnd::Dump(dc);
- }
-
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame message handlers
-
- /******************************************************************************/
- // DEMO code
-
- // Toggle all views between minimised and restored using std::for_each() and the
- // application view iterator 'AppViewIter' (defined on line 36 above), together
- // with the WindowShow predicate class.
-
- void CMainFrame::OnWindowToggleMinimiseAll()
- {
- CWaitCursor cwc; // Wait cursor until end of scope
- // CWaitWindowUpDate cwu(this); // Wait to update window until end of scope
-
- // Flag for show state
- static int show(SW_SHOWMINNOACTIVE);
-
- // Get application (to be the outermost container)
- CWinApp* pApp = AfxGetApp();
-
- // Do WindowShow on every view in the application
- for_each(AppViewIter(pApp), AppViewIter::end(), WindowShow(show));
-
- // Toggle the show state flag
- show = (show == SW_SHOWMINNOACTIVE) ? SW_RESTORE : SW_SHOWMINNOACTIVE;
- }
-
- // An alternative way of doing this would be to toggle the individual state of each
- // window, minimising normal windows and restoring minimised windows. In this case,
- // the static 'show' flag would not be required, and the WindowShow class could be
- // replaced by a WindowShow function that would call IsIconic() on the parent frame:
- //
- // void WindowShow(CView* pView)
- // {
- // CFrameWnd* pFrame = pView->GetParentFrame();
- // pFrame->ShowWindow(pFrame->IsIconic() ? SW_RESTORE : SW_SHOWMINNOACTIVE);
- // }
- //
-
- // End of DEMO code section
- /******************************************************************************/
-
- BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
- {
- dynamic_cast<CMFCIteratorDemoApp*>(AfxGetApp())->OnAppAbout();
- return CMDIFrameWnd::OnCreateClient(lpcs, pContext);
- }
-