Detecting a change in ComboBox.

This is a discussion on Detecting a change in ComboBox. within the Windows Programming forums, part of the Platform Specific Boards category; How can I detect a change in the ComboBox? For example: so when the first option of the combobox (index=0) ...

  1. #1
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768

    Detecting a change in ComboBox.

    How can I detect a change in the ComboBox?

    For example: so when the first option of the combobox (index=0) is selected, I could disable some other control.

    I would like to do that in simple API, without any MFC.


    Thank you.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  2. #2
    Grammar Police HybridM's Avatar
    Join Date
    Jan 2003
    Posts
    355
    The combobox will send you a notification message:
    Code:
    	case WM_COMMAND:
    		{
    			switch(HIWORD(wParam))
    			{
    			case CBN_CLOSEUP:
    				switch(LOWORD(wParam))
    				{
    				case IDC_SAMPFREQ2:
    					ChangeAvailableBitrates(hBitrates, false);
    				}
    			}
    This is from a program I am currently working on. It will launch the function ChangeAvailableBitrates() when the combo box IDC_SAMPFREQ2 has been closed (i.e. the user made a new selection).
    Thor's self help tip:
    Maybe a neighbor is tossing leaf clippings on your lawn, looking at your woman, or harboring desires regarding your longboat. You enslave his children, set his house on fire. He shall not bother you again.

    OS: Windows XP
    Compiler: MSVC

  3. #3
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    so when a user closed the combobox, he probably made a new selection, so then I will read the combobox, and know what to do...

    But I could just do:
    Code:
    if ((LOWORD(wParam)==ID_MY_COMBO)&&(HIWORD(wParam)==CBN_CLOSEUP))
       /*  do something  */
    Thanks man.
    Last edited by Devil Panther; 01-17-2004 at 07:04 AM.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  4. #4
    Grammar Police HybridM's Avatar
    Join Date
    Jan 2003
    Posts
    355
    yeah just send the something like the CB_GETCURSEL message, which will return the zero-based index of the item currently selected, then do your thang.
    Thor's self help tip:
    Maybe a neighbor is tossing leaf clippings on your lawn, looking at your woman, or harboring desires regarding your longboat. You enslave his children, set his house on fire. He shall not bother you again.

    OS: Windows XP
    Compiler: MSVC

  5. #5
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    Thanks a million
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  6. #6
    Grammar Police HybridM's Avatar
    Join Date
    Jan 2003
    Posts
    355
    No probs.
    Thor's self help tip:
    Maybe a neighbor is tossing leaf clippings on your lawn, looking at your woman, or harboring desires regarding your longboat. You enslave his children, set his house on fire. He shall not bother you again.

    OS: Windows XP
    Compiler: MSVC

  7. #7
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    Just one more thing...

    How did you know it's a HIWORD(wParam)...
    Because I just looked up the CBN_CLOSEUP in the msdn, and it didn't say anything about hiword.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  8. #8
    Grammar Police HybridM's Avatar
    Join Date
    Jan 2003
    Posts
    355
    Code:
    CBN_CLOSEUP  
    idComboBox = (int) LOWORD(wParam);  // identifier of combo box 
    hwndComboBox = (HWND) lParam;       // handle of combo box
    but
    Code:
    WM_COMMAND  
    wNotifyCode = HIWORD(wParam); // notification code 
    wID = LOWORD(wParam);         // item, control, or accelerator identifier 
    hwndCtl = (HWND) lParam;      // handle of control
    CBN_CLOSEUP is a notification message so it is in the high word of the wParam of WM_COMMAND.
    Thor's self help tip:
    Maybe a neighbor is tossing leaf clippings on your lawn, looking at your woman, or harboring desires regarding your longboat. You enslave his children, set his house on fire. He shall not bother you again.

    OS: Windows XP
    Compiler: MSVC

  9. #9
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    always the same structure... LOWORD is CONTROL ID
    and HIWORD is notification.

    Thanks for making it clear to me.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  10. #10
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,650
    Here is the entire reference for Combo Boxes (if you aren't already using it).

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. c++builder6 change form names problem
    By Leite33 in forum C++ Programming
    Replies: 2
    Last Post: 06-09-2008, 08:20 AM
  2. how to change static char* and not lose mem ?
    By jabka in forum C Programming
    Replies: 15
    Last Post: 09-07-2007, 05:33 PM
  3. Change Value in an array
    By beginner999 in forum C Programming
    Replies: 3
    Last Post: 01-18-2003, 06:16 AM
  4. Replies: 2
    Last Post: 11-08-2002, 02:22 AM
  5. Replies: 2
    Last Post: 09-04-2001, 02:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21