tanvon++

October 22, 2006

SHBrowseForFolder with a new look

Filed under: Windows — tanvon malik @ 3:50 pm

The code and demo for this article can be found here at www.codeproject.com

The old version of file open dialog box was not so good looking, Then came the explorer style file open dialog, a much better look, then added with the Placedbar yes it look so good.ms I already have tried to customized this explorer style dialog box look here. But this time I not tried to customize it more but I now decided to add the same look and feeling to another commonly used dialog box SHBrowseForFolder dialog. Here in my this project I tried to add the same Placesbar to this dialog.tanvon’s Places bar It has same UI works the same way.

Actually file open dialog ’s Placesbar has these properties.

  • It has a different background then the file open dialog
  • Whole places bar has 3D look.
  • All buttons work as the check boxes in a group.
  • has tooltips
  •  Buttons are transparent and Hot-tracked.

How Stuff Works ?

The messages are the key.

The first and foremost thing in  customization of  a dialog is to watch for its messages. Windows provides us with every commonly used dialog a CALLBACK function. It is the key, with these provided callback functions you can watch for all activity in that specified dialog for which that callback is provided. The same is with SHBrowseForFolder dialog.

CALLBACK   me

the callback function of SHBrowseForFolder  provides us the facility to watch want is happening inside. I handle here BFFM_INITIALIZED which is called just before showing the dialog and at that time all controls are there, so you can do whatever you like. and in my this project I do the same I do this dialog a bit fatty so it can easily reside my toolbar, I also create my toolbar here, because it is the proper place all controls are at there proper place I can choose a proper place for my control the toolbar. And its creation is also appropriate here, because this is the message in which it is easy to get this dialogs handle. And every thing else is ok so crete your control here so your control can live with all the other controls peacefully.

Creation of ToolBar ( The Places Bar )

hwndTB = CreateWindowEx(WS_EX_NOPARENTNOTIFY , TOOLBARCLASSNAME, (LPSTR) NULL,
WS_CHILD |WS_VISIBLE|WS_TABSTOP| CCS_TOP|CCS_NODIVIDER | CCS_NOPARENTALIGN |CCS_NORESIZE| TBSTYLE_FLAT| TBSTYLE_TRANSPARENT
|TBSTYLE_WRAPABLE| TBSTYLE_TOOLTIPS| TBSTYLE_CUSTOMERASE, pt.x-40,pt.y+55, 84,272, hwnd, NULL, NULL, NULL);
 See the Style bits some interesting are
TBSTYLE_FLAT  TBSTYLE_TRANSPARENT TBSTYLE_CUSTOMERASE  CCS_NOPARENTALIGN are.

Some of the Interesting Setting for ToolBar Buttons

The following are the setting for the buttons of the toolbar.

::SendMessage(hwndTB, TB_SETBITMAPSIZE, (WPARAM) 0, MAKELONG (32, 32)); ::SendMessage(hwndTB, TB_SETPADDING, (WPARAM) 0, MAKELONG (13, 22)); ::SendMessage(hwndTB, TB_SETBUTTONSIZE, (WPARAM) 0, MAKELONG (67, 50)); The first one sets the size of the bitmap which will be shown on the toolbar button. The second one sets the padding, the gap or margin which will be left at both sides horizontally and vertically. The fourth message tell the toolbar to set the size for its buttons according to the given dimensions.

Catch all the Messages

Another important thing in the callback function is that I replace the default dialogproc procedure with my own function.

OldProc = (WNDPROC) SetWindowLong(hwnd,DWL_DLGPROC, (LONG) MyProc);

This was necessary because the callback functions was good at giving the messages it was made for, but it does not give us a way to catch all the messages of that dialog, so replaces the default dialogproc with my own function. what I do in that function I will describe it below. (more…)

Blog at WordPress.com.