Partager via


CMFCEditBrowseCtrl Class

The CMFCEditBrowseCtrl class supports the edit browse control, which is an editable text box that optionally contains a browse button. When the user clicks the browse button, the control performs a custom action or displays a standard dialog box that contains a file browser or a folder browser.

class CMFCEditBrowseCtrl : public CEdit

Members

Public Constructors

Name

Description

CMFCEditBrowseCtrl::CMFCEditBrowseCtrl

Default constructor.

CMFCEditBrowseCtrl::~CMFCEditBrowseCtrl

Destructor.

Public Methods

Name

Description

CMFCEditBrowseCtrl::EnableBrowseButton

Enables or disables (hides) the browse button.

CMFCEditBrowseCtrl::EnableFileBrowseButton

Enables the browse button and puts the edit browse control in file browse mode.

CMFCEditBrowseCtrl::EnableFolderBrowseButton

Enables the browse button and puts the edit browse control in folder browse mode.

CMFCEditBrowseCtrl::GetMode

Returns the current browse mode.

CMFCEditBrowseCtrl::OnAfterUpdate

Called by the framework after the edit browse control is updated with the result of a browse action.

CMFCEditBrowseCtrl::OnBrowse

Called by the framework after the user clicks the browse button.

CMFCEditBrowseCtrl::OnChangeLayout

Redraws the current edit browse control.

CMFCEditBrowseCtrl::OnDrawBrowseButton

Called by the framework to draw the browse button.

CMFCEditBrowseCtrl::OnIllegalFileName

Called by the framework when an illegal file name was entered in the edit control.

CMFCEditBrowseCtrl::PreTranslateMessage

Translates window messages before they are dispatched to the TranslateMessage and DispatchMessage Windows functions. For syntax and more information, see CWnd::PreTranslateMessage.

CMFCEditBrowseCtrl::SetBrowseButtonImage

Sets a custom image for the browse button.

Remarks

Use an edit browse control to select a file or folder name. Optionally, use the control to perform a custom action such as to display a dialog box. You can display or not display the browse button, and you can apply a custom label or image on the button.

The browse mode of the edit browse control determines whether it displays a browse button and what action occurs when the button is clicked. For more information, see the GetMode method.

The CMFCEditBrowseCtrl class supports the following modes.

  • custom mode
    A custom action is performed when the user clicks the browse button. For example, you can display an application-specific dialog box.

  • file mode
    A standard file selection dialog box is displayed when the user clicks the browse button.

  • folder mode
    A standard folder selection dialog box is displayed when the user clicks the browse button.

How-To: Specify an Edit Browse Control

Perform the following steps to incorporate an edit browse control in your application:

  1. If you want to implement a custom browse mode, derive your own class from the CMFCEditBrowseCtrl class and then override the CMFCEditBrowseCtrl::OnBrowse method. In the overridden method, execute a custom browse action and update the edit browse control with the result.

  2. Embed either the CMFCEditBrowseCtrl object or the derived edit browse control object into the parent window object.

  3. If you use the Class Wizard to create a dialog box, add an edit control (CEdit) to the dialog box form. Also, add a variable to access the control in your header file. In your header file, change the type of the variable from CEdit to CMFCEditBrowseCtrl. The edit browse control will be created automatically. If you do not use the Class Wizard, add a CMFCEditBrowseCtrl variable to your header file and then call its Create method.

  4. If you add an edit browse control to a dialog box, use the ClassWizard tool to set up data exchange.

  5. Call the EnableFolderBrowseButton, EnableFileBrowseButton, or EnableBrowseButton method to set the browse mode and display the browse button. Call the GetMode method to obtain the current browse mode.

  6. To provide a custom image for the browse button, call the SetBrowseButtonImage method or override the OnDrawBrowseButton method.

  7. To remove the browse button from the edit browse control, call the EnableBrowseButton method with the bEnable parameter set to FALSE.

Inheritance Hierarchy

CObject

   CCmdTarget

      CWnd

         CEdit

            CMFCEditBrowseCtrl

Example

The following example demonstrates how to use two methods in the CMFCEditBrowseCtrl class: EnableFolderBrowseButton and EnableFileBrowseButton. This example is part of the New Controls sample.

    CMFCEditBrowseCtrl m_wndFolderEdit;
    CMFCEditBrowseCtrl m_wndFileEdit;


...


    // enable the browse button and put the control in file browse mode
    m_wndFolderEdit.EnableFolderBrowseButton();
    // enable the browse button and put the control in the folder browse mode
    m_wndFileEdit.EnableFileBrowseButton();

Requirements

Header: afxeditbrowsectrl.h

See Also

Reference

Hierarchy Chart

Other Resources

MFC Classes