📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "MyPaint.h"
#include "MainFrm.h"
#include "MyPaintDoc.h"
#include "MyPaintView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
CMainFrame* mainwnd=0; //定义全局主窗口指针变量
BOOL flag_setdlg=0;
extern CMyPaintView* dcpoint;
BOOL flag_xy=0,flag_z=0,flag_FOV=0;
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_COMMAND(AFX_ID_PAINT, OnIdPaint)
ON_WM_CLOSE()
ON_COMMAND(ID_XY_ROTE, OnXyRote)
ON_COMMAND(ID_Z_ROTE, OnZRote)
ON_COMMAND(ID_ZOOM, OnZoom)
ON_COMMAND(ID_MOUSE, OnMouse)
ON_COMMAND(ID_SAVE_BMP, OnSaveBmp)
ON_COMMAND(ID_MY_SAVE, OnMySave)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
ON_COMMAND(ID_SET, OnSet)
ON_COMMAND(ID_ABOUT_ME, OnAboutMe)
ON_COMMAND(ID_MY_OPEN, OnMyOpen)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_X,
ID_Y,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
extern BYTE focus,fov;
extern BOOL flag_focus;
extern COLORREF color_net,color_cordn,color_bk,color_text;
mainwnd=this;
CFile fp;
if(fp.Open("set.ini",CFile::modeRead)!=NULL)
{
fp.Read(&color_bk,sizeof(COLORREF));
fp.Read(&color_net,sizeof(COLORREF));
fp.Read(&color_cordn,sizeof(COLORREF));
fp.Read(&color_text,sizeof(COLORREF));
fp.Read(&flag_focus,sizeof(BOOL));
fp.Read(&focus,sizeof(BYTE));
fp.Read(&fov,sizeof(BYTE));
fp.Close();
}
else
{
fov=40;
focus=20;
}
}
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_TOOLBAR))
{
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
}
m_wndStatusBar.SetPaneInfo(1,ID_X,NULL,60);
m_wndStatusBar.SetPaneInfo(2,ID_Y,NULL,60);
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.cx =GetSystemMetrics(SM_CXSCREEN);
cs.cy=GetSystemMetrics(SM_CYSCREEN);
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::OnIdPaint()
{
if(dcpoint->paint.ShowWindow(SW_HIDE)) //判断绘图控制框是否可见,如果可见则隐藏,否则就显示
; //ShowWindow()返回的是窗口的previous状态
else
dcpoint->paint.ShowWindow(SW_SHOW);
}
void CMainFrame::OnClose()
{
// TODO: Add your message handler code here and/or call default
if(MessageBox("确定要退出吗?","退出?",MB_OKCANCEL|MB_ICONQUESTION)==IDOK)
CMainFrame::DestroyWindow();
}
void CMainFrame::OnAppAbout()
{
if( (short)ShellExecute(NULL,"open","help.chm",NULL,NULL,SW_SHOWNORMAL)<=32 )
MessageBox("找不到帮助文件,或者打开文件出错!","错误",MB_OK);
}
void CMainFrame::OnXyRote()
{
flag_z=0;
flag_FOV=0;
flag_xy=1;
}
void CMainFrame::OnZRote()
{
flag_z=1;
flag_FOV=0;
flag_xy=0;
}
void CMainFrame::OnZoom()
{
flag_FOV=1;
flag_z=0;
flag_xy=0;
}
void CMainFrame::OnMouse()
{
flag_FOV=0;
flag_z=0;
flag_xy=0;
}
void CMainFrame::OnSet()
{
if(!flag_setdlg)
{
setdlg.Create(IDD_DIALOG2,this);
flag_setdlg=1;
}
setdlg.ShowWindow(SW_SHOW);
}
void CMainFrame::OnAboutMe()
{
aboutme.DoModal();
}
void CMainFrame::OnSaveBmp()
{
dcpoint->OnSaveBmp();
}
void CMainFrame::OnMySave()
{
extern MY_LINE *head;
MY_LINE *p_line=head;
if(p_line==NULL)
{
MessageBox("现场为空,无须保存","提示",MB_OK);
return;
}
CFileDialog dlg(false,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
"数据文件(*.mp)|*.mp|",NULL);
if (dlg.DoModal()!= IDOK)
return;
char filename[128];
strncpy(filename,(LPCTSTR)(dlg.GetFileTitle()+".mp"),128);
FILE* fp;
if( (fp=fopen(filename,"wb"))==NULL)
{
MessageBox("错误","文件保存失败!",MB_OK);
return;
}
for(;p_line!=NULL;p_line=p_line->next)
fwrite(p_line,sizeof(MY_LINE),1,fp);
fclose(fp);
}
void CMainFrame::OnMyOpen()
{
extern MY_LINE *head,*p1,*p2;
extern BYTE line_count;
extern CMyPaintView* dcpoint;
if(MessageBox("打开文件会导致现有场景信息丢失,您确定继续吗?","警告",MB_YESNO)==IDNO)
return;
MY_LINE *del_line=NULL,*p_line=NULL;
del_line=p_line=head;/////////////删除现场
while(p_line!=NULL)
{
del_line=p_line;
p_line=p_line->next;
delete del_line;
}
line_count=0;
head=NULL;
CFileDialog dlg(true,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
"数据文件(*.mp)|*.mp|",NULL);
if (dlg.DoModal()!= IDOK)
return;
char filename[128];
strncpy(filename,(LPCTSTR)dlg.GetFileName(),128);
FILE* fp;
if( (fp=fopen(filename,"rb"))==NULL)
{
MessageBox("错误","文件打开失败!",MB_OK);
return;
}
head=(MY_LINE *)new MY_LINE;
fread(head,sizeof(MY_LINE),1,fp);
p2=head;
line_count++;
while(p2->next!=NULL)
{
p1=(MY_LINE *)new MY_LINE;
p2->next=p1;
fread(p1,sizeof(MY_LINE),1,fp);
p2=p1;
line_count++;
}
dcpoint->Invalidate(TRUE);
fclose(fp);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -