www.pudn.com > Toolbar.rar > MainFrm.cpp


// MainFrm.cpp : implementation of the CMainFrame class 
// 
 
#include "stdafx.h" 
#include "Toolbar.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) 
	ON_WM_CREATE() 
	ON_COMMAND(IDM_VIEW_NEWTOOLBAR, OnViewNewtoolbar) 
	ON_UPDATE_COMMAND_UI(IDM_VIEW_NEWTOOLBAR, OnUpdateViewNewtoolbar) 
	ON_COMMAND(ID_JIANG, OnJiang) 
	ON_COMMAND(ID_YONG, OnYong) 
	ON_COMMAND(ID_XIANG, OnXiang) 
	ON_COMMAND(ID_JIA, OnJia) 
	ON_COMMAND(ID_LIU, OnLiu) 
	ON_COMMAND(ID_PENG, OnPeng) 
	ON_COMMAND(ID_XIU, OnXiu) 
	ON_COMMAND(ID_YING, OnYing) 
	//}}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[0].CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP 
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || 
		!m_wndToolBar[0].LoadToolBar(IDR_MAINFRAME)) 
	{ 
		TRACE0("Failed to create toolbar\n"); 
		return -1;      // fail to create 
	} 
 
	if (!m_wndToolBar[1].CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP 
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || 
		!m_wndToolBar[1].LoadToolBar(IDR_TOOLBAR1)) 
	{ 
		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[0].EnableDocking(CBRS_ALIGN_ANY); 
	m_wndToolBar[1].EnableDocking(CBRS_ALIGN_ANY); 
	 
	EnableDocking(CBRS_ALIGN_ANY); 
	DockControlBar(&m_wndToolBar[0]); 
	DockControlBarLeftOf(&m_wndToolBar[1],&m_wndToolBar[0]); 
 
 
 
	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 
 
 
void CMainFrame::OnViewNewtoolbar()  
{ 
	// TODO: Add your command handler code here 
	ShowControlBar(&m_wndToolBar[1],!m_wndToolBar[1].IsWindowVisible(),FALSE); 
} 
 
void CMainFrame::OnUpdateViewNewtoolbar(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
	pCmdUI->SetCheck(m_wndToolBar[1].IsWindowVisible()); 
} 
 
void CMainFrame::DockControlBarLeftOf(CToolBar *Bar, CToolBar *LeftOf) 
{ 
	CRect rect; 
	DWORD dw; 
	UINT n; 
	 
	// get MFC to adjust the dimensions of all docked ToolBars 
	// so that GetWindowRect will be accurate 
	RecalcLayout(); 
	 
	LeftOf->GetWindowRect(&rect); 
    rect.OffsetRect(1,0); 
	dw=LeftOf->GetBarStyle(); 
	n = 0; 
	n = (dw&CBRS_ALIGN_TOP) ? AFX_IDW_DOCKBAR_TOP : n; 
	n = (dw&CBRS_ALIGN_BOTTOM && n==0) ? AFX_IDW_DOCKBAR_BOTTOM : n; 
	n = (dw&CBRS_ALIGN_LEFT && n==0) ? AFX_IDW_DOCKBAR_LEFT : n; 
	n = (dw&CBRS_ALIGN_RIGHT && n==0) ? AFX_IDW_DOCKBAR_RIGHT : n; 
	 
	// When we take the default parameters on rect, DockControlBar will dock 
	// each Toolbar on a seperate line.  By calculating a rectangle, we in effect 
	// are simulating a Toolbar being dragged to that location and docked. 
	DockControlBar(Bar,n,&rect); 
} 
 
 
void CMainFrame::OnJiang()  
{ 
	// TODO: Add your command handler code here 
	MessageBox("½¯"); 
} 
 
void CMainFrame::OnYong()  
{ 
	// TODO: Add your command handler code here 
	MessageBox("ÓÀ"); 
} 
 
void CMainFrame::OnXiang()  
{ 
	// TODO: Add your command handler code here 
	MessageBox("Ïè"); 
} 
 
void CMainFrame::OnJia()  
{ 
	// TODO: Add your command handler code here 
	MessageBox("¼Ò"); 
} 
 
void CMainFrame::OnLiu()  
{ 
	// TODO: Add your command handler code here 
	MessageBox("Áõ"); 
} 
 
void CMainFrame::OnPeng()  
{ 
	// TODO: Add your command handler code here 
	MessageBox("Åí"); 
} 
 
void CMainFrame::OnXiu()  
{ 
	// TODO: Add your command handler code here 
	MessageBox("Ðã"); 
} 
 
void CMainFrame::OnYing()  
{ 
	// TODO: Add your command handler code here 
	MessageBox("Ó¢"); 
}