|
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "Demo1.h"
#include "MainFrm.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)
//{{AFX_MSG_MAP(CMainFrame)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code !
ON_WM_CREATE()
ON_COMMAND(ID_VIEW_MYBAR, OnViewMybar)
ON_UPDATE_COMMAND_UI(ID_VIEW_MYBAR, OnUpdateViewMybar)
//}}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 (CFrameWnd::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
}
if (!m_wndMyBar.Create(_T("My Bar"), this, 123))
{
TRACE0("Failed to create mybar\n");
return -1; // fail to create
}
m_wndMyBar.SetBarStyle(m_wndMyBar.GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
EnableDocking(CBRS_ALIGN_ANY);
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
m_wndMyBar.EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
DockControlBar(&m_wndMyBar, AFX_IDW_DOCKBAR_LEFT);
CString sProfile(_T("BarState"));
if (VerifyBarState(sProfile))
{
m_wndMyBar.LoadState(sProfile);
LoadBarState(sProfile);
}
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::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
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
BOOL CMainFrame::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
CString sProfile(_T("BarState"));
m_wndMyBar.SaveState(sProfile);
SaveBarState(sProfile);
return CFrameWnd::DestroyWindow();
}
void CMainFrame::OnViewMybar()
{
// TODO: Add your command handler code here
BOOL bShow = m_wndMyBar.IsVisible();
ShowControlBar(&m_wndMyBar, !bShow, FALSE);
}
void CMainFrame::OnUpdateViewMybar(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable();
pCmdUI->SetCheck(m_wndMyBar.IsVisible());
}
// This function is Copyright (c) 2000, Cristi Posea.
// See www.datamekanix.com for more control bars tips&tricks.
BOOL CMainFrame::VerifyBarState(LPCTSTR lpszProfileName)
{
CDockState state;
state.LoadState(lpszProfileName);
for (int i = 0; i < state.m_arrBarInfo.GetSize(); i++)
{
CControlBarInfo* pInfo = (CControlBarInfo*)state.m_arrBarInfo[i];
ASSERT(pInfo != NULL);
int nDockedCount = pInfo->m_arrBarID.GetSize();
if (nDockedCount > 0)
{
// dockbar
for (int j = 0; j < nDockedCount; j++)
{
UINT nID = (UINT) pInfo->m_arrBarID[j];
if (nID == 0) continue; // row separator
if (nID > 0xFFFF)
nID &= 0xFFFF; // placeholder - get the ID
if (GetControlBar(nID) == NULL)
return FALSE;
}
}
if (!pInfo->m_bFloating) // floating dockbars can be created later
if (GetControlBar(pInfo->m_nBarID) == NULL)
return FALSE; // invalid bar ID
}
return TRUE;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.