You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

586 lines
17 KiB
C++

// MainFrm.cpp : CMainFrame 类的实现
#include "stdafx.h"
#include "LaiPuLaser.h"
#include "MainFrm.h"
#include "GlobalDrawMgr.h"
#include "LogMgr.h"
#include "PltReader.h"
#include "GlobalFunction.h"
#include "MarkObjPropertieMgr.h"
#include "ModuleDeviceMgr.h"
#include "ModuleDrawMgr.h"
#include "DlgAuthorityLogin.h"
#include "AuthorityMgr.h"
#include "DlgMarkArea.h"
#include "MsgBox.h"
#include "TemplateMgr.h"
#include "WorkFileMgr.h"
#include "PropertieMgr.h"
#include "DlgAuthorityAccount.h"
#include "WorkTime.h"
#include "ProgramLaserTuiHuo.h"
#include "FileMgr.h"
#include "DlgDeviceMain.h"
#include "TekOscilloscopeMgr.h"
#define DLG_FACTORY_MODE_FILE _T("\\Factory_mode_0.bat") //用来控制是否为调试模式的文件
#define PAR_TempVal "PAR_TempVal"//发送温度值
#define PAR_TempErrMsg "PAR_TempErrMsg"//发送错误信息
#define MSG_CMD_OSC_DATA "OscillData->"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CMainFrame
IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWndEx)
const int iMaxUserToolbars = 10;
const UINT uiFirstUserToolBarId = AFX_IDW_CONTROLBAR_FIRST + 40;
const UINT uiLastUserToolBarId = uiFirstUserToolBarId + iMaxUserToolbars - 1;
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWndEx)
ON_WM_CREATE()
ON_WM_COPYDATA()//响应进程间消息
// 全局帮助命令
ON_COMMAND(ID_HELP_FINDER, &CMDIFrameWndEx::OnHelpFinder)
ON_COMMAND(ID_HELP, &CMDIFrameWndEx::OnHelp)
ON_COMMAND(ID_DEFAULT_HELP, &CMDIFrameWndEx::OnHelpFinder)
ON_COMMAND(ID_WINDOW_MANAGER, &CMainFrame::OnWindowManager)
ON_COMMAND(ID_VIEW_CUSTOMIZE, &CMainFrame::OnViewCustomize)
ON_REGISTERED_MESSAGE(AFX_WM_CREATETOOLBAR, &CMainFrame::OnToolbarCreateNew)
ON_COMMAND_RANGE(ID_VIEW_APPLOOK_WIN_2000, ID_VIEW_APPLOOK_WINDOWS_7, &CMainFrame::OnApplicationLook)
ON_UPDATE_COMMAND_UI_RANGE(ID_VIEW_APPLOOK_WIN_2000, ID_VIEW_APPLOOK_WINDOWS_7, &CMainFrame::OnUpdateApplicationLook)
ON_COMMAND(ID_VIEW_CAPTION_BAR, &CMainFrame::OnViewCaptionBar)
ON_UPDATE_COMMAND_UI(ID_VIEW_CAPTION_BAR, &CMainFrame::OnUpdateViewCaptionBar)
ON_COMMAND(ID_TOOLS_OPTIONS, &CMainFrame::OnOptions)
ON_WM_SETTINGCHANGE()
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // 状态行指示器
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
// CMainFrame 构造/析构
CMainFrame::CMainFrame()
{
theApp.m_nAppLook = theApp.GetInt(_T("ApplicationLook"), ID_VIEW_APPLOOK_VS_2008);
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWndEx::OnCreate(lpCreateStruct) == -1)
return -1;
BOOL bNameValid;
// 基于持久值设置视觉管理器和样式
OnApplicationLook(theApp.m_nAppLook);
CMDITabInfo mdiTabParams;
#if 0//不要选项卡式文档
mdiTabParams.m_style = CMFCTabCtrl::STYLE_3D_ONENOTE; // 其他可用样式...
mdiTabParams.m_bActiveTabCloseButton = TRUE; // 设置为 FALSE 会将关闭按钮放置在选项卡区域的右侧
mdiTabParams.m_bTabIcons = FALSE; // 设置为 TRUE 将在 MDI 选项卡上启用文档图标
mdiTabParams.m_bAutoColor = TRUE; // 设置为 FALSE 将禁用 MDI 选项卡的自动着色
mdiTabParams.m_bDocumentMenu = TRUE; // 在选项卡区域的右边缘启用文档菜单
EnableMDITabbedGroups(TRUE, mdiTabParams);
#endif
if (!m_wndMenuBar.Create(this))
{
TRACE0("未能创建菜单栏\n");
return -1; // 未能创建
}
m_wndMenuBar.SetPaneStyle(m_wndMenuBar.GetPaneStyle() | CBRS_SIZE_DYNAMIC | CBRS_TOOLTIPS | CBRS_FLYBY);
// 防止菜单栏在激活时获得焦点
CMFCPopupMenu::SetForceMenuFocus(FALSE);
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(theApp.m_bHiColorIcons ? IDR_MAINFRAME_256 : IDR_MAINFRAME))
{
TRACE0("未能创建工具栏\n");
return -1; // 未能创建
}
CString strToolBarName;
bNameValid = strToolBarName.LoadString(IDS_TOOLBAR_STANDARD);
ASSERT(bNameValid);
m_wndToolBar.SetWindowText(strToolBarName);
CString strCustomize;
bNameValid = strCustomize.LoadString(IDS_TOOLBAR_CUSTOMIZE);
ASSERT(bNameValid);
m_wndToolBar.EnableCustomizeButton(TRUE, ID_VIEW_CUSTOMIZE, strCustomize);
// 允许用户定义的工具栏操作:
InitUserToolbars(NULL, uiFirstUserToolBarId, uiLastUserToolBarId);
#if 0
if (!m_wndStatusBar.Create(this))
{
TRACE0("未能创建状态栏\n");
return -1; // 未能创建
}
m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT));
#endif
// TODO: 如果您不希望工具栏和菜单栏可停靠,请删除这五行
#if 1
// 启用 Visual Studio 2005 样式停靠窗口行为
CDockingManager::SetDockingMode(DT_SMART);
// 启用 Visual Studio 2005 样式停靠窗口自动隐藏行为
EnableAutoHidePanes(CBRS_ALIGN_ANY);
// 导航窗格将创建在左侧,因此将暂时禁用左侧的停靠:
EnableDocking(CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM | CBRS_ALIGN_RIGHT);
#endif
// 创建标题栏:
if (!CreateCaptionBar())
{
TRACE0("未能创建标题栏\n");
return -1; // 未能创建
}
// 已创建 Outlook 栏,应允许在左侧停靠。
EnableDocking(CBRS_ALIGN_LEFT);
EnableAutoHidePanes(CBRS_ALIGN_RIGHT);
// 创建停靠窗口
if (!CreateDockingWindows())
{
TRACE0("未能创建停靠窗口\n");
return -1;
}
EnableDocking(CBRS_ALIGN_ANY);
m_wndMenuBar.EnableDocking(CBRS_ALIGN_ANY);
DockPane(&m_wndMenuBar);
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
DockPane(&m_wndToolBar);
//m_OutputLog.EnableDocking(CBRS_ALIGN_ANY);
//DockPane(&m_OutputLog);
//m_pPromptInfo.EnableDocking(CBRS_ALIGN_ANY);
//DockPane(&m_pPromptInfo);
//m_GraphEditPane.EnableDocking(CBRS_ALIGN_TOP);
//DockPane(&m_GraphEditPane);
#if 0
m_DeviceMainPane.EnableDocking(CBRS_ALIGN_ANY);
DockPane(&m_DeviceMainPane);
#endif
// 启用增强的窗口管理对话框
EnableWindowsDialog(ID_WINDOW_MANAGER, ID_WINDOW_MANAGER, TRUE);
// 启用工具栏和停靠窗口菜单替换
EnablePaneMenu(TRUE, ID_VIEW_CUSTOMIZE, strCustomize, ID_VIEW_TOOLBAR);
// 启用快速(按住 Alt 拖动)工具栏自定义
CMFCToolBar::EnableQuickCustomization();
if (CMFCToolBar::GetUserImages() == NULL)
{
// 加载用户定义的工具栏图像
if (m_UserImages.Load(_T(".\\UserImages.bmp")))
{
CMFCToolBar::SetUserImages(&m_UserImages);
}
}
// 启用菜单个性化(最近使用的命令)
CList<UINT, UINT> lstBasicCommands;
lstBasicCommands.AddTail(ID_FILE_NEW);
lstBasicCommands.AddTail(ID_FILE_OPEN);
lstBasicCommands.AddTail(ID_FILE_SAVE);
lstBasicCommands.AddTail(ID_FILE_PRINT);
lstBasicCommands.AddTail(ID_APP_EXIT);
lstBasicCommands.AddTail(ID_EDIT_CUT);
lstBasicCommands.AddTail(ID_EDIT_PASTE);
lstBasicCommands.AddTail(ID_EDIT_UNDO);
lstBasicCommands.AddTail(ID_APP_ABOUT);
lstBasicCommands.AddTail(ID_VIEW_STATUS_BAR);
lstBasicCommands.AddTail(ID_VIEW_TOOLBAR);
lstBasicCommands.AddTail(ID_VIEW_APPLOOK_OFF_2003);
lstBasicCommands.AddTail(ID_VIEW_APPLOOK_VS_2005);
lstBasicCommands.AddTail(ID_VIEW_APPLOOK_OFF_2007_BLUE);
lstBasicCommands.AddTail(ID_VIEW_APPLOOK_OFF_2007_SILVER);
lstBasicCommands.AddTail(ID_VIEW_APPLOOK_OFF_2007_BLACK);
lstBasicCommands.AddTail(ID_VIEW_APPLOOK_OFF_2007_AQUA);
lstBasicCommands.AddTail(ID_VIEW_APPLOOK_WINDOWS_7);
CMFCToolBar::SetBasicCommands(lstBasicCommands);
// 将文档名和应用程序名称在窗口标题栏上的顺序进行交换。这
// 将改进任务栏的可用性,因为显示的文档名带有缩略图。
//ModifyStyle(0, FWS_PREFIXTITLE);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CMDIFrameWndEx::PreCreateWindow(cs) )
return FALSE;
// CREATESTRUCT cs 来修改窗口类或样式
return TRUE;
}
#if 1//可停靠控件
BOOL CMainFrame::CreateDockingWindows()
{
CFileMgr FileMgr;
CString FilePath;
FileMgr.GetFullFilePath(FilePath,DLG_FACTORY_MODE_FILE);//结果文件路径
if(FileMgr.IsFileExist(FilePath))
{
gbFactoryMode = true;
}
//日志窗口---------------------------------------------------------------
if (!m_OutputLog.Create(_T("Log"), this, CRect(0, 0, 100, 100), TRUE, ID_OUTPUT_LOG, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_BOTTOM | CBRS_FLOAT_MULTI))
{
return FALSE; // 未能创建
}
if (!m_pPromptInfo.Create(_T("Msg"), this, CRect(0, 0, 100, 100), TRUE, ID_OUTPUT_CMD, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_BOTTOM | CBRS_FLOAT_MULTI))
{
return FALSE; // 未能创建
}
{
m_GraphEditPane.SetDlg(&m_DlgGraphEdit);
if (!m_GraphEditPane.Create(_T("Info"), this, CRect(0, 0, 0, 0), TRUE, m_DlgGraphEdit.GetIDD(),
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI))
{
return FALSE;
}
m_GraphEditPane.EnableDocking(CBRS_ALIGN_ANY);
}
gDlgDeviceMain = new CDlgDeviceMain;
gDlgDeviceMain->Create(IDD_DEVICE_MAIN_DLG, this);
#if 0
{
m_DeviceMainPane.SetDlg(&m_DlgDeviceMain);
if (!m_DeviceMainPane.Create(_T("Laipu Laser"), this, CRect(0, 0, 3000, 2000), TRUE, m_DlgDeviceMain.GetIDD(),
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI))
{
return FALSE;
}
m_DeviceMainPane.EnableDocking(CBRS_ALIGN_ANY);
}
#endif
return TRUE;
}
#endif
BOOL CMainFrame::CreateCaptionBar()
{
#ifdef __CAPTION_BAR__
if (!m_wndCaptionBar.Create(WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, this, ID_VIEW_CAPTION_BAR, -1, TRUE))
{
TRACE0("未能创建标题栏\n");
return FALSE;
}
ResetCaptionBar();
#endif
return TRUE;
}
// CMainFrame 诊断
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CMDIFrameWndEx::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CMDIFrameWndEx::Dump(dc);
}
#endif //_DEBUG
// CMainFrame 消息处理程序
void CMainFrame::OnWindowManager()
{
ShowWindowsDialog();
}
void CMainFrame::OnViewCustomize()
{
CMFCToolBarsCustomizeDialog* pDlgCust = new CMFCToolBarsCustomizeDialog(this, TRUE /* 扫描菜单*/);
pDlgCust->EnableUserDefinedToolbars();
pDlgCust->Create();
}
LRESULT CMainFrame::OnToolbarCreateNew(WPARAM wp,LPARAM lp)
{
LRESULT lres = CMDIFrameWndEx::OnToolbarCreateNew(wp,lp);
if (lres == 0)
{
return 0;
}
CMFCToolBar* pUserToolbar = (CMFCToolBar*)lres;
ASSERT_VALID(pUserToolbar);
BOOL bNameValid;
CString strCustomize;
bNameValid = strCustomize.LoadString(IDS_TOOLBAR_CUSTOMIZE);
ASSERT(bNameValid);
pUserToolbar->EnableCustomizeButton(TRUE, ID_VIEW_CUSTOMIZE, strCustomize);
return lres;
}
void CMainFrame::OnApplicationLook(UINT id)
{
CWaitCursor wait;
theApp.m_nAppLook = id;
switch (theApp.m_nAppLook)
{
case ID_VIEW_APPLOOK_WIN_2000:
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManager));
break;
case ID_VIEW_APPLOOK_OFF_XP:
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOfficeXP));
break;
case ID_VIEW_APPLOOK_WIN_XP:
CMFCVisualManagerWindows::m_b3DTabsXPTheme = TRUE;
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
break;
case ID_VIEW_APPLOOK_OFF_2003:
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2003));
CDockingManager::SetDockingMode(DT_SMART);
break;
case ID_VIEW_APPLOOK_VS_2005:
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerVS2005));
CDockingManager::SetDockingMode(DT_SMART);
break;
case ID_VIEW_APPLOOK_VS_2008:
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerVS2008));
CDockingManager::SetDockingMode(DT_SMART);
break;
case ID_VIEW_APPLOOK_WINDOWS_7:
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows7));
CDockingManager::SetDockingMode(DT_SMART);
break;
default:
switch (theApp.m_nAppLook)
{
case ID_VIEW_APPLOOK_OFF_2007_BLUE:
CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_LunaBlue);
break;
case ID_VIEW_APPLOOK_OFF_2007_BLACK:
CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_ObsidianBlack);
break;
case ID_VIEW_APPLOOK_OFF_2007_SILVER:
CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_Silver);
break;
case ID_VIEW_APPLOOK_OFF_2007_AQUA:
CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_Aqua);
break;
}
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2007));
CDockingManager::SetDockingMode(DT_SMART);
}
RedrawWindow(NULL, NULL, RDW_ALLCHILDREN | RDW_INVALIDATE | RDW_UPDATENOW | RDW_FRAME | RDW_ERASE);
theApp.WriteInt(_T("ApplicationLook"), theApp.m_nAppLook);
}
void CMainFrame::OnUpdateApplicationLook(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(theApp.m_nAppLook == pCmdUI->m_nID);
}
void CMainFrame::OnViewCaptionBar()
{
#ifdef __CAPTION_BAR__
m_wndCaptionBar.ShowWindow(m_wndCaptionBar.IsVisible() ? SW_HIDE : SW_SHOW);
RecalcLayout(FALSE);
#endif
}
void CMainFrame::OnUpdateViewCaptionBar(CCmdUI* pCmdUI)
{
#ifdef __CAPTION_BAR__
pCmdUI->SetCheck(m_wndCaptionBar.IsVisible());
#endif
}
void CMainFrame::OnOptions()
{
}
BOOL CMainFrame::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle, CWnd* pParentWnd, CCreateContext* pContext)
{
// 基类将执行真正的工作
if (!CMDIFrameWndEx::LoadFrame(nIDResource, dwDefaultStyle, pParentWnd, pContext))
{
return FALSE;
}
// 为所有用户工具栏启用自定义按钮
BOOL bNameValid;
CString strCustomize;
bNameValid = strCustomize.LoadString(IDS_TOOLBAR_CUSTOMIZE);
ASSERT(bNameValid);
for (int i = 0; i < iMaxUserToolbars; i ++)
{
CMFCToolBar* pUserToolbar = GetUserToolBarByIndex(i);
if (pUserToolbar != NULL)
{
pUserToolbar->EnableCustomizeButton(TRUE, ID_VIEW_CUSTOMIZE, strCustomize);
}
}
return TRUE;
}
void CMainFrame::OnSettingChange(UINT uFlags, LPCTSTR lpszSection)
{
CMDIFrameWndEx::OnSettingChange(uFlags, lpszSection);
}
//处理退出程序的消息
LRESULT CMainFrame::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
//如果是系统消息
case WM_SYSCOMMAND:
{
if(wParam==SC_CLOSE)
{
CMsgBox MsgBox;
if(gProgramLaserTuiHuo->CloseAppCheck()==false)
return 0;
}
break;
}
}
return CMDIFrameWndEx::WindowProc(message, wParam, lParam);
}
#if 1
//显示鼠标位置坐标
void CMainFrame::ShowMouseCoord(CPoint point)
{
#if 0
Dbxy pt = gDraw->CPoint2Dbxy(point);
CString MouseX,MouseY;
MouseX.Format("%lf",pt.x);
MouseY.Format("%lf",pt.y);
CString str = "当前坐标(单位mm ):x = ["+MouseX+"]"+" y = ["+MouseY+"]";
str += " "+m_StatusBarExtStr;
m_wndStatusBar.SetPaneText(0,(LPCTSTR)str,TRUE);
#endif
}
//显示view 当前的缩放比例
void CMainFrame::ShowViewScale(double s)
{
#if 0
CString Str;
Str.Format("%lf",s);
m_wndStatusBar.SetPaneText(0,(LPCTSTR)Str,TRUE);
#endif
}
void CMainFrame::SetCaptionCmdStr(CString str)
{
m_CaptionCmdStr = str+STR_INPUT_SYMBOL;
}
void CMainFrame::SetCaptionInputStr(CString str)
{
m_CaptionInputStr = str;
}
void CMainFrame::RefreashCaptionBar()
{
}
void CMainFrame::ResetCaptionBar()
{
m_CaptionCmdStr = "";
m_CaptionInputStr = "";
RefreashCaptionBar();
ResetStatusBarExtStr();
}
void CMainFrame::ResetStatusBarExtStr()
{
m_StatusBarExtStr = "";
}
void CMainFrame::SetStatusBarExtStr(CString str,CString val1,CString val2)
{
if(val1 != STR_NULL || val2 != STR_NULL)
{
str += " : ";
}
if(val1 != STR_NULL)
{
val1 = "<"+val1+">";
}
if(val2 != STR_NULL)
{
val2 = "<"+val2+">";
}
m_StatusBarExtStr = str+val1+val2;
}
//撤销对话框绑定的obj 参数
void CMainFrame::UnBindingDlg()
{
}
//窗口最大化
void CMainFrame::ShowWindowMax()
{
ShowWindow(SW_SHOWMAXIMIZED);
}
//窗口最小化
void CMainFrame::ShowWindowMin()
{
ShowWindow(SW_SHOWMINIMIZED);
}
//收到进程间消息
BOOL CMainFrame::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct)
{
CString strRecievedText = (LPCSTR)(pCopyDataStruct->lpData);
if(gbAppInitComplete)
{
}
return CMDIFrameWndEx::OnCopyData(pWnd, pCopyDataStruct);
}
#endif