Click here to Skip to main content
15,569,858 members
Articles / Desktop Programming / MFC
Posted 26 Apr 2003


20 bookmarked

Customizing "Browse for folder" dialog Part - II

Rate me:
Please Sign up or sign in to vote.
3.60/5 (9 votes)
26 Apr 20032 min read
Adding and subclassing the custom controls

Sample Image - Browse_for_folder_part_2.jpg


This is my second article on the topic Customizing "Browse for folder" dialog and in the previous article (Customizing the "Browse for folder" dialog Part - I) we have seen how to add the caption and the edit box on the browse for folder dialog.

In the previous code we have seen how to add simple controls on the dialog but, some people have problem to add the custom controls like a "Check Box","Button" and interfacing with them and that's why I a writing the special article to interface with these controls and adding them on the dialog box.


I think the code given below is very simple to understand if you are familiar with the WIN32API. The code subclasses the controls and then we can interface them through our program. The code uses simple functions like SendWindowLong to subclass the dialog control. Once the control has been subclassed then every thing is yours. You can process the messages as usual and then you can process the messages as regular.

<h>Creating the controls

To create the controls I have used the CreateWindowEx function but here, for the check box the class is "BUTTON" and flag is the BS_AUTOCHECKBOX that will create the check box. The code is as given below...

edit=CreateWindowEx(0,"EDIT","Yogesh M Joshi.",WS_CHILD|WS_VISIBLE|WS_BORDER|
checkbox = CreateWindowEx(0,"BUTTON","Show the edit control.",

Here edit and the checkbox give the handles to the respective control.

Subclassing the control

The subclassing of the control is the very important thing since we are interfacing with the controls. Actually, we don't have the main dialog procedure of the browse for folder dialog, and so, I am subclassing the check box within the BFFM_INITIALIZED message. this gives us the better way because the controls are just being created. Here the WNDPROC declares the default window procedure which have to be returned named CBProc. This will go in the following way.

// Subclass the checkbox control. 
CBProc = (WNDPROC) SetWindowLong(checkbox,GWL_WNDPROC, 
         (LONG) CheckBoxSubclassProc); 

Here the CheckBoxSubClassProc is the subclass procedure which will process the messages. As sown below...

// Subclass procedure 
LRESULT APIENTRY CheckBoxSubclassProc(HWND hwnd,UINT uMsg,WPARAM wParam,
                 LPARAM lParam) 

     return CallWindowProc(CBProc, hwnd, uMsg, 
        wParam, lParam); 

Processing the messages :

To process the messages posted by the main window procedure of the Browse for folder dialog, we have declared the procedure above. and the just put the following code to that procedure. (I have used the LBUTTONUP message I don't get the result of CLICK message). Here ShowWindow function will set the visibility of the edit control by SW_HIDE or SW_SHOW flags.



In this way we can add and subclass the controls on the browse for folder dialog. I thing You will get the "WINAMP" styled browse for folder dialog with this code try for it. That's not over wait for the Part - III of this article. click the following links to contact me or visit my website for COOL programs. Mail me at : Visit my website :


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

Written By
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

QuestionHow to set focus to added control by pressing Tab? Pin
Michael A. Rusakov29-May-03 5:18
Michael A. Rusakov29-May-03 5:18 
AnswerRe: How to set focus to added control by pressing Tab? Pin
Michael A. Rusakov9-Jun-03 16:35
Michael A. Rusakov9-Jun-03 16:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.