Creating a splitter window in a dialog box in three easy steps

Source: Internet
Author: User

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:

    1. In the oncreate function or your cdialog, register a new windowclass by calling "afxregisterwndclass ".
    2. Create a new cframewnd by using the "new" operator and initialize it.
    3. 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 }

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.