📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "ZCR14Paint.h"
#include "ColorPane.h"
//#include "OptionZone.h"
#include "ZCR14PaintDoc.h"
#include "MainFrm.h"
#include "MyImage.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_FILE_OPEN, OnFileOpen)
ON_COMMAND(ID_FILE_NEW, OnFileNew)
ON_WM_CLOSE()
//}}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
a=0;
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
//////////////与ColorPane有关的代码////////
if (!m_wndColorPane.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_BOTTOM
| CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_FIXED) ||
!m_wndColorPane.LoadToolBar(IDR_COLORPANE))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
m_wndColorPane.SetWindowText("颜色");
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndColorPane.EnableDocking(CBRS_ALIGN_BOTTOM);
EnableDocking(CBRS_ALIGN_BOTTOM);
DockControlBar(&m_wndColorPane);
///////////////////////////////////////////////
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_LEFT
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_FIXED) ||
!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
}
// 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_wndToolBar.SetWindowText(_T("工具"));
HICON hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
SetIcon(hIcon, TRUE); // Set big icon
SetIcon(hIcon, FALSE); // Set small icon
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
int CMainFrame::GetPenWith()
{
return m_wndToolBar.GetPenWidth();
}
int CMainFrame::GetRectType()
{
return m_wndToolBar.GetRectType();
}
void CMainFrame::OnFileOpen()
{
// TODO: Add your command handler code here
char BASED_CODE szFilter[] =
"工程文件 (*.shp)|*.shp||";
CFileDialog dlgFileOpen ( TRUE, "SHP", "*.shp",
OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, szFilter, this );
if (dlgFileOpen.DoModal()!=IDOK)
return;
if(a==0)
{
strPathName = dlgFileOpen.GetPathName();
// 5. 按串行化打开文件
VERIFY( GetActiveDocument()
->OnOpenDocument(strPathName));
// 6. 打开文件之后的系统初始化
Invalidate();
a++;
}
else
{
VERIFY( GetActiveDocument()
->OnOpenDocument(strPathName));
strPathName = dlgFileOpen.GetPathName();
// 5. 按串行化打开文件
VERIFY( GetActiveDocument()
->OnOpenDocument(strPathName));
// 6. 打开文件之后的系统初始化
Invalidate();
}
}
void CMainFrame::OnFileNew()
{
// TODO: Add your command handler code here
CZCR14PaintDoc * pDoc = (CZCR14PaintDoc *)GetActiveDocument();
//如果m_emState为 STATE_MODIFIED则需要提醒当前画图内容是否需要保存。
if(pDoc ->GetState()==1)
{
int nResponse = AfxMessageBox("保存文件吗?",MB_YESNOCANCEL);
if ( nResponse == IDCANCEL )
return;
else if ( nResponse == IDYES )
// 保存原有文件
pDoc->OnFileSave();
}
// 创建新的工程
pDoc ->SetTitle("无标题");
pDoc->DeleteContents();
pDoc ->UpdateAllViews(NULL);
}
void CMainFrame::OnClose()
{
// TODO: Add your message handler code here and/or call default
CZCR14PaintDoc* pDoc;
pDoc=(CZCR14PaintDoc*)((CFrameWnd*)AfxGetApp()->m_pMainWnd)->GetActiveDocument();
{ int nResponse =
AfxMessageBox("退出工程吗?",MB_YESNOCANCEL);
if ( nResponse == IDCANCEL )
return;
else if ( nResponse == IDYES )
GetActiveDocument()->OnCmdMsg(ID_FILE_SAVE,0,NULL,NULL);
}
pDoc->DeleteContents();
CFrameWnd::OnClose();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -