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


// MainFrm.cpp : implementation of the CMainFrame class 
// 
 
#include "stdafx.h" 
#include "MapMark.h" 
 
#include "MainFrm.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
#define SHOW_TIMER    1			//显示时钟 
 
///////////////////////////////////////////////////////////////////////////// 
// CMainFrame 
 
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd) 
 
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) 
	//{{AFX_MSG_MAP(CMainFrame) 
	ON_WM_CREATE() 
	ON_WM_CLOSE() 
	ON_WM_TIMER() 
	ON_COMMAND(ID_VIEW_TOOLBAR, OnViewToolbar) 
	ON_UPDATE_COMMAND_UI(ID_VIEW_TOOLBAR, OnUpdateViewToolbar) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
static UINT indicators[] = 
{ 
	ID_SEPARATOR,           // status line indicator 
	ID_INDICATOR_SCALE,			//地图比例尺 
	ID_INDICATOR_COORDINATE,	//鼠标位置坐标 
	ID_INDICATOR_CLOCK,			//时钟 
}; 
 
///////////////////////////////////////////////////////////////////////////// 
// 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; 
 
	//获取显示分辨率,指定大窗口大小 
	CDC *pDC=GetDC(); 
	HDC m_hDC=pDC->m_hDC; 
	m_iScrX=GetDeviceCaps(m_hDC,HORZRES); 
	m_iScrY=GetDeviceCaps(m_hDC,VERTRES); 
 
	SetWindowPos(&CFrameWnd::wndTop,0,0,m_iScrX,m_iScrY,SWP_SHOWWINDOW);	//指定主窗口位置、大小 
	SetWindowText("地图标绘"); 
	 
	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 
	} 
	// 设置状态栏的字体、字号 
	CFont *pStatusFont;		 
	int iptSize = 14; 
	char *pszFace="宋体";		//MS Serif 
	 
	pStatusFont = new CFont(); 
	pStatusFont->CreateFont(-iptSize,0,0,0,FW_MEDIUM,0,0,0,0,0,0,0,0,pszFace); 
	m_wndStatusBar.SetFont(pStatusFont,1); 
 
	// TODO: Delete these three lines if you don't want the toolbar to 
	//  be dockable 
	m_wndToolBar.EnableDocking(CBRS_ALIGN_TOP); 
	EnableDocking(CBRS_ALIGN_TOP); 
	DockControlBar(&m_wndToolBar); 
 
	//创建标绘工具栏 
	if (!m_MarkBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP 
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || 
		!m_MarkBar.LoadToolBar(IDR_TOOLMARK)) 
	{ 
		TRACE0("Failed to create toolbar\n"); 
		return -1;      // fail to create 
	} 
 
	m_MarkBar.EnableDocking(CBRS_ALIGN_ANY); 
	EnableDocking(CBRS_ALIGN_ANY); 
	m_MarkBar.SetWindowText("标绘");	//工具栏标题 
	m_MarkBar.m_nMRUWidth = 90;			//工具栏宽度 
	 
	CPoint pt(1100,60);					//工具栏定位 
	ClientToScreen(&pt); 
	FloatControlBar(&m_MarkBar,pt); 
 
	//==========定时器,时间间隔设为1000毫秒,用于时钟显示 
	SetTimer(SHOW_TIMER,1000,NULL); 
 
	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 
	cs.hMenu=NULL; 
	cs.style=WS_BORDER|WS_CAPTION|CBRS_TOOLTIPS; 
 
	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::OnClose()  
{ 
	// TODO: Add your message handler code here and/or call default 
	int iResult; 
	iResult=MessageBox("确实要退出系统吗?\r\n","警告",MB_ICONWARNING|MB_OKCANCEL); 
	if(IDOK==iResult) 
	{ 
		CFrameWnd::OnClose(); 
	} 
} 
 
void CMainFrame::OnTimer(UINT nIDEvent)  
{ 
	// TODO: Add your message handler code here and/or call default 
	CTime time; 
	CString sTime,strInfo; 
 
	if (nIDEvent==SHOW_TIMER) 
	{ 
		time = CTime::GetCurrentTime();					//得到当前时间 
		sTime = time.Format("%Y年%m月%d日 %H:%M:%S");	//转换时间格式 
		m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_CLOCK),sTime); //状态栏显示时钟 
	} 
	 
	CFrameWnd::OnTimer(nIDEvent); 
} 
 
void CMainFrame::OnViewToolbar()  
{ 
	ShowControlBar(&m_MarkBar,TRUE,TRUE); 
	m_MarkBar.IsVisible(); 
} 
 
void CMainFrame::OnUpdateViewToolbar(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
	if (m_MarkBar.IsVisible()) 
	{ 
		pCmdUI->Enable(FALSE); 
	} 
	else 
	{ 
		pCmdUI->Enable(TRUE); 
	} 
}