📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "SlsPrj.h"
#include "MainFrm.h"
#include <stdlib.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)
ON_COMMAND_EX(CG_ID_VIEW_ENTITYDIALOGBAR, OnBarCheck)
ON_UPDATE_COMMAND_UI(CG_ID_VIEW_ENTITYDIALOGBAR, OnUpdateControlBarMenu)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
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():m_sizeMainFrame("主框架窗口尺寸"), m_profileRect("Rect"),
m_profileIcon("Icon"), m_profileMax("Maximized"),
m_profileTool("ToolBar"), m_profileStatus("StatusBar")
{
m_bFirstTime=TRUE;
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.Create(this) ||
!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
}
m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
// Initialize dialog bar m_wndEntityDialogBar if (!m_wndEntityDialogBar.Create(this, IDD_ENTITYDIALOGBAR, CBRS_BOTTOM | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_HIDE_INPLACE, CG_ID_VIEW_ENTITYDIALOGBAR)) { TRACE0("Failed to create dialog bar m_wndEntityDialogBar\n"); return -1; // fail to create } m_wndEntityDialogBar.SetWindowText("实体状态条");
m_wndEntityDialogBar.EnableDocking(CBRS_ALIGN_BOTTOM | CBRS_ALIGN_TOP); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndEntityDialogBar);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
return CMDIFrameWnd::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// 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::ActivateFrame(int nCmdShow)
{
CWnd* pBar;
CString text;
BOOL bIconic, bMaximized, bTool, bStatus;
UINT flags;
CRect rect;
WINDOWPLACEMENT wndPlacement;
if(m_bFirstTime)
{
m_bFirstTime=FALSE;
text=AfxGetApp()->GetProfileString(m_sizeMainFrame, m_profileRect);
if(!text.IsEmpty())
{
rect.left=atoi(LPCTSTR(text));
rect.top=atoi(LPCTSTR(text)+5);
rect.right=atoi(LPCTSTR(text)+10);
rect.bottom=atoi(LPCTSTR(text)+15);
}
else
{
rect = CFrameWnd::rectDefault;
}
bIconic=AfxGetApp()->GetProfileInt(m_sizeMainFrame,m_profileIcon,-1);
bMaximized=AfxGetApp()->GetProfileInt(m_sizeMainFrame,m_profileMax,-1);
if(bIconic)
{
nCmdShow=SW_SHOWMINNOACTIVE;
if(bMaximized)
flags=WPF_RESTORETOMAXIMIZED;
}
else
{
if(bMaximized)
{
nCmdShow=SW_SHOWMAXIMIZED;
flags=WPF_RESTORETOMAXIMIZED;
}
else
{
nCmdShow=SW_SHOWNORMAL;
flags=0;
}
}
wndPlacement.length=sizeof(WINDOWPLACEMENT);
wndPlacement.flags=flags;
wndPlacement.showCmd=nCmdShow;
wndPlacement.ptMinPosition=CPoint(0, 0);
wndPlacement.ptMaxPosition=CPoint(-::GetSystemMetrics(SM_CXBORDER),
-::GetSystemMetrics(SM_CYBORDER ));
wndPlacement. rcNormalPosition=rect;
bTool=AfxGetApp()->GetProfileInt(m_sizeMainFrame,m_profileTool,-1);
if(pBar = GetDescendantWindow(AFX_IDW_TOOLBAR))
pBar->ShowWindow(bTool);
bStatus=AfxGetApp()->GetProfileInt(m_sizeMainFrame,m_profileStatus,-1);
if(pBar = GetDescendantWindow(AFX_IDW_STATUS_BAR))
pBar->ShowWindow(bStatus);
//sets window's positoin and iconized/maximized status
SetWindowPlacement(&wndPlacement);
}
CMDIFrameWnd::ActivateFrame(nCmdShow);
}
BOOL CMainFrame::DestroyWindow()
{
CWnd* pBar;
CString text;
BOOL bIconic, bMaximized;
WINDOWPLACEMENT wndPlacement;
wndPlacement.length=sizeof(WINDOWPLACEMENT);
//gets current window's positoin and iconized/maximized status
GetWindowPlacement(&wndPlacement);
if(wndPlacement.showCmd == SW_SHOWNORMAL)
{
bIconic = FALSE;
bMaximized = FALSE;
}
else
if(wndPlacement.showCmd == SW_SHOWMAXIMIZED)
{
bIconic = FALSE;
bMaximized = TRUE;
}
else
if(wndPlacement.showCmd == SW_SHOWMINIMIZED)
{
bIconic = TRUE;
if(wndPlacement.flags)
bMaximized = TRUE;
else
bMaximized = FALSE;
}
sprintf(text.GetBuffer(20), "%4d %4d %4d %4d",
wndPlacement. rcNormalPosition.left,
wndPlacement. rcNormalPosition.top,
wndPlacement. rcNormalPosition.right,
wndPlacement. rcNormalPosition.bottom );
text.ReleaseBuffer();
AfxGetApp()->WriteProfileString(m_sizeMainFrame,m_profileRect,text);
AfxGetApp()->WriteProfileInt(m_sizeMainFrame,m_profileIcon,bIconic);
AfxGetApp()->WriteProfileInt(m_sizeMainFrame,m_profileMax,bMaximized);
if(pBar = GetDescendantWindow(AFX_IDW_TOOLBAR))
AfxGetApp()->WriteProfileInt(m_sizeMainFrame,m_profileTool,(pBar
->GetStyle() & WS_VISIBLE) != 0L);
if(pBar = GetDescendantWindow(AFX_IDW_STATUS_BAR))
AfxGetApp()->WriteProfileInt(m_sizeMainFrame,m_profileStatus,(pBar
->GetStyle() & WS_VISIBLE) != 0L);
return CMDIFrameWnd::DestroyWindow();
}
void CMainFrame::OnClose()
{
CString str;
str.Empty();
str += "注意:\n";
str += "i)关闭应用程序之前请先检查加工过程是否结束;\n";
str += "ii)若要人为终止当前加工过程请先使用“停止”按钮;\n";
str += "上述操作是否完成?\n";
int ret;
ret = AfxMessageBox(str, MB_YESNO | MB_ICONQUESTION);
if(ret != IDYES)
return;
CMDIFrameWnd::OnClose();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -