Switch between drop-list and drop-down mode

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


Comments

  • highlight the characters in Drop down mode

    Posted by Legacy on 08/12/1999 12:00am

    Originally posted by: Ian

    Hi Bruno,

    Your program is really helpful to me. Thanks.

    I'd like to highlight the characters (set by SetWindowText(str)) right away after switching to Drop down mode. However I couldn't fig it out after spending several hours. Your help will be much appreciated.

    Ian

    Reply
  • no CBN_SELCHANGE message?

    Posted by Legacy on 08/06/1999 12:00am

    Originally posted by: Thomas Scherer

    Hey Bruno
    
    if the "CFineEdit" is active, the "parent dialog window" will be not notified about selection changing with "up/down key". I changed your code like this..

    void CFineEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
    {
    ..
    switch( .. ) {
    case DOWNARROW and UPARROW:
    ..
    GetParent()->SendMessage(WM_COMMAND,
    MAKEWPARAM(m_combo->GetDlgCtrlID(), CBN_SELCHANGE),
    (LPARAM)m_combo->m_hWnd);
    break;
    }
    ..
    }

    Insert the "SendMessage.." line at both locations (Down / Up) and the user will be notified!

    Thomas Scherer

    Reply
  • How to rebuild CLW file?

    Posted by Legacy on 07/28/1999 12:00am

    Originally posted by: Tom Stepka

    Exactly how does one go about rebuilding a deleted CLW file?

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • With the average hard drive now averaging one terabyte in size, the fallout from the explosion of user-created data has become an overwhelming volume of potential evidence that law-enforcement and corporate investigators spend countless hours examining. Join Us and SANS' Rob Lee for our 45-minute webinar, A Triage and Collection Strategy for Time-Sensitive Investigations, will demonstrate how to: Identify the folders and files that often contain key insights Reduce the time spent sifting through content by …

Most Popular Programming Stories

More for Developers

RSS Feeds