MainFrm.cpp
上传用户:ywlong9188
上传日期:2022-05-31
资源大小:2656k
文件大小:7k
- // MainFrm.cpp : implementation of the CMainFrame class
- //
- #include "stdafx.h"
- #include "Proj.h"
- #include "palettebar.h"
- #include "MainFrm.h"
- #include "Splash.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame
- IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
- BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
- ON_UPDATE_COMMAND_UI(ID_INDICATOR_DATE, OnUpdateDate)
- //{{AFX_MSG_MAP(CMainFrame)
- ON_WM_CREATE()
- ON_COMMAND(ID_VIEW_PALETTE_BAR, OnViewPaletteBar)
- ON_UPDATE_COMMAND_UI(ID_VIEW_PALETTE_BAR, OnUpdateViewPaletteBar)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- static UINT BASED_CODE palette[] =
- {
- // same order as in the bitmap 'palette.bmp'
- ID_DRAW_SELECTION,
- ID_DRAW_LINE,
- ID_DRAW_RECT,
- ID_DRAW_ELLIPSE,
- ID_DRAW_POLYGON,
- ID_DRAW_TEXT,
- ID_DRAW_BAR_GRAPH,
- ID_DRAW_ANIMATE_TAG,
- ID_DRAW_CURSOR,
- ID_DRAW_ISA,
- ID_DRAW_LOOP,
- ID_DRAW_BUTTON,
- ID_DRAW_LIB
- };
- static UINT indicators[] =
- {
- ID_SEPARATOR, // status line indicator
- ID_SEPARATOR,
-
- ID_INDICATOR_NUM,
- ID_INDICATOR_CAPS
- };
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame construction/destruction
- CMainFrame::CMainFrame()
- {
- // TODO: add member initialization code here
-
- }
- CMainFrame::~CMainFrame()
- {
- }
- BOOL CMainFrame::CreatePaletteBar()
- {
- // TODO: Delete these three lines if you don't want the toolbar to
- // be dockable
- if (!m_wndPaletteBar.Create(this)||!m_wndPaletteBar.LoadBitmap(IDB_PALETTE)
- //!m_wndPaletteBar.LoadBitmap(IDB_PALETTE) ||
- // !m_wndPaletteBar.SetIndicators(palette,
- // sizeof(palette)/sizeof(UINT)))
- ||!m_wndPaletteBar.SetButtons(palette,
- sizeof(palette)/sizeof(UINT)))
- {
- TRACE0("Failed to create toolbarn");
- return FALSE; // fail to create
- }
- m_wndPaletteBar.SetBarStyle(m_wndPaletteBar.GetBarStyle() |
- CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
-
- m_wndPaletteBar.SetWindowText(_T("Palette"));
- m_wndPaletteBar.EnableDocking(CBRS_ALIGN_ANY);
- EnableDocking(CBRS_ALIGN_ANY);
- // Create the Palette. We are using hardcoded numbers for ease here
- // normally the location would be read in from an ini file.
- //CPoint pt(GetSystemMetrics(SM_CXSCREEN) - 100,
- // GetSystemMetrics(SM_CYSCREEN) / 3);
- //m_wndPaletteBar.SetColumns(2);
- //FloatControlBar(&m_wndPaletteBar, pt);
- DockControlBar(&m_wndPaletteBar,AFX_IDW_DOCKBAR_LEFT);
- return TRUE;
- }
- int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
- EnableDocking(CBRS_ALIGN_ANY);
- if(!CreatePaletteBar())
- return -1;
- if (!m_wndToolBar.Create(this) ||
- !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
- {
- TRACE0("Failed to create toolbarn");
- return -1; // fail to create
- }
- if (!m_wndStatusBar.Create(this) ||
- !m_wndStatusBar.SetIndicators(indicators,
- sizeof(indicators)/sizeof(UINT)))
- {
- TRACE0("Failed to create status barn");
- return -1; // fail to create
- }
- // TODO: Remove this if you don't want tool tips or a resizeable toolbar
- m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
- CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
- // 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);
- // CG: The following line was added by the Splash Screen component.
CSplashWnd::ShowSplashScreen(this);
- ::Sleep(2000);
- // CG: The following block was inserted by 'Status Bar' component.
- {
- // Find out the size of the static variable 'indicators' defined
- // by AppWizard and copy it
- int nOrigSize = sizeof(indicators) / sizeof(UINT);
- UINT* pIndicators = new UINT[nOrigSize + 2];
- memcpy(pIndicators, indicators, sizeof(indicators));
- // Call the Status Bar Component's status bar creation function
- if (!InitStatusBar(pIndicators, nOrigSize, 60))
- {
- TRACE0("Failed to initialize Status Barn");
- return -1;
- }
- delete[] pIndicators;
- }
- m_wndStatusBar.SetPaneInfo(0,0,SBPS_STRETCH,0);
-
- DragAcceptFiles();
- return 0;
- }
- BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CFrameWnd::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame diagnostics
- #ifdef _DEBUG
- void CMainFrame::AssertValid() const
- {
- CFrameWnd::AssertValid();
- }
- void CMainFrame::Dump(CDumpContext& dc) const
- {
- CFrameWnd::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame message handlers
- void CMainFrame::OnViewPaletteBar()
- {
- BOOL bVisible = ((m_wndPaletteBar.GetStyle() & WS_VISIBLE) != 0);
- ShowControlBar(&m_wndPaletteBar, !bVisible, FALSE);
- RecalcLayout();
-
- }
- void CMainFrame::OnUpdateViewPaletteBar(CCmdUI* pCmdUI)
- {
- BOOL bVisible = ((m_wndPaletteBar.GetStyle() & WS_VISIBLE) != 0);
- pCmdUI->SetCheck(bVisible);
-
-
- }
- void CMainFrame::ActivateFrame(int nCmdShow)
- {
- CFrameWnd::ActivateFrame(SW_SHOWMAXIMIZED);
- }
- void CMainFrame::OnUpdateDate(CCmdUI* pCmdUI)
- {
- // CG: This function was inserted by 'Status Bar' component.
- // Get current date and format it
- CTime time = CTime::GetCurrentTime();
- CString strDate = time.Format(_T("%A, %B %d, %y "));
- // BLOCK: compute the width of the date string
- CSize size;
- {
- HGDIOBJ hOldFont = NULL;
- HFONT hFont = (HFONT)m_wndStatusBar.SendMessage(WM_GETFONT);
- CClientDC dc(NULL);
- if (hFont != NULL)
- hOldFont = dc.SelectObject(hFont);
- size = dc.GetTextExtent(strDate);
- if (hOldFont != NULL)
- dc.SelectObject(hOldFont);
- }
- // Update the pane to reflect the current date
- UINT nID, nStyle;
- int nWidth;
- m_wndStatusBar.GetPaneInfo(m_nDatePaneNo, nID, nStyle, nWidth);
- m_wndStatusBar.SetPaneInfo(m_nDatePaneNo, nID, nStyle, size.cx);
- pCmdUI->SetText(strDate);
- pCmdUI->Enable(TRUE);
- }
- BOOL CMainFrame::InitStatusBar(UINT *pIndicators, int nSize, int nSeconds)
- {
- // CG: This function was inserted by 'Status Bar' component.
- // Create an index for the DATE pane
- m_nDatePaneNo = nSize++;
- pIndicators[m_nDatePaneNo] = ID_INDICATOR_DATE;
- // TODO: Select an appropriate time interval for updating
- // the status bar when idling.
- m_wndStatusBar.SetTimer(0x1000, nSeconds * 1000, NULL);
- return m_wndStatusBar.SetIndicators(pIndicators, nSize);
- }