Thread: Combo box / subclassing issues

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    161

    Combo box / subclassing issues

    I've got 2 problems right now.

    1. I'm trying to figure out how to catch the CBN_SELCHANGE or CB_SETCURSEL message, but I'm not having any luck. What message goes to the combobox procedure when the selection is changed?

    2. Doesn't the combobox control have the ability to scroll vertically if it needs to? MSDN implies that it can in the description for CBS_DISABLENOSCROLL .

    Code:
    CONTROL "",CMB_CS_SEARCH_TYPE,"ComboBox",WS_CHILD|WS_VISIBLE|WS_TABSTOP|CBS_HASSTRINGS|CBS_DROPDOWNLIST,18,64,189,50
    Last edited by Viper187; 09-08-2008 at 02:01 PM.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> What message goes to the combobox procedure when the selection is changed?
    WM_COMMAND's go to the parent, not the control itself. The parent will have to "reflect" the messages back to the control - if you want the control to handle them.

    gg

  3. #3
    Registered User
    Join Date
    Jun 2008
    Posts
    161
    Ok. so why the hell won't it scroll vertically?

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    You will just get a typical WM_VSCROLL if I am not mistaken. Though it may be something else that is similar. Remember, the whole idea behind a WM_COMMAND message is to let a parent know that someone was accessing a child. Not the other way around. When subclassing you are basically going to control if and when you send a WM_COMMAND, not intercept it outright.

  5. #5
    Registered User
    Join Date
    Jun 2008
    Posts
    161
    How am I supposed to handle a WM_VSCROLL for a combobox? Listboxes/Listviews scroll automatically, don't they?

  6. #6
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    if you specify WS_VSCROLL or WS_HSCROLL (i think it's those, might want to double check the exact name) it will have a scroll bar automatically be enabled when it needs to be. Here is a snippet i used when i wanted to get the selection change from a combobox, drop down list to be exact.

    Code:
    case WM_COMMAND:
            switch(LOWORD(wParam))
            {
               case CONSEL: //Con-Selection ID
                //gets the selection from the dropdown box
                int ConSel = SendDlgItemMessage(hwnd,CONSEL,CB_GETCURSEL,0,0);
    
                //desides where to send the message depending on selection
                if(ConSel == 0){
                   //do stuff
                }
    
                if(ConSel == 1){
    
                }
    
                if(ConSel == 2){
    
                }
    
                if(ConSel == 3){
    
                }
                break;
            }
            break;

  7. #7
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Quote Originally Posted by Viper187 View Post
    How am I supposed to handle a WM_VSCROLL for a combobox? Listboxes/Listviews scroll automatically, don't they?
    You are subclassing the control, you can intercept its WM_* messages with your subclass. I think there is a custom message for scrolling in a combo-box now that I really think about it. Since the scroll bar within a combobox is actually a child window within the control. Either way, the WIN32 API still lets you intercept these messages.

  8. #8
    Registered User
    Join Date
    Jun 2008
    Posts
    161
    Quote Originally Posted by scwizzo View Post
    if you specify WS_VSCROLL or WS_HSCROLL (i think it's those, might want to double check the exact name) it will have a scroll bar automatically be enabled when it needs to be.
    AH! Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Create new combo boxes based on items selected in preview combo box
    By RealityFusion in forum Windows Programming
    Replies: 2
    Last Post: 01-10-2007, 09:50 AM
  2. No data showing in combo box
    By PJYelton in forum Windows Programming
    Replies: 6
    Last Post: 04-29-2005, 07:20 PM
  3. How to program a "back" button with MFC
    By 99atlantic in forum Windows Programming
    Replies: 3
    Last Post: 04-26-2005, 08:34 PM
  4. New Theme
    By XSquared in forum A Brief History of Cprogramming.com
    Replies: 160
    Last Post: 04-01-2004, 08:00 PM
  5. SkyLock tech demo (GUI - DX combo box)
    By jdinger in forum Game Programming
    Replies: 4
    Last Post: 07-14-2002, 09:04 PM