MFC多文档应用程序常用知识点-创新互联
1、修改左上角圆形按图标。可以将要显示的图标放在资源中加载,也可以将图标文件放在程序目录下加载。
成都创新互联公司长期为数千家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为图木舒克企业提供专业的成都网站制作、成都做网站,图木舒克网站改版等技术服务。拥有十多年丰富建站经验和众多成功案例,为您定制开发。CRect rt1; m_wndRibbonBar.GetClientRect(&rt1); CMFCRibbonApplicationButton * pAppButton = m_wndRibbonBar.GetApplicationButton(); HBITMAP hBitmap = (HBITMAP)::LoadImage(NULL, CScale3DCGlobal::GetAppllicationPath()+ _T("\\user\\admin.bmp"), IMAGE_BITMAP, 0, 0, //原始大小 LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_LOADFROMFILE); pAppButton->SetImage(hBitmap);
以上代码放在MainFrame.cpp的OnCreate中执行。
2、在Ribbon中加载自己的控件
CRect rt(10, rt1.bottom+3, 460, rt1.bottom + 3+107); m_LedString.Create(_T("000000"), 0, rt, &m_wndRibbonBar, IDC_LED1); m_LedString.SetStringPost(25, 21); m_LedString.SetStringAmp(0.3); m_LedString.SetTip(_T("COM4:9600 XK3190A9 COM2:YH-5大屏幕")); m_LedString.SetUnit(_T("公斤"));
3、在一个按钮点击事件中创建新的视图
if (m_bIsScaleWeightView) { m_pScaleWeightChildFrame->ActivateFrame();//激活已存在的视图 m_pScaleWeightChildFrame->SetFocus(); return; } m_pScaleWeightChildFrame = new CScale3DCChildFrame; CCreateContext context; context.m_pNewViewClass = RUNTIME_CLASS(CScale3DCScaleWeightView); if (!m_pScaleWeightChildFrame->LoadFrame(IDR_MAINFRAME, WS_OVERLAPPEDWINDOW | FWS_PREFIXTITLE, AfxGetMainWnd(), &context)) return; m_pScaleWeightChildFrame->InitialUpdateFrame(NULL, TRUE); m_bIsScaleWeightView = TRUE;//防止重复创建视图
4、通过工具栏隐藏和显示面板
BOOL CScale3DCMainFrame::OnCloseDockingPane(CDockablePane* pWnd)//虚函数 { // TODO: 在此添加专用代码和/或调用基类 m_bVideoShow = TRUE; m_bDataGridShow = TRUE; return CMDIFrameWndEx::OnCloseDockingPane(pWnd); } //虚函数 BOOL CScale3DCMainFrame::OnCloseMiniFrame(CPaneFrameWnd* pWnd) { // TODO: 在此添加专用代码和/或调用基类 CWnd* pwnd = pWnd->GetPane(); if (pwnd->IsKindOf(RUNTIME_CLASS(CTabbedPane)))//多个窗口 { CTabbedPane* tabpane = (CTabbedPane *)pwnd; CMFCBaseTabCtrl* pTabWnd = tabpane->GetUnderlyingWindow(); //关闭所有的面板 for (int i = 0; i < pTabWnd->GetTabsNum(); i++) { CDockablePane* pBar = DYNAMIC_DOWNCAST(CDockablePane, pTabWnd->GetTabWnd(i)); if (pBar != NULL) { ASSERT_VALID(pBar); //将关闭消息加入该DockPane队列,等待完成本函数后关闭 ::PostMessageA(pBar->m_hWnd, WM_CLOSE, 0, 0); } } } else { //单个窗口 CDockablePane* pane = (CDockablePane *)pwnd; if (pane->IsKindOf(RUNTIME_CLASS(CDockablePane)) || pane->IsKindOf(RUNTIME_CLASS(CPane)) && pane->IsKindOf(RUNTIME_CLASS(CPaneFrameWnd))) { //将关闭消息加入该DockPane队列,等待完成本函数后关闭 ::PostMessageA(pWnd->GetPane()->m_hWnd, WM_CLOSE, 0, 0); } } m_bVideoShow = TRUE; m_bDataGridShow = TRUE; return TRUE; //return CMDIFrameWndEx::OnCloseMiniFrame(pWnd); } void CScale3DCMainFrame::OnButtonVideo() { if (!m_bVideoShow) { m_bVideoShow = TRUE; m_wndVideoPanel.ShowPane(FALSE, FALSE, FALSE); } else if (m_wndVideoPanel.GetSafeHwnd()) { m_bVideoShow = FALSE; m_wndVideoPanel.ShowPane(TRUE, FALSE, TRUE); } else { BOOL bNameValid; CString strPropertiesWnd; bNameValid = strPropertiesWnd.LoadString(IDS_PROPERTIES_WND); ASSERT(bNameValid); if (!m_wndVideoPanel.Create(strPropertiesWnd, this, CRect(0, 0, 200, 200), TRUE, ID_VIEW_PROPERTIESWND, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_RIGHT | CBRS_FLOAT_MULTI)) { TRACE("未能创建%s窗口\n", strPropertiesWnd); return; } m_wndVideoPanel.EnableDocking(CBRS_ALIGN_ANY); DockPane(&m_wndVideoPanel); m_bVideoShow = FALSE; } RecalcLayout(); } void CScale3DCMainFrame::OnButtonDatagrid() { // TODO: 在此添加命令处理程序代码 if (!m_bDataGridShow) { m_bDataGridShow = TRUE; m_wndDataGridPanel.ShowPane(FALSE, FALSE, FALSE); } else if (m_wndDataGridPanel.GetSafeHwnd()) { m_bDataGridShow = FALSE; m_wndDataGridPanel.ShowPane(TRUE, FALSE, TRUE); } else { BOOL bNameValid; CString strPropertiesWnd; bNameValid = strPropertiesWnd.LoadString(IDS_OUTPUT_WND); ASSERT(bNameValid); if (!m_wndDataGridPanel.Create(strPropertiesWnd, this, CRect(0, 0, 200, 200), TRUE, ID_VIEW_PROPERTIESWND, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_RIGHT | CBRS_FLOAT_MULTI)) { TRACE("未能创建%s窗口\n", strPropertiesWnd); return; } m_wndDataGridPanel.EnableDocking(CBRS_ALIGN_ANY); DockPane(&m_wndDataGridPanel); m_bDataGridShow = FALSE; } RecalcLayout(); }
5、设置视图的标签标题文字
BOOL CScale3DCChildFrame::PreCreateWindow(CREATESTRUCT& cs) { // TODO: 在此处通过修改 CREATESTRUCT cs 来修改窗口类或样式 cs.style &= ~(LONG)FWS_ADDTOTITLE; if( !CMDIChildWndEx::PreCreateWindow(cs) ) return FALSE; return TRUE; }
void CScale3DCScaleWeightView::OnInitialUpdate() { CFormView::OnInitialUpdate(); CMDIChildWndEx * pFrame = (CMDIChildWndEx*)this->GetParentFrame(); CScale3DCChildFrame * pMidFrame = (CScale3DCChildFrame*)pFrame; pMidFrame->SetWindowText(_T("称重数据区")); // TODO: 在此添加专用代码和/或调用基类 }
6、改变视图的背景颜色
BOOL CScale3DCScaleWeightView::OnEraseBkgnd(CDC* pDC) { // TODO: 在此添加消息处理程序代码和/或调用默认值 CRect rt; GetClientRect(&rt); CBrush brush; brush.CreateSolidBrush(RGB(255, 255, 255)); CBrush * pOldBrush = pDC->SelectObject(&brush); pDC->FillRect(&rt, &brush); pDC->SelectObject(pOldBrush); return TRUE; //return CFormView::OnEraseBkgnd(pDC); }
7、在一个视图中创建另一个视图
CScale3DCMainFrame * pMainFrame = (CScale3DCMainFrame*)AfxGetMainWnd(); CScale3DCMainControlPanel2 * pPanel = &pMainFrame->m_wndMainControlPanel; pPanel->m_wndMainToolbarDlg->CreateScaleWeightView();
8、遍历主框架中的子框架
void CScale3DCMainFrame::SearchAllMDIFrame() { CMDIFrameWnd *pFrame = (CMDIFrameWnd*)::AfxGetMainWnd(); if (pFrame) { CMDIChildWnd *pOldChildFrame = pFrame->MDIGetActive(); CMDIChildWnd *pChildFrame = pOldChildFrame; if (pChildFrame) { do { CString strCaption; pChildFrame->GetWindowText(strCaption); if (_T("主控界面区") == strCaption) { CView * pView= pChildFrame->GetActiveView(); //消息发向主控视图 pView->SendMessage(WM_STARTSCALEWEIGHTVIEW, 0, 0); return; } pFrame->MDINext(); pChildFrame = pFrame->MDIGetActive(); } while (pChildFrame != pOldChildFrame); } } }
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
网站栏目:MFC多文档应用程序常用知识点-创新互联
文章地址:http://hbruida.cn/article/cecigi.html