Home

The OS/2 directory control


Date : 27 - February - 2008
Author : Jasper de Keijzer

Introduction

Currently OS/2 does not have a directory control. Most developers use the standard file dialog and by using subclassing they are able to give the end user the option to select a directory. Unfortunatly the way this works is a bit glumsy, it namely still shows the edit control for entering a filename, the directory tree is very small and does not give a good impression on where you are in the big picture. What actually is needed is a kind of explorer tree showing all drives and allows the navigation through the directories by expanding the nodes in the tree. Here the directory control (dirctrl) comes into play.
 
 

Directory Control

The directory control allows you to navigate through a tree view of all drives and directories. From the developer perspectief it can be created by one single call and the selected directory can be queried. Depending on the constructor used it also can notify the parent window on a directory change.

The following picture shows a standard window with at the left side the directory control.

With a simple call the directory can be queried.
 
 

Constructor:

dirCtrl::dirCtrl(HAB hab, HWND hParent, long controlid, long flAttribute, unsigned long ulNotify )
 
 
 
Parameter Description
HAB hab - anchorblock handle, mandatory
HWND hParent - The window handle of the parent.
LONG controlid - This is the contol number used to create the window/control. Must be unique in the program. The control uses the controlid number plus controlid+1.
LONG flAttribute - Can be zero or CV_MINI. Defines the display size of the pictured in the control.
ULONG ulNotify - When needed you can ask to be notified on a directory selection change. Specify a value > WM_USER. The specified message id will be used to notify the parent window. 

Example:

 myTree = new dirCtrl(hab,hwnd,TREE_ID,CV_MINI,0)
This construction implies that we have to ask for the selected directory since the last parameter is smaller than WM_USER. Further, the icon will be shown in small format due to the CV_MINI defined in the constructor. TREE_ID is just a #define TREE_ID 100, but that's up to you. The control is created standard with a Helvetica 8 points font, which can be changed.

Querying the selected directory

At a certain moment you want to know in your code what the selected diretory is. This can be done with the following method.

BOOL dirCtrl::getDirectoryName( char *szBuf, int iSize) ;

Example

On a menu selection or on a button click in your app, you want to know what the selected directoy is

case WM_COMMAND:
switch(LOUSHORT(mp1)) {
case IDM_NEW:
myTree->getDirectoryName(szDirectory, sizeof(szDirectory));
break;

szDirectory will contain the selected directory on return. To be sure you can check on the return value of the method. It returns false when the given buffer is too small. Use a buffer of 255 chars and you are on the save side.
 
 

Getting notified.

The control sends a message when a selection lasts longer than one second. So you will not be notified during selection changes but only when the selection is stable for a while.

Example:

#define UM_LETMEKNOW WM_USER+100

 myTree 
= new dirCtrl(hab,hwnd,TREE_ID,CV_MINI,UM_LETMEKNOW);
In the window procedure the following code will do the job,
switch(msg) 
{
case 
UM_LETMEKNOW:
STRCPY(szBuf,(char *)mp1); 
.....
A buffer of 255 chars length will be sufficient.

Getting the window handle.

You need the window handle to position the control in your app. You can use the function hwndControl = WinWindowFromID (hwnd,TREE_ID); or use the method of the dirctrl class. getWindowHandle(). Of course TREE_ID is something defined by you with #define. You need the window handle to size the control in your window.
 
 

The sources.

The sources are free for download. You can use them in your program without paying any fees. But if you find a bug or serious flaw in the implementation, please mail me so I can correct it and put it on the web. Just to be sure the latest and greatest is always available here.
 
 
 

Download the sources.

pmdirctrl.zip

Free download of PMSHEET

The pmsheet homepage