Click here to Skip to main content
15,860,861 members
Articles / Desktop Programming / WTL
Article

WTL Hybrid Edit Control that Combines Edit Control and Button Control

Rate me:
Please Sign up or sign in to vote.
4.25/5 (12 votes)
13 May 20031 min read 55.7K   1.4K   30   4
A control that combines an edit control, and a browse button that brings up a file/folder browse dialog.

Sample Image - WtlEditBrowserCtrl.jpg

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 "WtlEditBrowserCtrl.h"

//...

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


Written By
Web Developer
Canada Canada
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralAdding theme support Pin
_oti20-Dec-05 11:01
_oti20-Dec-05 11:01 
Hi Ilya,

Nice work. I've used it in a couple of projects now Smile | :)

I had a need to add theme support to the control, and did it like this:
<br />
void CWtlEditBrowserCtrl::DrawButton(int nButtonState)<br />
{   // if the button is too small, do not draw it<br />
  // ... skipped setup code ...<br />
  DC.SelectBitmap(Bitmap);<br />
<br />
  CTheme theme;<br />
  if (0 != theme.OpenThemeData(GetDesktopWindow(), L"Button"))<br />
  {<br />
    DC.FillRect(DrawRect, GetSysColor(COLOR_WINDOW));<br />
    DrawRect.InflateRect(1, 1);<br />
    if (nButtonState == BTN_DOWN)<br />
    {<br />
      theme.DrawThemeBackground(DC, BP_PUSHBUTTON, PBS_PRESSED, DrawRect);<br />
      DrawDots(DC, GetSysColor(COLOR_BTNTEXT), 1);<br />
    }<br />
    else if (nButtonState & BTN_DISABLED)<br />
    {<br />
      theme.DrawThemeBackground(DC, BP_PUSHBUTTON, PBS_PRESSED, DrawRect);<br />
      DrawDots(DC, GetSysColor(COLOR_3DHILIGHT), 1);<br />
      DrawDots(DC, GetSysColor(COLOR_3DSHADOW));<br />
    }<br />
    else<br />
    {<br />
      theme.DrawThemeBackground(DC, BP_PUSHBUTTON, PBS_NORMAL, DrawRect);<br />
      DrawDots(DC, GetSysColor(COLOR_BTNTEXT));<br />
    }<br />
  }<br />
  else<br />
  {<br />
    // use HS_DIAGCROSS pattern brush to test brush alignment<br />
    // ... skipped regular button drawing code, which could<br />
    // probably benefit from the use of DrawFrameControl ...<br />
  }<br />
<br />
  // Blit the button image onto the screen<br />
  // ... skipped blitting and cleanup code ...<br />
}<br />

You will need to #include <atltheme.h> at some point, and this requires _WIN32_WINNT >= 0x0501.

And that's about it.

Thanks again,
   Phil.

--
All things considered, you can't really consider all things ...
GeneralREFLECT_NOTIFICATIONS Pin
fioresoft28-Dec-04 19:44
fioresoft28-Dec-04 19:44 
GeneralNice work! Pin
Michael Hulthin30-Oct-03 23:38
Michael Hulthin30-Oct-03 23:38 
GeneralRe: Nice work! Pin
Patrick DellEra14-Nov-04 11:49
Patrick DellEra14-Nov-04 11:49 

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.