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)return; m_pScaleWeight = new CScale3DCChildFrame;//子框架 CCreateContext context; context.m_pNewViewClass = RUNTIME_CLASS(CScale3DCScaleWeightView); if (!m_pScaleWeight->LoadFrame(IDR_MAINFRAME, WS_OVERLAPPEDWINDOW | FWS_PREFIXTITLE, AfxGetMainWnd(), &context)) return; m_pScaleWeight->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); }
原文地址:http://blog.51cto.com/9233403/2085368