Click here to Skip to main content
Click here to Skip to main content

WTL MDI Application with Splitter

, , 12 Oct 2002
Rate this:
Please Sign up or sign in to vote.
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

Introduction

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;
  GetClientRect(&rcClient);

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

  // Create the About dialog in the left pane
  m_about.Create(m_splitter.m_hWnd);
  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
  ::SetFocus(m_hWndMDIClient);

  // 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);
    MDIRefreshMenu();
    ::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 SOFTWARE IS DISTRIBUTED AS-IS, WITHOUT WARRANTIES OF ANY KIND.

License

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

Share

About the Authors

Ed Gadziemski
Founder KwikiVac
United States United States
Ed has over 40 years experience in computer technology and a bachelor's degree in Business Administration. He currently owns an online retail business and previously owned a software consulting firm. During his career, he has 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.
 
This material is copyright 2014 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 PinmemberPrafull_neo_code12-Jan-12 2:39 
GeneralRe: Nice Article PinmemberPrafull_neo_code18-Jan-12 19:46 
GeneralRe: Nice Article PinmemberPrafull_neo_code21-Jan-12 1:50 
GeneralRe: Nice Article PinmemberPrafull_neo_code23-Jan-12 1:31 
GeneralRe: Nice Article PinmemberPrafull_neo_code23-Jan-12 4:30 
GeneralRe: Nice Article PinmemberPrafull_neo_code28-Jan-12 3:20 
Questioni don't want to use a command bar but... Pinmember[aMDS]22-Sep-07 5:05 
Generalgood Pinmembervikas4117923-Aug-05 1:01 
GeneralRe: good PinmemberRick Pingry23-Aug-05 4:42 
GeneralCool! PinmemberJörgen Sigvardsson6-Jul-05 8:47 
Questionhow to lock pane for auto-resizing ? PinmemberMandalay17-Jul-04 2:48 
AnswerRe: how to lock pane for auto-resizing ? PinmemberMandalay18-Jul-04 0:40 
GeneralScroll Bars in Dialog Box PinmemberRick Pingry3-Apr-04 3:58 
QuestionMiss atlres.h? Pinmembertsung-yu25-Dec-03 20:53 
AnswerRe: Miss atlres.h? Pinmemberdragon wang29-Dec-03 3:57 
GeneralRe: Miss atlres.h? PinmemberKim, HighControl17-Apr-05 23:07 
GeneralCrashes on New File Pinmemberjweston30-Jun-03 4:49 
GeneralRe: Crashes on New File PinmemberEd Gadziemski30-Jun-03 9:15 
GeneralRe: Crashes on New File Pinmemberjweston1-Jul-03 2:46 
GeneralRe: Crashes on New File Pinmemberjweston29-Jul-03 2:47 
GeneralRe: Crashes on New File PinmemberFatalError0x4c28-Jul-03 18:09 
GeneralRe: Crashes on New File Pinmembere-buch29-Sep-04 23:25 
GeneralRe: Crashes on New File Pinmemberfree2000fly13-Nov-07 4:06 
GeneralChanging the panes around Pinmemberjasco14-Dec-02 12:46 
QuestionMFC MDI Application with Splitter? Pinmemberjasco7-Dec-02 12:49 

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.141022.2 | Last Updated 13 Oct 2002
Article Copyright 2002 by Ed Gadziemski, Rick Pingry
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid