// MainFrm.cpp: CMainFrame 类的实现 // #include "pch.h" #include "framework.h" #include "MTerm2.h" #include "MainFrm.h" #include "ChildFrm.h" #include "MTerm2Doc.h" #include "MTerm2View.h" #include "MTerm2CtrlView.h" #include "MTerm2TestView.h" #include "MTerm2ProgTxt.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // CMainFrame IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWndEx) BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWndEx) ON_WM_CREATE() ON_COMMAND(ID_UPLOAD_FROM_PLC, &CMainFrame::OnUploadFromPlc) ON_COMMAND(ID_VIEW_FUNCKEY_BAR, &CMainFrame::OnViewFunckeyBar) ON_UPDATE_COMMAND_UI(ID_VIEW_FUNCKEY_BAR, &CMainFrame::OnUpdateViewFunckeyBar) ON_COMMAND(ID_VIEW_INPUT_BAR, &CMainFrame::OnViewInputBar) ON_UPDATE_COMMAND_UI(ID_VIEW_INPUT_BAR, &CMainFrame::OnUpdateViewInputBar) ON_COMMAND(ID_VIEW_NUMKEY_BAR, &CMainFrame::OnViewNumkeyBar) ON_UPDATE_COMMAND_UI(ID_VIEW_NUMKEY_BAR, &CMainFrame::OnUpdateViewNumkeyBar) ON_COMMAND(ID_VIEW_INPUTSEG_BAR, &CMainFrame::OnViewInputsegBar) ON_UPDATE_COMMAND_UI(ID_VIEW_INPUTSEG_BAR, &CMainFrame::OnUpdateViewInputsegBar) ON_COMMAND(ID_VIEW_COMMENTS_BAR, &CMainFrame::OnViewCommentsBar) ON_UPDATE_COMMAND_UI(ID_VIEW_COMMENTS_BAR, &CMainFrame::OnUpdateViewCommentsBar) // ON_COMMAND(ID_MENU_VIEW_LDS, &CMainFrame::OnMenuViewLds) // ON_COMMAND(ID_MENU_VIEW_BLD, &CMainFrame::OnMenuViewBld) // ON_COMMAND(ID_MENU_VIEW_BNL, &CMainFrame::OnMenuViewBnl) ON_COMMAND(ID_MENU_SHOW_LOG, &CMainFrame::OnMenuShowLog) END_MESSAGE_MAP() static UINT indicators[] = { ID_SEPARATOR, // 状态行指示器 ID_INDICATOR_SEL_TYPE, ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL, }; // CMainFrame 构造/析构 CMainFrame::CMainFrame() noexcept { // TODO: 在此添加成员初始化代码 } CMainFrame::~CMainFrame() { } int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CMDIFrameWndEx::OnCreate(lpCreateStruct) == -1) return -1; // m_dlgMyLog.Create(m_dlgMyLog.IDD, GetParent()); // m_dlgMyLog.ShowWindow(SW_SHOW); 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("未能创建工具栏\n"); return -1; // 未能创建 } ///* 输入栏 if (!m_wndToolBar_InputShow.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_BOTTOM | CBRS_FLOAT_MULTI | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC, CRect(1, 1, 1, 1), IDW_TOOL_BAR2) || !m_wndToolBar_InputShow.LoadToolBar(IDR_TOOLBAR_INPUT_SHOW)) { TRACE0("未能创建数字工具栏\n"); return -1; // 未能创建 } //*/ CRect rect1; int index = m_wndToolBar_InputShow.CommandToIndex(ID_BUTTON_INPUT_SHOW); UINT nID,nStyle; int iImage; m_wndToolBar_InputShow.GetButtonInfo(0, nID, nStyle, iImage); m_wndToolBar_InputShow.SetButtonInfo(index, ID_BUTTON_INPUT_SHOW, TBBS_SEPARATOR, 100); m_wndToolBar_InputShow.GetItemRect(index, &rect1); rect1.left = 1; rect1.top = 2; rect1.right = rect1.left + 100; rect1.bottom = rect1.top + 20; /* if (!m_InputShowEdit.Create(WS_CHILD | WS_VISIBLE | WS_BORDER, rect1, \ &m_wndToolBar_InputShow, ID_BUTTON_INPUT_SHOW)) { TRACE(_T("Failed to create CEdit\n")); return FALSE; } //*/ if (!m_InputShowStatic.Create(_T("Test1"),WS_CHILD | WS_VISIBLE |WS_EX_CLIENTEDGE, rect1, \ &m_wndToolBar_InputShow, ID_BUTTON_INPUT_SHOW)) { TRACE(_T("Failed to create CStaticEx\n")); return FALSE; } m_InputShowStatic.SetBkColor(RGB(255, 255, 255)); m_InputShowStatic.SetTextColor(RGB(255, 128, 128)); m_InputShowStatic.SetTextSize(20); //m_InputShowEdit.SetReadOnly(true); ///* if (!m_wndToolBar_Num.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_BOTTOM | CBRS_FLOAT_MULTI | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC, CRect(1,1,1,1),IDW_TOOL_BAR2) || !m_wndToolBar_Num.LoadToolBar(IDR_TOOLBAR_NUM)) { TRACE0("未能创建数字工具栏\n"); return -1; // 未能创建 } //*/ ///* if (!m_wndToolBar_Edit.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_BOTTOM | CBRS_FLOAT_MULTI | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC, CRect(1, 1, 1, 1), IDW_TOOL_BAR_EDIT) || !m_wndToolBar_Edit.LoadToolBar(IDR_TOOLBAR_EDIT)) { TRACE0("未能创建数字工具栏\n"); return -1; // 未能创建 } //*/ if (!m_wndStatusBar.Create(this)) { TRACE0("未能创建状态栏\n"); return -1; // 未能创建 } m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT)); m_wndStatusBar.SetPaneStyle(0, SBPS_STRETCH); // /* if (!m_wndMyPaneLog.Create(_T("日志窗口"), this, CRect(0, 0, 200, 200), TRUE, 1235, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_RIGHT | CBRS_FLOAT_MULTI)) { TRACE0("未能创建“MyPaneLog窗口\n"); return FALSE; } //*/ // TODO: 如果不需要可停靠工具栏,则删除这三行 m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); EnableDocking(CBRS_ALIGN_ANY); DockPane(&m_wndToolBar); m_wndMyPaneLog.EnableDocking(CBRS_ALIGN_ANY); // EnableDocking(CBRS_ALIGN_ANY); ///* m_wndToolBar_InputShow.EnableDocking(CBRS_ALIGN_ANY); m_wndToolBar_Num.EnableDocking(CBRS_ALIGN_ANY); m_wndToolBar_Edit.EnableDocking(CBRS_ALIGN_ANY); EnableDocking(CBRS_ALIGN_ANY); // DockPane(&m_wndToolBar); DockPane(&m_wndToolBar_InputShow); DockPane(&m_wndToolBar_Num); DockPane(&m_wndToolBar_Edit); DockPane(&m_wndMyPaneLog); //*/ return 0; } BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { if( !CMDIFrameWndEx::PreCreateWindow(cs) ) return FALSE; // TODO: 在此处通过修改 // CREATESTRUCT cs 来修改窗口类或样式 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::OnUploadFromPlc() { // TODO: 在此添加命令处理程序代码 CWinAppEx* pApp = &theApp; POSITION curTemplatePos = pApp->GetFirstDocTemplatePosition(); if (curTemplatePos != NULL) { CDocTemplate* curTemplate = pApp->GetNextDocTemplate(curTemplatePos); curTemplate->OpenDocumentFile(NULL); //CView* thisView = GetActiveView(); CMTerm2Doc* pDoc = (CMTerm2Doc*)GetActiveDocument(); // pDoc->OnNewDocument(); pDoc->OnUploadFromPlc(); } //SysLog(_T("From mainframe")); } void CMainFrame::OnMenuShowLog() { // TODO: 在此添加命令处理程序代码 m_wndMyPaneLog.ShowWindow(SW_SHOW); } void CMainFrame::OnViewFunckeyBar() { // TODO: 在此添加命令处理程序代码 } void CMainFrame::OnUpdateViewFunckeyBar(CCmdUI *pCmdUI) { // TODO: 在此添加命令更新用户界面处理程序代码 } void CMainFrame::OnViewInputBar() { // TODO: 在此添加命令处理程序代码 } void CMainFrame::OnUpdateViewInputBar(CCmdUI *pCmdUI) { // TODO: 在此添加命令更新用户界面处理程序代码 } void CMainFrame::OnViewNumkeyBar() { // TODO: 在此添加命令处理程序代码 } void CMainFrame::OnUpdateViewNumkeyBar(CCmdUI *pCmdUI) { // TODO: 在此添加命令更新用户界面处理程序代码 } void CMainFrame::OnViewInputsegBar() { // TODO: 在此添加命令处理程序代码 } void CMainFrame::OnUpdateViewInputsegBar(CCmdUI *pCmdUI) { // TODO: 在此添加命令更新用户界面处理程序代码 } void CMainFrame::OnViewCommentsBar() { // TODO: 在此添加命令处理程序代码 } void CMainFrame::OnUpdateViewCommentsBar(CCmdUI *pCmdUI) { // TODO: 在此添加命令更新用户界面处理程序代码 } /* CView * FindView(CDocument * pDoc, CRuntimeClass * pClass) { CView* pView = NULL; POSITION pos = pDoc->GetFirstViewPosition(); while (pos != NULL) { pView = pDoc->GetNextView(pos); if (pView->IsKindOf(pClass)) break; } if (!pView->IsKindOf(pClass)) { //AfxMessageBox("Connt Locate the View."); return NULL; } return pView; } */