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...
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...
GetWindowRect(hwnd,&Dialog);
GetWindowRect(ListView,&ListViewRect);
SetWindowPos(ListView,0,(ListViewRect.left-Dialog.left),
(ListViewRect.top-Dialog.top )-20,290,170,0);
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.
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.
if(uMsg==BFFM_SELCHANGED)
{
t = SHGetPathFromIDList((ITEMIDLIST*)lParam, c);
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.