Common knowledge points for MFC multi-document applications

Source: Internet
Author: User
Tags assert

1, modify the upper left corner of the circle by icon. You can load the icon you want to display in the resource, or you can put the icon file in the program directory.

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,//original size Lr_defaultcolor | lr_createdibsection | Lr_loadfromfile);p appbutton->setimage (HBITMAP);

The above code is executed in the MainFrame.cpp OnCreate.
2. Load your own controls in the Ribbon

CRect RT (Ten, Rt1.bottom+3, 460, Rt1.bottom + 3+107); M_ledstring.create (_t ("000000"), 0, RT, &m_wndribbonbar, IDC_ LED1); M_ledstring.setstringpost (+), M_ledstring.setstringamp (0.3); M_ledstring.settip (_t ("com4:9600 XK3190A9 Com2:yh-5 Large Screen ")); M_ledstring.setunit (_t (" kg "));

3. Create a new view in a button

if (m_bisscaleweightview) return;m_pscaleweight = new cscale3dcchildframe;//child frame 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);//virtual function m_ Bisscaleweightview = true;//Custom Create tag

4. Hide and display the panel through the toolbar

Bool cscale3dcmainframe::onclosedockingpane (Cdockablepane* pwnd)//virtual function {// todo:  here to add special code and/ or call the base class M_bvideoshow = true;m_bdatagridshow = true;return cmdiframewndex::o Nclosedockingpane (pWnd);} virtual function Bool cscale3dcmainframe::oncloseminiframe (Cpaneframewnd* pwnd) {// todo:  here to add private code and/ or call the base class Cwnd* pwnd = pwnd->getpane ();if  (Pwnd->iskindof (Runtime_class (CTabbedPane)))// Multiple Windows {ctabbedpane* tabpane =  (ctabbedpane *) pwnd; Cmfcbasetabctrl* ptabwnd = tabpane->getunderlyingwindow ();//Close All panel for  (int i  = 0; i < ptabwnd->gettabsnum ();  i++) {cdockablepane* pbar =  dynamic_downcast (cdockablepane,                                  ptabwnd->gettabwnd (i));if  (pbar != null) {assert_valid (PBar);//closes the message into the DockPane queue, waits for the function to close::P Ostmessagea (Pbar->m_hwnd, wm_close,  0, 0);}}} else { //Single Window cdockablepane* pane =  (cdockablepane *) pwnd;if  (pane-> IsKindOf (Runtime_class (CDockablePane))  | |  pane->iskindof (Runtime_class (CPane))  && pane->iskindof (RUNTIME_CLASS ( CPaneFrameWnd)) {//closes the message into the DockPane queue, waits for the function to close::P Ostmessagea (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&Nbsp;= 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 ("Failed to create%s window \ n ",  strpropertieswnd); return;} M_wndvideopanel.enabledocking (Cbrs_align_any);D Ockpane (&m_wndvideopanel);m_bvideoshow     = false;} RecalcLayout ();} Void cscale3dcmainframe::onbuttondatagrid () {// todo:  add Command handler code 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 ("Failed to create%s window \ n ",  strpropertieswnd); return;} M_wnddatagridpanel.enabledocking (Cbrs_align_any);D Ockpane (&m_wnddatagridpanel); m_bDataGridShow =  false;} RecalcLayout ();}

5. Set the label caption text for the view

BOOL cscale3dcchildframe::P Recreatewindow (createstruct& cs) {//TODO: Modify the window class or style here by modifying the CREATESTRUCT CS Cs.style &= ~ (LONG) fws_addtotitle;if (! CMDIChildWndEx::P Recreatewindow (CS)) return False;return TRUE;}
void Cscale3dcscaleweightview::oninitialupdate () {cformview::oninitialupdate (); CMDIChildWndEx * pframe = (cmdichildwndex*) this->getparentframe (); Cscale3dcchildframe * Pmidframe = (cscale3dcchildframe*) pframe;pmidframe->setwindowtext (_T ("Weighing data area"));//TODO: Add private code here and/or call base class}

6. Change the background color of the view

BOOL cscale3dcscaleweightview::onerasebkgnd (cdc* PDC) {//TODO: Add the message Handler code here and/or call the default value CRect RT; GetClientRect (&RT); CBrush Brush;brush. CreateSolidBrush (RGB (255, 255, 255)); CBrush * Poldbrush = Pdc->selectobject (&brush);pD c->fillrect (&rt, &brush);pD C->selectobject ( Poldbrush); return True;//return cformview::onerasebkgnd (PDC);}


Common knowledge points for MFC multi-document applications

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.