Click here to Skip to main content
15,305,969 members
Articles / Desktop Programming / WTL
Posted 12 Oct 2002


25 bookmarked

WTL MDI Application with Splitter

Rate me:
Please Sign up or sign in to vote.
4.90/5 (12 votes)
12 Oct 20022 min read
This article describes how to use an MDI client in a splitter pane of a WTL MDI application with splitter window.

WTL MDI Splitter Sample


This article explains how to use WTL's CSplitterWindow class in an MDI application. The sample project included with this article is a wizard-generated MDI application enhanced with a two pane vertical splitter. On the left side of the splitter is the About dialog (thus no Help menu) and on the right side is the MDI client window.

Main Frame

Most of the relevant code for using the splitter window is contained in the mainframe.h file of the sample project. The splitter is initialized in OnCreate() by calling the CreateClient() method and assigning the result to m_hWndClient. CreateClient() sets up the left and right panes, issues a call to CreateMDIClient(), and assigns that result to m_hWndMDIClient. It is important to change the parent of the MDI client to the splitter, as shown below.

// Create and populate the spltter window
HWND CreateClient()
{ // Get the Client RECT for the entire window as a starting size
  RECT rcClient;

  // Create the vertical splitter. This is the main window
  m_splitter.Create(m_hWnd, rcClient, NULL, WS_CHILD | WS_VISIBLE |

  // Create the About dialog in the left pane
  m_splitter.SetSplitterPane(SPLIT_PANE_LEFT, m_about.m_hWnd);

  // Create the MDI client in the right pane
  m_hWndMDIClient = CreateMDIClient();
  m_splitter.SetSplitterPane(SPLIT_PANE_RIGHT, m_hWndMDIClient);

  // IMPORTANT! Make the splitter the parent of the MDI client
  ::SetParent(m_hWndMDIClient, m_splitter.m_hWnd);

  m_splitter.SetSplitterPos(132); // from left

  // Splitter is ultimately the client of Main Frame (m_hWndClient)
  return m_splitter.m_hWnd; }

In addition, a modification is made to the OnFileNew handler so that the child window is assigned the proper parent: pChild->CreateEx(m_hWndMDIClient). It is important to use the MDI client handle when carrying out operations of this sort, since m_hWndClient refers only to the splitter window.

Child Frame

The relevant code for handling child window activation is contained in the childfrm.h file of the sample project. A child window with an edit control view is initialized and assigned an icon in OnCreate(). In addition, a window message, WM_MDIACTIVATE, is overriden to ensure proper title bar and menu activation and deactivation. Here is the handler code:

LRESULT OnMDIActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{ // Child to deactivate
  ::SendMessage((HWND)wParam, WM_NCACTIVATE, FALSE, 0);

  // Child to activate
  ::SendMessage((HWND)lParam, WM_NCACTIVATE, TRUE, 0);

  // Set focus to the MDI client

  // Switch to child window menu or back to default menu
  if((HWND)lParam == m_hWnd && m_hMenu != NULL)
  { HMENU hWindowMenu = GetStandardWindowMenu(m_hMenu);
    MDISetMenu(m_hMenu, hWindowMenu);
    ::DrawMenuBar(GetMainFrame()); }
  else if((HWND)lParam == NULL) // last child has closed
    ::SendMessage(GetMainFrame(), WM_MDISETMENU, 0, 0);

  bHandled = FALSE;
  return 1; }

The GetMainFrame() method called in OnMDIActivate() is a simple wrapper function that accounts for the splitter window as follows:

HWND GetMainFrame() { return ::GetParent(GetMDIFrame()); }

Finally, another window message, WM_MENUSELECT, is overriden to allow activation of the child window's system menu (upper left title bar icon), like this:

LRESULT OnMenuSelect(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL&)
{ return ::SendMessage(GetMainFrame(), uMsg, wParam, lParam); }

Additional Stuff

The sample project also has a few helper routines in mainframe.h that work with the UpdateUI mechanism to enable/disable menu and toolbar buttons when a child window and its edit control are active. A WTL class, CEditCommands is inherited by the view (mdisplitview.h) to provide standard undo, cut, copy, and paste functions for the edit control.

The sample project also uses two WTL message map macros to exchange commands between the main frame and child frame. CHAIN_MDI_CHILD_COMMANDS() is added to the main frame message map and CHAIN_CLIENT_COMMANDS() is added to the child frame map so that edit commands are available from the main menu and toolbar as well as the edit control's popup menu.

Terms Of Use

The sample application available with this article is free for any purpose.



This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Authors

Ed Gadziemski
Founder Choycer
United States United States
Ed has over 40 years experience in computer technology and a bachelor's degree in Business Administration. He's currently a marketing technology consultant. During his career, he's led software development departments and created software still in use in the communications and healthcare industries. Ed is a veteran of the United States Army. He lives in Arizona in the United States.

Find Ed on Linkedin.

This material is copyright 2019 by Ed Gadziemski. Unauthorized use is strictly prohibited. All rights reserved.

Rick Pingry
Software Developer (Senior) Gremlin Games
United States United States
No Biography provided

Comments and Discussions

NewsNice Article Pin
Prafull_neo_code12-Jan-12 2:39
MemberPrafull_neo_code12-Jan-12 2:39 
GeneralRe: Nice Article Pin
Prafull_neo_code18-Jan-12 19:46
MemberPrafull_neo_code18-Jan-12 19:46 
GeneralRe: Nice Article Pin
Prafull_neo_code21-Jan-12 1:50
MemberPrafull_neo_code21-Jan-12 1:50 
GeneralRe: Nice Article Pin
Prafull_neo_code23-Jan-12 1:31
MemberPrafull_neo_code23-Jan-12 1:31 
GeneralRe: Nice Article Pin
Prafull_neo_code23-Jan-12 4:30
MemberPrafull_neo_code23-Jan-12 4:30 
GeneralRe: Nice Article Pin
Prafull_neo_code28-Jan-12 3:20
MemberPrafull_neo_code28-Jan-12 3:20 
Questioni don't want to use a command bar but... Pin
[amdx]22-Sep-07 5:05
Member[amdx]22-Sep-07 5:05 
Generalgood Pin
vikas amin23-Aug-05 1:01
Membervikas amin23-Aug-05 1:01 
GeneralRe: good Pin
Rick Pingry23-Aug-05 4:42
MemberRick Pingry23-Aug-05 4:42 
GeneralCool! Pin
Jörgen Sigvardsson6-Jul-05 8:47
MemberJörgen Sigvardsson6-Jul-05 8:47 
Questionhow to lock pane for auto-resizing ? Pin
Mandalay17-Jul-04 2:48
MemberMandalay17-Jul-04 2:48 
AnswerRe: how to lock pane for auto-resizing ? Pin
Mandalay18-Jul-04 0:40
MemberMandalay18-Jul-04 0:40 
GeneralScroll Bars in Dialog Box Pin
Rick Pingry3-Apr-04 3:58
MemberRick Pingry3-Apr-04 3:58 
QuestionMiss atlres.h? Pin
tsung-yu25-Dec-03 20:53
Membertsung-yu25-Dec-03 20:53 
AnswerRe: Miss atlres.h? Pin
dragon wang29-Dec-03 3:57
Memberdragon wang29-Dec-03 3:57 
GeneralRe: Miss atlres.h? Pin
Member 21272217-Apr-05 23:07
MemberMember 21272217-Apr-05 23:07 
GeneralCrashes on New File Pin
jweston30-Jun-03 4:49
Memberjweston30-Jun-03 4:49 
GeneralRe: Crashes on New File Pin
Ed Gadziemski30-Jun-03 9:15
professionalEd Gadziemski30-Jun-03 9:15 
GeneralRe: Crashes on New File Pin
jweston1-Jul-03 2:46
Memberjweston1-Jul-03 2:46 
GeneralRe: Crashes on New File Pin
jweston29-Jul-03 2:47
Memberjweston29-Jul-03 2:47 
GeneralRe: Crashes on New File Pin
fioresoft28-Jul-03 18:09
Memberfioresoft28-Jul-03 18:09 
GeneralRe: Crashes on New File Pin
e-buch29-Sep-04 23:25
Membere-buch29-Sep-04 23:25 
GeneralRe: Crashes on New File Pin
free2000fly13-Nov-07 4:06
Memberfree2000fly13-Nov-07 4:06 
GeneralChanging the panes around Pin
jasco14-Dec-02 12:46
Memberjasco14-Dec-02 12:46 
QuestionMFC MDI Application with Splitter? Pin
jasco7-Dec-02 12:49
Memberjasco7-Dec-02 12:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.