Click here to Skip to main content
15,895,746 members
Articles / Desktop Programming / MFC
Article

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 64.1K   1.6K   20   2
Adding and subclassing the custom controls

Sample Image - Browse_for_folder_part_2.jpg

Introduction

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.

Logic

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|
   ES_AUTOHSCROLL,0,100,100,50,hwnd,0,ghInstance,NULL);
checkbox = CreateWindowEx(0,"BUTTON","Show the edit control.",
   WS_CHILD|WS_VISIBLE| WS_CLIPCHILDREN|BS_AUTOCHECKBOX,0,100,100,
   50,hwnd,0,ghInstance,NULL);

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.

if(uMsg==WM_LBUTTONUP)
{
    if((SendMessage(hwnd,BM_GETCHECK,0,0))==1)
    {
        ShowWindow(edit,SW_HIDE);
    }
    else
    {
        ShowWindow(edit,SW_SHOW);
    }

}

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 : yogmj@hotmail.com. Visit my website : http://www.stechome.netfirms.com/

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


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 Rusakow29-May-03 4:18
Michael Rusakow29-May-03 4:18 
AnswerRe: How to set focus to added control by pressing Tab? Pin
Michael Rusakow9-Jun-03 15:35
Michael Rusakow9-Jun-03 15: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.