Click here to Skip to main content
Click here to Skip to main content
Go to top

Customizing the "Browse for folder" dialog

, 20 Apr 2003
Rate this:
Please Sign up or sign in to vote.
This Program customizes the "Browse For folder dialog" with a few lines of code...

Sample Image - Customize_FolderDialog_1.jpg

Introduction

I was just working with WIN32 apis and I thought that when we use the browse for folder dialog boxes, at that time there is nothing that shows us the full path and so, I have written this program.

How It Works?

This code is fully based on the win32 apis. I am giving this functionality using the basic functions; let us discuss them one by one...

Logic

This program uses the simple win32 api function calls like , FindWindowEx, CreateWindow etc. With these functions we can create the edit box and the static control. The CreateWindowEx function is used to create the child controls that are one edit box and the one static control. Then just add it to the Browse for folder dialog.

Code

Firstly Declare the lpofn to the BorwseCallbackProc Procedure. Then the whenever the browse for folder dialog box initializes that time it will send the message to the procedure that is "BFFM_INITIALIZED". That time create the edit and the static controls like below...

//Create the edit and static control on the dialog box
edit=CreateWindowEx(0,"EDIT","Yogesh M Joshi.",WS_CHILD|WS_VISIBLE|WS_BORDER|
   ES_AUTOHSCROLL,0,100,100,50,hwnd,0,ghInstance,NULL);
HWND caption=CreateWindowEx(0,"STATIC","You have selected the folder :",
   WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN,0,100,100,50,hwnd,0,ghInstance,NULL);

Here the ghInstance is the instance of the dialog box. The "EDIT" and "STATIC" are the names of the classes. and The flags sets the style of the contols. Just then we will have to resize the list view contol but firstly we will find it on the "Browse For Folder" dialog, That's so easy just use the FindWindowEx function.

HWND ListView=FindWindowEx(hwnd,NULL,"SysTreeView32",NULL);

In this way we have find the handle of the List iew then resize it. Use the GetWindowRect function to get the rectangles of the "Browse For Folder" Dialog. This will take place in the following way...

//Gets the dimentions of the windows
GetWindowRect(hwnd,&Dialog);
GetWindowRect(ListView,&ListViewRect);

//Sets the listview controls dimentions
SetWindowPos(ListView,0,(ListViewRect.left-Dialog.left),
            (ListViewRect.top-Dialog.top )-20,290,170,0);
//Sets the window positions of edit and dialog controls
SetWindowPos(edit,HWND_BOTTOM,(ListViewRect.left-Dialog.left),
            (ListViewRect.top-Dialog.top )+170,290,20,SWP_SHOWWINDOW);
SetWindowPos(caption,HWND_BOTTOM,(ListViewRect.left-Dialog.left),
            (ListViewRect.top-Dialog.top )+152,290,16,SWP_SHOWWINDOW);

And then I have used the SetFont function to set the fonts of the static and edit control.

//This will set the font of the controls
void SetFont(HWND hwnd,LPTSTR FontName,int FontSize)
{
    
    HFONT hf;
    LOGFONT lf={0};
    HDC hdc=GetDC(hwnd);
    
    GetObject(GetWindowFont(hwnd),sizeof(lf),&lf);
    lf.lfWeight = FW_REGULAR;
    lf.lfHeight = (LONG)FontSize;
    lstrcpy( lf.lfFaceName, FontName );
    hf=CreateFontIndirect(&lf);
    SetBkMode(hdc,OPAQUE);
    SendMessage(hwnd,WM_SETFONT,(WPARAM)hf,TRUE);
    ReleaseDC(hwnd,hdc);
   
}

In this way we have resized the contols. But main thing is not over that if we select any folder then the edit contol must show it. For this purpose the callback message "BFFM_SELCHANGED" and use the SetWindowText api to set the text of the edit contol.

//Selection change message
if(uMsg==BFFM_SELCHANGED)
{
    t = SHGetPathFromIDList((ITEMIDLIST*)lParam, c);

    //Sets the text of the edit control to the current folder
    SetWindowText(edit,c);
        
}

That's all and in this way we can customize the "Browse For Folder" dialog box.

Conclusion

Use this code for educational purpose only. Mail your comments at : yogmj@hotmail.com and to pick some COOL windows utilities isit my homepage at http://www.stechome.netfirms.com/ I am waiting to hear from you.

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 Author

Yogesh M Joshi.
Software Developer AVAYA India Pvt Ltd.
India India
I have completed my B.E. Degree in IT form Aditya Engineering College, Beed. (Maharashtra) India.
 
I have completed Diploma In Advanced Computing (DAC) in Feb 07.
 
Now I am working for AVAYA India Pvt. LTD as software engineer.
Platform : C/C++, Solaris 10, AIX and Windows

Comments and Discussions

 
QuestionNew Folder PinmemberiWizardPro25-Nov-09 7:30 
QuestionCan We Use this Control in ASP.NET For Web Application Pinmembersunilp30-Jan-09 7:16 
GeneralBIF_NEWDIALOGSTYLE Pinmemberrawbite11-Nov-06 22:32 
GeneralPassing the folder path PinmemberJoel++16-Apr-05 19:16 
GeneralRe: Passing the folder path PinsussAnonymous18-Apr-05 7:04 
GeneralRe: Passing the folder path PinmemberYogesh M Joshi.18-Apr-05 7:12 
GeneralRe: Passing the folder path PinmemberJoel++1-May-05 4:54 
GeneralAdding a checkbox PinsussMav Rossi22-Apr-03 7:46 
GeneralRe: Adding a checkbox PinsussMav Rossi22-Apr-03 8:13 
GeneralRe: Adding a checkbox PinmemberYogesh M Joshi.24-Apr-03 22:56 
GeneralTo generate Drive Control PinmemberLalit Kandi10-Jul-06 21:51 
GeneralFeature already supported PinmemberErnest Laurentin21-Apr-03 4:09 
GeneralRe: Feature already supported PinmemberYogesh M Joshi.21-Apr-03 4:49 
GeneralNice idea and a suggestion PinmemberJerry Evans21-Apr-03 3:20 
GeneralRe: Nice idea and a suggestion PinmemberYogesh M Joshi.21-Apr-03 4:54 

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
Web01 | 2.8.140922.1 | Last Updated 21 Apr 2003
Article Copyright 2003 by Yogesh M Joshi.
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid