www.pudn.com > MyCAD.rar > MainFrm.cpp
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "MyCAD.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(ID_VIEW_GRAPHTOOL, OnViewGraphtool)
ON_UPDATE_COMMAND_UI(ID_VIEW_GRAPHTOOL, OnUpdateViewGraphtool)
ON_WM_CLOSE()
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_SEPARATOR,
ID_INDICATOR_TIME,
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_newToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_newToolBar.LoadToolBar(IDR_GRAPHTOOL))
{
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);
// 停靠新的工具栏
m_newToolBar.EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_newToolBar);
m_wndToolBar.SetWindowText("标准");
m_newToolBar.SetWindowText("绘图");
// 设置计时器
SetTimer(1,1000,NULL);
// 创建一个无模式的设置线条属性的对话框
m_LineStyleDlg.Create(IDD_LINESTYLE,this);
m_LineStyleDlg.ShowWindow(SW_SHOW);
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::OnViewGraphtool()
{
// TODO: Add your command handler code here
/*
// 方法1
if(m_newToolBar.IsWindowVisible())
m_newToolBar.ShowWindow(SW_HIDE);
else
m_newToolBar.ShowWindow(SW_SHOW);
DockControlBar(&m_newToolBar);
RecalcLayout(); // 重新排列工具栏
*/
// 方法2
ShowControlBar(&m_newToolBar,!m_newToolBar.IsWindowVisible(),FALSE);
}
void CMainFrame::OnUpdateViewGraphtool(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
// 根据工具栏的显示状态设置菜单项是否有选中标志
pCmdUI->SetCheck(m_newToolBar.IsWindowVisible());
}
void CMainFrame::OnClose()
{
// TODO: Add your message handler code here and/or call default
KillTimer(1);
CFrameWnd::OnClose();
}
void CMainFrame::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CTime time;
time = CTime::GetCurrentTime();
CString str = time.Format("%H:%M:%S");
m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_TIME),str);
CFrameWnd::OnTimer(nIDEvent);
}