Click here to Skip to main content
Click here to Skip to main content

WTL Hybrid Edit Control that Combines Edit Control and Button Control

, 13 May 2003
Rate this:
Please Sign up or sign in to vote.
A control that combines an edit control, and a browse button that brings up a file/folder browse dialog.
<!-- Article image -->

Sample Image - WtlEditBrowserCtrl.jpg

<!-- Add the rest of your HTML here -->

Introduction

Sometimes, when we need a user to select a file or folder or ODBC driver, we would have to create two controls, an edit control for entering the text, and a browse button that would bring up a dialog for actually choosing the file or folder or etc. So I thought why not combine the two controls into one. The CWtlEditBrowserCtrl class is the result. The class definition and implementation are in the files WtlEditBrowserCtrl.h and WtlEditBrowserCtrl.cpp which are included in the demo project.

Using the Control

To use this control in your application:

  1. Add the WtlEditBrowserCtrl.h and WtlEditBrowserCtrl.cpp files to your project.
  2. Design the dialog and add the Edit control
  3. Add the WtlEditBrowserCtrl.h header file to your project
  4. Assign a CWtlEditBrowserCtrl to your editbox.
  5. In OnInitDialog(), subclass CWtlEditBrowserCtrl control to ID using the SubclassWindow method.
#include <span class="code-string">"WtlEditBrowserCtrl.h"
</span>

//...

class CMainDlg : public CDialogImpl<CMainDlg>
{     
    BEGIN_MSG_MAP(CMainDlg)          
       ...          
       MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)          
       REFLECT_NOTIFICATIONS()     
    END_MSG_MAP()
    ...
    LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, 
        LPARAM /*lParam*/, BOOL& /*bHandled*/);
    ...
    CWtlEditBrowserCtrl m_Path;     
    ...
}; 

//...

LRESULT CMainDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, 
      LPARAM /*lParam*/, BOOL& /*bHandled*/) 
{
     ...     
     m_Path.SubclassWindow( ::GetDlgItem( m_hWnd, IDC_EDIT1 ) );     
     ...
}

Requirements

You will require the WTL Libraries, these can be downloaded from the microsoft site.

Acknowledgements

I'd like to thank Pete Arends for his original controls :-

I'd also like to thank the others who have given feedback, made suggestions, and helped this become what it is today:

Contacting the Author

Ilya Solnyshkin, E-mail: isolnyshkin@yahoo.com, Web: http://www.printsniffer.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

Share

About the Author

Ilya Solnyshkin
Web Developer
Canada Canada
No Biography provided

Comments and Discussions

 
GeneralAdding theme support Pinmember_oti20-Dec-05 12:01 
GeneralREFLECT_NOTIFICATIONS PinmemberFatalError0x4c28-Dec-04 20:44 
GeneralNice work! PinmemberMichael Hulthin31-Oct-03 0:38 
GeneralRe: Nice work! PinmemberPatrick DellEra14-Nov-04 12:49 
Indeed, nice work!
 
In addition to correcting the initial focused dialog control problem mentioned, that modification also fixes a problem when navigating a dialog with hot keys.
 
To demonstrate, change the labels for the demo project to "F&ileName" and "F&olderName". Then add an edit box (with "Tab Stop" and "Visible" properties set to true) to the dialog. The expectation would be that Alt+I would select the FileName edit box, and that Alt+O would select the FolderName box. Using the original code without the SWP_NOZORDER flag, the newly added edit box will always gain the focus when Alt+I and Alt+O are pressed. With the flag, the accelerator keys work as expected.

 
--
Patrick Dell'Era

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 | Terms of Use | Mobile
Web02 | 2.8.1411022.1 | Last Updated 14 May 2003
Article Copyright 2003 by Ilya Solnyshkin
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid