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

📄 mainfrm.cpp

📁 地理信息系统(GIS)相关.子图符号转成文字描述的功能.
💻 CPP
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "VCEditDemo.h"

#include "MainFrm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMainFrame

IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
	//{{AFX_MSG_MAP(CMainFrame)
	ON_WM_CREATE()
	ON_WM_SIZE()
	ON_WM_CLOSE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

static UINT indicators[] =
{
	ID_SEPARATOR,           // status line indicator
	ID_INDICATOR_MOUSEPOINT,
	ID_INDICATOR_LAYERINFO,
	ID_INDICATOR_CAPS,
	ID_INDICATOR_NUM,
};

/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction

CMainFrame::CMainFrame()
{
	// TODO: add member initialization code here
	
}

CMainFrame::~CMainFrame()
{
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;

	//允许框架窗口dock各工具条
	EnableDocking(CBRS_ALIGN_ANY);

	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_wndLineEditBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
		!m_wndLineEditBar.LoadToolBar(IDR_LINTOOLBAR))
	{
		TRACE0("Failed to create LineEdit toolbar\n");
		return -1;      // fail to create
	}

	if (!m_wndRegionEditBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
		!m_wndRegionEditBar.LoadToolBar(IDR_REGTOOLBAR))
	{
		TRACE0("Failed to create RegionEdit toolbar\n");
		return -1;      // fail to create
	}

	if (!m_wndPointEditBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
		!m_wndPointEditBar.LoadToolBar(IDR_PNTTOOLBAR))
	{
		TRACE0("Failed to create PointEdit toolbar\n");
		return -1;      // fail to create
	}

	if (!m_wndWindowBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
		!m_wndWindowBar.LoadToolBar(IDR_WINDOWBAR))
	{
		TRACE0("Failed to create Window 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
	}

	m_wndStatusBar.SetPaneText(1,NULL);
	m_wndStatusBar.SetPaneText(2,NULL);

	//设置各工具条的标题
	m_wndToolBar.SetWindowText(_T("标准工具条"));
	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);

	m_wndLineEditBar.SetWindowText(_T("线编辑工具条"));
	m_wndLineEditBar.EnableDocking(CBRS_ALIGN_ANY);

	m_wndRegionEditBar.SetWindowText(_T("区编辑工具条"));
	m_wndRegionEditBar.EnableDocking(CBRS_ALIGN_ANY);

	m_wndPointEditBar.SetWindowText(_T("点编辑工具条"));
	m_wndPointEditBar.EnableDocking(CBRS_ALIGN_ANY);

	m_wndWindowBar.SetWindowText(_T("窗口工具条"));
	m_wndWindowBar.EnableDocking(CBRS_ALIGN_ANY);
	// TODO: Delete these three lines if you don't want the toolbar to
	//  be dockable

	//dock各工具条的位置
	CRect rect;
	DockControlBar(&m_wndToolBar,AFX_IDW_DOCKBAR_TOP);
	RecalcLayout();
	m_wndToolBar.GetWindowRect(&rect);
	rect.OffsetRect(10,0);
	DockControlBar(&m_wndWindowBar,AFX_IDW_DOCKBAR_TOP,&rect);
    RecalcLayout();
	m_wndWindowBar.GetWindowRect(&rect);
	rect.OffsetRect(10,0);
	DockControlBar(&m_wndLineEditBar,AFX_IDW_DOCKBAR_TOP,&rect);
	RecalcLayout();
	m_wndLineEditBar.GetWindowRect(&rect);
	rect.OffsetRect(10,0);
	DockControlBar(&m_wndPointEditBar,AFX_IDW_DOCKBAR_TOP,&rect);
	RecalcLayout();
	m_wndPointEditBar.GetWindowRect(&rect);
	rect.OffsetRect(10,0);
	DockControlBar(&m_wndRegionEditBar,AFX_IDW_DOCKBAR_TOP,&rect);

	//m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
	//EnableDocking(CBRS_ALIGN_ANY);
	//DockControlBar(&m_wndToolBar);

	return 0;
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	if( !CMDIFrameWnd::PreCreateWindow(cs) )
		return FALSE;
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	cs.style = WS_OVERLAPPED | WS_CAPTION | FWS_ADDTOTITLE
		| WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_MAXIMIZE;

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
	CMDIFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
	CMDIFrameWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::InitStatusBar()
{//定制状态栏的大小
	RECT rect;
	GetClientRect(&rect);
	CClientDC dc(this);
	TEXTMETRIC tm;
	short charwidth,width,MinSepWid;

	//得字符的平均宽度
	dc.GetTextMetrics(&tm);
	charwidth=(short)tm.tmAveCharWidth;
	
	//设置第0项的最小宽度
	MinSepWid=10*charwidth;

	width=(m_wndStatusBar.GetPaneText(4).GetLength())*charwidth;
	m_wndStatusBar.SetPaneInfo(4,ID_INDICATOR_NUM,SBPS_NORMAL,width);

	width=(m_wndStatusBar.GetPaneText(3).GetLength())*charwidth;
	m_wndStatusBar.SetPaneInfo(3,ID_INDICATOR_CAPS,SBPS_NORMAL,width);

	width=40*charwidth;
    m_wndStatusBar.SetPaneInfo(2,ID_INDICATOR_LAYERINFO,SBPS_NORMAL,width);

	width=40*charwidth;
    m_wndStatusBar.SetPaneInfo(1,ID_INDICATOR_MOUSEPOINT,SBPS_NORMAL,width);

	width=rect.right-(m_wndStatusBar.GetPaneText(4).GetLength())*charwidth;
	width=width-(m_wndStatusBar.GetPaneText(3).GetLength())*charwidth;
	width=width-40*charwidth;
	width=width-40*charwidth;
	width=width-10*4;

	if (width<MinSepWid)
		width=MinSepWid;
	m_wndStatusBar.SetPaneInfo(0,ID_SEPARATOR,SBPS_NORMAL,width);
}


void CMainFrame::OnSize(UINT nType, int cx, int cy) 
{
	CMDIFrameWnd::OnSize(nType, cx, cy);
	
	InitStatusBar();
	
}

//判断是否可关闭应用程序
void CMainFrame::OnClose() 
{
	POSITION DocPos;
	CWinApp *app = AfxGetApp();

	DocPos = app->GetFirstDocTemplatePosition( );
	while (DocPos != NULL)
	{
		CDocTemplate* pDocTemp = app->GetNextDocTemplate(DocPos);
		DocPos = pDocTemp->GetFirstDocPosition( );
		while(DocPos != NULL)
		{
	 		CDocument* pDoc = pDocTemp->GetNextDoc(DocPos);
			if(!pDoc->CanCloseFrame(this))
			{
				//按了"取消"
			     return;
			}
		}
	}

	CMDIFrameWnd::OnClose();
}

⌨️ 快捷键说明

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