Switch between drop-list and drop-down mode | CodeGuru

Switch between drop-list and drop-down mode

Environment: VC6, NT4 SP3. After reading the article written by Robert Cremer , I realized that his version doesn’t correctly draw the blue selection rectangle around the selected item within the combo box. Therefore, I took a different tack in the designing of my version of a class that allows you to programmatically switch a […]

Written By
CodeGuru Staff
CodeGuru Staff
Jul 25, 1999
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

Environment: VC6, NT4 SP3.

switch_list.jpg (5874 bytes)

switch_drop.jpg (4847 bytes)

After reading the article written by

Robert Cremer

, I realized that his
version doesn’t correctly draw the blue selection rectangle around the selected
item within the combo box. Therefore, I took a different tack in the designing of my version of a class that allows you to programmatically switch a combo box between “drop-list” and “drop-down” mode.

To do this, I create an edit control that simulates the child edit of a
real drop-down combo box. The included files have one CComboBox derived class with overrides on OnDropDown and OnCloseUp, and one CEdit derived class that takes care
of the up/down arrows used no navigate in the combobox.

The only (let’s say) tricky parts are:

  • Making the edit selectable by mouse. I used ::SetWindowPos to put in in the front of the combo in the Z-order
  • Making the combo selectable/not selectable by TAB. ModifyStyle(WS_TABSTOP,0) to remove, ModifyStyle(0,WS_TABSTOP) to add the combo to the tab order list.

Usage

In order to use this class, simply follow these steps:

  • In your dialog, add a drop-list combobox
  • Add a member variable to the dialog of the type CComboBox
  • Modify the dialog’s header file so that instead of the newly created
    combo box variable being declared as a CComboBox, it is declared as a CFineCombo.
  • Now, update your dialog’s code to include calls to
    SwitchToDrop(TRUE) (switches to drop-down) or SwitchToDrop(FALSE) (switches
    to drop-list) where appropriate.
  • Delete the ClassWizard (.clw) file.
  • Rebuild the ClassWizard file so that it contains the newly added CFineCombo class.

Downloads

Download demo project – 20 Kb
Download source – 3 Kb

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.