CMFCToolBarComboBoxButton Class
A toolbar button that contains a combo box control ( CComboBox Class).
class CMFCToolBarComboBoxButton : public CMFCToolBarButton
Name | Description |
---|---|
CMFCToolBarComboBoxButton::CMFCToolBarComboBoxButton | Constructs a CMFCToolBarComboBoxButton . |
Name | Description |
---|---|
CMFCToolBarComboBoxButton::AddItem | Adds an item to the end of the combo box list. |
CMFCToolBarComboBoxButton::AddSortedItem | Adds an item to the combo box list. The order of items in the list is specified by Compare . |
CMFCToolBarComboBoxButton::Compare | Compares two items. Called to sort items that AddSortedItems adds to the combo box list. |
CMFCToolBarComboBoxButton::CreateEdit | Creates a new edit control for the combo box button. |
CMFCToolBarComboBoxButton::DeleteItem | Deletes an item from the combo box list. |
CMFCToolBarComboBoxButton::FindItem | Returns the index of the item that contains a specified string. |
CMFCToolBarComboBoxButton::GetByCmd | Returns a pointer to the combo box button with a specified command ID. |
CMFCToolBarComboBoxButton::GetComboBox | Returns a pointer to the combo box control that is embedded in the combo box button. |
CMFCToolBarComboBoxButton::GetCount | Returns the number of items in the combo box list. |
CMFCToolBarComboBoxButton::GetCountAll | Finds the combo box button that has a specified command ID. Returns the number of items in the combo box list of that button. |
CMFCToolBarComboBoxButton::GetCurSel | Returns the index of the selected item in the combo box list. |
CMFCToolBarComboBoxButton::GetCurSelAll | Finds the combo box button that has a specified command ID, and returns the index of the selected item in the combo box list of that button. |
CMFCToolBarComboBoxButton::GetEditCtrl | Returns a pointer to the edit control that is embedded in the combo box button. |
CMFCToolBarComboBoxButton::GetItem | Returns the string that is associated with a specified index in the combo box list. |
CMFCToolBarComboBoxButton::GetItemAll | Finds the combo box button that has a specified command ID, and returns the string that is associated with an index in the combo box list of that button. |
CMFCToolBarComboBoxButton::GetItemData | Returns the 32-bit value that is associated with a specified index in the combo box list. |
CMFCToolBarComboBoxButton::GetItemDataAll | Finds the combo box button that has a specified command ID, and returns the 32-bit value that is associated with an index in the combo box list of that button. |
CMFCToolBarComboBoxButton::GetItemDataPtrAll | Finds the combo box button that has a specified command ID. Retrieves the 32-bit value that is associated an index in the combo box list of that button, and returns the 32-bit value as a pointer. |
CMFCToolBarComboBoxButton::GetText | Returns the text from the edit control of the combo box. |
CMFCToolBarComboBoxButton::GetTextAll | Finds the combo box button that has a specified command ID, and returns the text from edit control of that button. |
CMFCToolBarComboBoxButton::IsCenterVert | Determines whether combo box buttons in the application are centered or aligned with the top of the toolbar. |
CMFCToolBarComboBoxButton::IsFlatMode | Determines whether combo box buttons in the application have a flat appearance. |
CMFCToolBarComboBoxButton::RemoveAllItems | Removes all items from the list box and edit control of the combo box. |
CMFCToolBarComboBoxButton::SelectItem | Selects an item in the combo box according to its index, 32-bit value, or string, and notifies the combo box control about the selection. |
CMFCToolBarComboBoxButton::SelectItemAll | Finds the combo box button that has a specified command ID. Calls SelectItem to select an item in the combo box of that button according to its string, index, or 32-bit value. |
CMFCToolBarComboBoxButton::SetCenterVert | Specifies whether combo box buttons in the application are centered vertically or aligned with the top of the toolbar. |
CMFCToolBarComboBoxButton::SetDropDownHeight | Sets the height of the drop-down list box. |
CMFCToolBarComboBoxButton::SetFlatMode | Specifies whether combo box buttons in the application have a flat appearance. |
To add a combo box button to a toolbar, follow these steps:
Reserve a dummy resource ID for the button in the parent toolbar resource.
Construct a
CMFCToolBarComboBoxButton
object.In the message handler that processes the AFX_WM_RESETTOOLBAR message, replace the dummy button with the new combo box button by using CMFCToolBar::ReplaceButton.
For more information, see Walkthrough: Putting Controls On Toolbars. For an example of a combo box toolbar button, see the example project VisualStudioDemo.
The following example demonstrates how to use various methods in the CMFCToolBarComboBoxButton
class. The example shows how to enable the edit and combo boxes, set the vertical position of combo box buttons in the application, set the height of the list box when it is dropped down, set the flat style appearance of combo box buttons in the application, and set the text in the edit box of the combo box button. This code snippet is part of the Visual Studio Demo sample.
// CObList listButtons
// POSITION posCombo
CMFCToolBarComboBoxButton* pCombo = DYNAMIC_DOWNCAST(CMFCToolBarComboBoxButton, listButtons.GetNext(posCombo));
pCombo->EnableWindow(true);
pCombo->SetCenterVert();
pCombo->SetDropDownHeight(25);
pCombo->SetFlatMode();
pCombo->SetText(_T("this is a combo box"));
Header: afxtoolbarcomboboxbutton.h
Appends a unique item to the list box.
virtual INT_PTR AddItem(
LPCTSTR lpszItem,
DWORD_PTR dwData=0);
lpszItem
[in] The text of the item to add to the list box.
dwData
[in] The data associated with the item to add to the list box.
The index of the last item in the list box.
Do not use this method when the list box style is sorted.
If the item text is already in the list box, the new data is stored with the existing item. The search for the item is case sensitive.
Adds an item to the list box in the order that is defined by the Compare method.
virtual INT_PTR AddSortedItem(
LPCTSTR lpszItem,
DWORD_PTR dwData=0);
lpszItem
[in] The text of the item to add to the list box.
dwData
[in] The data associated with the item to add to the list box.
Index of the item that was added to the list box.
Use this function to add items to the list box in a specific order.
Indicates whether the combo box button size can change.
virtual BOOL CanBeStretched() const;
Returns TRUE.
Constructs a CMFCToolBarComboBoxButton object.
CMFCToolBarComboBoxButton(
UINT uiID,
int iImage,
DWORD dwStyle=CBS_DROPDOWNLIST,
int iWidth=0);
uiID
[in] The command ID of the new button.
iImage
[in] The image index of the image associated with the new button.
dwStyle
[in] The style of the new button.
iWidth
[in] The width, in pixels, of the new button.
The default width is 150 pixels.
For a list of toolbar button styles see ToolBar Control Styles
Deletes user-defined data.
virtual void ClearData();
By default this method does nothing. Override this method in a derived class if you want to delete any user-defined data.
Compares two strings.
virtual int Compare(
LPCTSTR lpszItem1,
LPCTSTR lpszItem2);
lpszItem1
[in] The first string to compare.
lpszItem2
[in] The second string to compare.
A value that indicates the case-sensitive lexicographic relationship between the strings. The following table lists the possible values:
Value | Description |
---|---|
<0 | The first string is less than the second. |
0 | The first string equals the second. |
>0 | The first string is greater than the second. |
Override this method to change how items are sorted in the list box.
The comparison is case-sensitive.
This method is called only from the AddSortedItem method.
Copies the state of the specified CMFCToolBarComboBoxButton
to the current object.
virtual void CopyFrom(const CMFCToolBarButton& src);
src
[in] The source CMFCToolBarComboBoxButton
object.
Creates a new combo box for the combo box button.
virtual CComboBox* CreateCombo(
CWnd* pWndParent,
const CRect& rect);
pWndParent
[in] A pointer to the parent window of the button.
rect
[in] Bounding rectangle of the combo box.
A pointer to the new combo box if the method was successful; otherwise, NULL.
Creates a new edit box for the combo box button.
virtual CMFCToolBarComboBoxEdit* CreateEdit(
CWnd* pWndParent,
const CRect& rect,
DWORD dwEditStyle);
pWndParent
[in] A pointer to the parent window of the button.
rect
[in] Bounding rectangle of the new edit box.
dwEditStyle
[in] Control style of the new edit box.
A pointer to the new edit box if the method was successful; otherwise, NULL.
The framework calls this method when it creates a new edit box for a combo box button. Override this method to change how CMFCToolBarComboBoxEdit is created.
Deletes a specified item from the list box.
BOOL DeleteItem(int iIndex);
BOOL DeleteItem(DWORD_PTR dwData);
BOOL DeleteItem(LPCTSTR lpszText);
iIndex
[in] The zero-based index of the item to be deleted.
dwData
[in] The data associated with the item to be deleted.
lpszText
[in] The text of the item to be deleted. If there are multiple items with the same text, the first item is deleted.
TRUE if the item was located and successfully deleted; otherwise, FALSE.
Duplicates user-defined data.
virtual void DuplicateData();
By default this method does nothing. Override this method in a derived class if you want to copy any user-defined data.
Enables or disables the edit and combo boxes.
virtual void EnableWindow(BOOL bEnable = TRUE);
bEnable
[in] TRUE to enable the edit and combo boxes; FALSE to disable the edit and combo boxes.
When disabled, the controls cannot become active and cannot accept user input.
Copies a string from the application string table to the specified menu using the combo box button command ID.
virtual BOOL ExportToMenuButton(CMFCToolBarMenuButton& menuButton) const;
menuButton
[out] Reference to a menu button.
Always TRUE.
Returns the index of the first item in the list box that contains a specified string.
int FindItem(LPCTSTR lpszText) const;
lpszText
[in] The text for which to search in the list box.
The index of the item; or CB_ERR if the item is not found.
Gets a pointer to the combo box button that has a specified command ID.
static CMFCToolBarComboBoxButton* GetByCmd(
UINT uiCmd,
BOOL bIsFocus=FALSE);
uiCmd
[in] The command ID of a combo box button.
bIsFocus
[in] TRUE to search only focused buttons; FALSE to search all buttons.
A pointer to a combo box button; or NULL if the button is not found.
Returns a pointer to the combo box in the combo box button.
CComboBox* GetComboBox() const;
A pointer to the CComboBox Class object if the method was successful; otherwise NULL.
Gets the shortcut menu resource ID for the combo box button.
UINT GetContextMenuID();
The shortcut menu resource ID.
Returns the number of items in the list box.
INT_PTR GetCount() const;
The number of items in the list box.
Gets the number of items in the list box of a combo box button that has a specified command ID.
static int GetCountAll(UINT uiCmd);
uiCmd
[in] The command ID of a combo box button.
The number of items in the list box; otherwise, CB_ERR if the combo box button is not found.
Gets the index of the currently selected item in the list box.
int GetCurSel() const;
The index of the currently selected item in the list box; or CB_ERR if no item is selected.
The list box index is zero-based.
Returns the index of the currently selected item in the list box of a combo box button that has a specified command ID.
static int GetCurSelAll(UINT uiCmd);
uiCmd
[in] The command ID of a combo box button.
The index of the currently selected item in the list box; otherwise, CB_ERR if no item is selected or a combo box button is not found.
The list box index is zero-based.
Returns a pointer to the edit box in the combo box button.
virtual CEdit* GetEditCtrl();
A pointer to the edit box if the method was successful; otherwise, NULL.
Returns the window handle for the combo box.
virtual HWND GetHwnd();
The window handle, or NULL if the combo box is not associated with a window object.
Returns the string associated with an item at a specified index in the list box.
LPCTSTR GetItem(int iIndex=-1) const;
iIndex
[in] Zero-based index of an item in the list box.
A pointer to the string that is associated with the item; otherwise, NULL if the index parameter is invalid, or if the index parameter is -1 and there is no selected item in the combo box.
An index parameter of -1 returns the string of the item that is currently selected.
Returns the string associated with an item at a specified index in the list box of a combo box button that has a specified command ID.
static LPCTSTR GetItemAll(
UINT uiCmd,
int iIndex=-1);
uiCmd
[in] The command ID of a combo box button.
iIndex
[in] The zero-based index of an item in the list box.
A pointer to the item's string if the method was successful; otherwise, NULL if the index is invalid, a combo box button is not found, or if index is -1 and there is no selected item in the combo box.
An index value of -1 returns the string of the item that is currently selected.
Returns the data associated with an item at a specific index in the list box.
DWORD_PTR GetItemData(int iIndex=-1) const;
iIndex
[in] The zero-based index of an item in the list box.
The data associated with the item; or 0 if the item does not exist.
An index parameter of -1 returns the data associated with the currently selected item.
Returns the data associated with an item at a specific index in the list box of a combo box button that has a specific command ID.
static DWORD_PTR GetItemDataAll(
UINT uiCmd,
int iIndex=-1);
uiCmd
[in] The command ID of a combo box button.
iIndex
[in] The zero-based index of an item in the list box.
The data associated with the item if the method was successful; otherwise, 0 if the specified index is not valid, or CB_ERR if the combo box button is not found.
An index parameter of -1 returns the data associated with the currently selected item.
Returns the data associated with an item at a specific index in the list box of a combo box button that has a specific command ID. This data is returned as a pointer.
static void* GetItemDataPtrAll(
UINT uiCmd,
int iIndex=-1);
uiCmd
[in] The command ID of the combo box button.
iIndex
[in] The zero-based index of an item in the list box.
A pointer associated with the item if the method was successful; otherwise, -1 if an error occurs, or NULL if the combo box button is not found.
Returns the prompt string for the combo box button.
virtual CString GetPrompt() const;
The prompt string.
This method is currently not implemented.
Gets the text in the edit box.
LPCTSTR GetText() const;
The text in the edit box.
Gets the text in the edit box of a combo box button that has a specified command ID.
static LPCTSTR GetTextAll(UINT uiCmd);
uiCmd
[in] The command ID of a specific combo box button.
The text in the edit box if the method was successful; otherwise, NULL.
Indicates whether the combo box currently has the focus.
virtual BOOL HasFocus() const;
TRUE if the combo box currently has the focus; otherwise, FALSE.
This method also returns TRUE if any child window of the combo box currently has the focus.
Returns the vertical position of combo box buttons in the application.
static BOOL IsCenterVert();
TRUE if the buttons are centered; FALSE if the buttons are aligned at the top.
Returns the flat style appearance of combo box buttons in the application.
static BOOL IsFlatMode();
TRUE if the buttons have a flat style; otherwise, FALSE.
The default flat style for combo box buttons is FALSE.
Indicates whether the specified handle is associated with the combo box button, or one of its children.
virtual BOOL IsOwnerOf(HWND hwnd);
hwnd
[in] A window handle.
TRUE if the handle is assocated with the combo box button, or one of its children; otherwise, FALSE.
Indicates whether the combo box button resides on a ribbon panel.
BOOL IsRibbonButton() const;
Always FALSE.
By default, this method always returns FALSE, which means the combo box button is never displayed on a ribbon panel.
Returns the visibility state of the combo box button.
virtual BOOL IsWindowVisible();
The visibility state of the combo box button.
Indicates whether the combo box button processes the message.
virtual BOOL NotifyCommand(int iNotifyCode);
iNotifyCode
[in] The notification message that is associated with the command.
Whether the combo box button processes the message.
Called by the framework when the button is added to the Customize dialog box.
virtual void OnAddToCustomizePage();
Called by the framework to calculate the size of the button.
virtual SIZE OnCalculateSize(
CDC* pDC,
const CSize& sizeDefault,
BOOL bHorz);
pDC
[in] The device context that displays the combo box button.
sizeDefault
[in] The default size of the combo box button.
bHorz
[in] The dock state of the parent toolbar. TRUE when the toolbar is docked horizontally and FALSE when the toolbar is docked vertically.
A SIZE
structure that contains the dimensions of the combo box button, in pixels.
Called by the framework when the combo box button is inserted into a new toolbar.
virtual void OnChangeParentWnd(CWnd* pWndParent);
pWndParent
[in] Pointer to the new parent toolbar.
Called by the framework when the user clicks the combo box button.
virtual BOOL OnClick(
CWnd* pWnd,
BOOL bDelay = TRUE);
pWnd
[in] Pointer to the parent window of the combo box button.
bDelay
[in] Reserved for use in a derived class.
TRUE if the method handles the event; otherwise, FALSE.
Called by the framework when the user changes the parent toolbar color to set the combo box button color.
virtual HBRUSH OnCtlColor(
CDC* pDC,
UINT nCtlColor);
pDC
[in] The device context that displays the combo box button.
nCtlColor
[in] Unused.
Handle to the brush that the framework uses to paint the background of the combo box button.
This method also sets the combo box button text color.
Called by the framework to draw the combo box button by using the specified styles and options.
virtual void OnDraw(
CDC* pDC,
const CRect& rect,
CMFCToolBarImages* pImages,
BOOL bHorz = TRUE,
BOOL bCustomizeMode = FALSE,
BOOL bHighlight = FALSE,
BOOL bDrawBorder = TRUE,
BOOL bGrayDisabledButtons = TRUE);
Pdc
[in] The device context that displays the button.
rect
[in] The bounding rectangle of the button.
pImages
[in] The collection of images that is associated with the button.
bHorz
[in] The dock state of the parent toolbar. TRUE when the toolbar is docked horizontally and FALSE when the toolbar is docked vertically.
bCustomizeMode
[in] Whether the application is in customization mode.
bHighlight
[in] Whether to draw the combo box button highlighted.
bDrawBorder
[in] Whether to draw the combo box button with a border.
bGrayDisabledButtons
[in] TRUE to draw shaded disabled buttons; FALSE to use the disabled images collection.
Called by the framework to draw the combo box button in the Commands pane of the Customize dialog box.
virtual int OnDrawOnCustomizeList(
CDC* pDC,
const CRect& rect,
BOOL bSelected);
pDC
[in] The device context that displays the combo box button.
rect
[in] The bounding rectangle of the combo box button.
bSelected
[in] TRUE if the combo box button is selected; otherwise, FALSE.
The width, in pixels, of the combo box button.
Called by the framework to set the combo box button font when the application font changes.
virtual void OnGlobalFontsChanged();
Called by the framework to change the location of the combo box button when the parent toolbar moves.
virtual void OnMove();
Called by the framework when the combo box button is hidden or displayed.
virtual void OnShow(BOOL bShow);
bShow
[in] Whether to hide or display the combo box button.
Called by the framework to change the size of the combo box button when the parent toolbar changes size.
virtual void OnSize(int iSize);
iSize
[in] The new width of the combo box button.
Called by the framework when the user changes the tool tip for the combo box button.
virtual BOOL OnUpdateToolTip(
CWnd* pWndParent,
int iButtonIndex,
CToolTipCtrl& wndToolTip,
CString& str);
pWndParent
[in] Pointer to the parent window for the combo box button.
iButtonIndex
[in] ID of the combo box button.
wndToolTip
[in] The tool tip to associate with the combo box button.
str
[in] The tool tip text.
TRUE if the method handles the event; otherwise, FALSE.
Deletes all items from the list and edit boxes.
void RemoveAllItems();
Removes all items from the list box and edit control of a combo box.
Selects an item in the list box.
BOOL SelectItem(
int iIndex,
BOOL bNotify=TRUE);
BOOL SelectItem(DWORD_PTR dwData);
BOOL SelectItem(LPCTSTR lpszText);
iIndex
[in] The zero-based index of an item in the list box.
bNotify
[in] TRUE to notify the combo box button of the selection; otherwise FALSE.
dwData
[in] The data associated with an item in the list box.
lpszText
[in] The text of an item in the list box.
TRUE if the method was successful; otherwise FALSE.
Selects an item in the list box of a combo box button that has a specified command ID.
static BOOL SelectItemAll(
UINT uiCmd,
int iIndex);
static BOOL SelectItemAll(
UINT uiCmd,
DWORD_PTR dwData);
static BOOL SelectItemAll(
UINT uiCmd,
LPCTSTR lpszText);
uiCmd
[in] The command ID of the combo box button that contains the list box.
iIndex
[in] The zero-based index of the item in the list box. A value of -1 removes any current selection in the list box and clears the edit box.
dwData
[in] The data of an item in the list box.
lpszText
[in] The text of an item in the list box.
TRUE if the method was successful; otherwise FALSE.
Reads this object from an archive or writes it to an archive.
virtual void Serialize(CArchive& ar);
ar
[in, out] The CArchive
object to serialize.
Settings in the CArchive
object determine whether this method reads or writes to the archive.
Populates the specified CAccessibilityData
object by using accessibility data from the combo box button.
virtual BOOL SetACCData(
CWnd* pParent,
CAccessibilityData& data);
pParent
[in] The parent window of the combo box button.
data
[out] A CAccessibilityData
object that receives the accessibility data from the combo box button.
TRUE if the method was successful; otherwise FALSE.
Sets the vertical position of combo box buttons in the application.
static void SetCenterVert(BOOL bCenterVert=TRUE);
bCenterVert
[in] TRUE to center the combo box button in the toolbar; FALSE to align the combo box button to the top of the toolbar.
By default, combo box buttons are aligned to the top.
Sets the shortcut menu resource ID for the combo box button.
void SetContextMenuID(UINT uiResID);
uiResID
[in] The shortcut menu resource ID.
Sets the height of the list box when it is dropped down.
void SetDropDownHeight(int nHeight);
nHeight
[in] The height, in pixels, of the list box.
The default height is 150 pixels.
Sets the flat style appearance of combo box buttons in the application.
static void SetFlatMode(BOOL bFlat=TRUE);
bFlat
[in] TRUE for a flat style appearance; otherwise FALSE.
The default flat style for combo box buttons is FALSE.
Sets the specified style for the combo box button and redraws the control if it is not disabled.
virtual void SetStyle(UINT nStyle);
nStyle
[in] A bitwise combination (OR) of toolbar styles.
For a list of toolbar button styles see ToolBar Control Styles
Sets the text in the edit box of the combo box button.
void SetText(LPCTSTR lpszText);
lpszText
[in] Pointer to a string that contains the text for the edit box.
Hierarchy Chart
Classes
CMFCToolBarButton Class
CComboBox Class
CMFCToolBar::ReplaceButton
Walkthrough: Putting Controls On Toolbars