⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainfrm.cpp

📁 Visual c++.程序设计培训教程
💻 CPP
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "2DCAD.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_TIMER()
	ON_WM_CLOSE()
	//}}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))//装载工具条资源IDR_GRAPHTOOL
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      //如果创建失败,返回-1
	}

	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_newToolBar.SetWindowText("Graph Tools");//设置绘图工具条标题
	m_wndToolBar.SetWindowText("标准");//设置缺省工具条标题

	//////////////////////////////////
	//设置一个计时器,时间间隔为1秒
	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:使用CWnd::ShowWindow函数显示隐藏工具条
	if(m_newToolBar.IsWindowVisible())
	{
		m_newToolBar.ShowWindow(SW_HIDE);//如果可见,就隐藏
	}
	else
	{
		m_newToolBar.ShowWindow(SW_SHOW);//如果不可见,就显示
	}

//	DockControlBar(&m_newToolBar);//停靠工具条
	RecalcLayout();	//重新排列工具条

	//方法2:使用CMainFrame::ShowControlBar函数显示隐藏工具条
//	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::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);
}

void CMainFrame::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	KillTimer(1);//释放计时器
	
	CFrameWnd::OnClose();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -