How to implement a csplitterwnd into a cdialogbox in three easy steps without overriding any function, writing new classes, etc.
Because I'm not a writer, this article will take you directly to the main subject: how to implement a csplitterwnd into a cdialogbox without overriding MFC any functions or writing new classes. the solution is simple; you just need to follow these steps:
- In the oncreate function or your cdialog, register a new windowclass by calling "afxregisterwndclass ".
- Create a new cframewnd by using the "new" operator and initialize it.
- Create your splitter by using the new cframewnd you just created as the parent.
By using this technique, you don't need to override anything because the parent of the splitter is still a cframewnd. in the following sample, we create a splitter with two panes (with the same view type ).
Sample: Int Cmydialog: oncreate (maid ){ If (Cdialog: oncreate (lpcreatestruct) =-1) Return -1; // Initialize a context for the view. cdialog1 is my view and // Is defined as: Class cdialog1: Public ctreeview. Ccreatecontext CCC; CCC. m_pnewviewclass = runtime_class (cdialog1); CCC. m_pcurrentdoc = Null ; CCC. m_pnewdoctemplate = Null ; CCC. m_plastview = Null ; CCC. m_pcurrentframe = Null ; // Because the cframewnd needs a window class, we will create // A new one. I just copied the sample from msdn help. // When using it in your project, you may keep cs_vredraw and // Cs_hredraw and then throw the other three parameters. Cstring strmyclass = afxregisterwndclass (cs_vredraw | cs_hredraw,: loadcursor ( Null , Idc_arrow), (hbrush): getstockobject (white_brush),: loadicon ( Null , Idi_application )); // Create the frame window with "this" as the parent M_pmyframe =New Cframewnd; m_pmyframe-> Create (strmyclass, "", ws_child, crect (0, 1, 1 ), This ); M_pmyframe-> showwindow (sw_show); m_pmyframe-> movewindow (0, 0, 300,300 ); // And finally, create the splitter with the frame // The parent M_csplitter.createstatic (pmyframe, 1, 2); m_csplitter.createview (100,100, runtime_class (cdialog1), csize (), & CCC); substring (, runtime_class (cdialog1 ), csize (100,100), & CCC);} bool cmydialog: oninitdialog () {cdialog: oninitdialog (); crect; // Get the rectangle of the custom window. The custom window // Is just a big button that is not visible and is disabled. // It's a trick to not use coordinates directly. Getdlgitem (idc_cutsom_window)-> getwindowrect (& crect ); // Move the Splitter Screentoclient (& crect); m_pframewnd-> movewindow (& crect); m_pframewnd-> showwindow (sw_show); m_csplitter.movewindow (0, 0, crect. width (), crect. height (); m_csplitter.showwindow (sw_show ); Return True; // Return true unless you set the focus to // Control // Exception: OCX property pages shocould return // False }