home
Using the Splitter Bar dll in a Program
Part III  Introduction

Ernest Murphy ernie@surfree.com

October 18, 2000 

Get the source code here.
 

Abstract:
------------------------------------------------------------------------------------------ 

  Splitter bars are a distinctive visual control element that help organize a large amount of information in a window. They allow your user to resize the relation between two panes of information. A very common example of a splitter is in Windows File Explorer, which uses a splitter bar to divide two panes of information.

  Having built a reusable library to hold our splitter bar class, we now demonstrate a program that uses the splitter.
 

Introduction:
------------------------------------------------------------------------------------------

  If the code for the program in this part looks somewhat familiar, good for you. You have recognized Iczelion's Tutorial 10: Dialog Box as Main Window. I copied most of his source (and most of the resource code too) as a base for this project.

  The first change I made was to the dialog resource. The buttons were removed, a second edit control was added, and the menu was simplified. The final window looks like so:

 Wow, see it there in the middle? That's our splitter. First, let's look at the resource file:
 
#include "resource.h"

#define IDC_EDIT1     3000
#define IDC_EDIT2     3001
#define IDC_SPLITTER  3002
#define IDM_EXIT      3003

MyDialog DIALOG 10, 10, 205, 99
STYLE 0x0004 | DS_CENTER | WS_CAPTION | WS_MINIMIZEBOX |
      WS_SYSMENU | WS_VISIBLE | WS_OVERLAPPED | 
      DS_MODALFRAME | DS_3DLOOK
CAPTION "Splitter Control Test Application"
CLASS "DLGCLASS"
BEGIN
    EDITTEXT         IDC_EDIT1,   5,5,111,80, ES_AUTOHSCROLL | ES_LEFT
    CONTROL "",      IDC_SPLITTER, "VSplitterCtrl", 0, 116, 5, 2, 80
    EDITTEXT         IDC_EDIT2,  118,5,82,80, ES_AUTOHSCROLL | ES_LEFT
END

MyMenu  MENU
BEGIN
    POPUP "&File"
    BEGIN
        MENUITEM "E&xit", IDM_EXIT
    END
END

  Look closely at the middle line in the DIALOG BEGIN block. See the CONTROL statement? That is our splitter control. The CONTROL statement is a generic way to load a control that rc.exe (the resource compiler) does not understand.

  The CONTROL statement will translate to the following code:
 
invoke CreateWindow ("VSplitterCtrl", "", StyleFlags, 
                     116 * cxChar/4, 5 * cyChar/8,
                     2 * cxChar/4,  80 * cyChar/8, 
                     hWndParent, IDC_SPLITTER, hInstance, NULL)

  where cxChar and cyChar are the width and height of a system font character in pixels.

  We only need make a slight addition to the program between the lines where we CreateDialogParam and ShowWindow:
 
invoke CreateDialogParam,hInstance,ADDR DlgName,NULL,NULL,NULL
mov   hDlg,eax

; now inform the splitter what is should move
invoke GetDlgItem, hDlg, IDC_EDIT1
mov hLeft, eax
invoke GetDlgItem, hDlg, IDC_EDIT2
mov hRight, eax
invoke GetDlgItem, hDlg, IDC_SPLITTER
mov hSplitter, eax
invoke SendMessage, hSplitter, WM_SET_PANES_HWND, hLeft, hRight
invoke SendMessage, hSplitter, WM_SET_BORDERS_MIN, 60, 30

invoke ShowWindow, hDlg,SW_SHOWNORMAL

  These are our new window messages. We use GetDlgItem to get the window handle of the three controls on our parent window, and use the splitter window handle to send a message to our splitter what the side window handles are. Then we send the minimum widths. For this test program, we make the left side noticeably wider then the right side.

  Now, compile the program and run it. That's all we need do to get our new custom control to run in our project. Gee, that was easy, huh?

------------------------------------------------------------------------------------------

Part I Splitter Bars

Part II Splitter Bar DLL

Part IV Ready for Prime Time
 

home