locked
How can I handle many CComboBox Message in one handle? RRS feed

  • Question

  • Hi,
    I'm using a few CComboBox instances, on different CToolBars and I wanted to know if there is a way to catch all CComboBox messages on the same handle like for example you can do in toolbar case:
    ON_NOTIFY(TBN_DROPDOWN, AFX_IDW_TOOLBAR, OnToolbarDropDown)

    tnx
    Monday, October 9, 2006 8:48 AM

Answers

  • Combobox notifications (e.g. CBN_SELCHANGE) are sent through WM_COMMAND message. So you can override CWnd::OnCommand virtual function like in the next example.
    BOOL CMainFrame::OnCommand(WPARAM wParam, LPARAM lParam) 
    {
       WORD wNotify  = HIWORD(wParam); // notification message
       WORD wID      = LOWORD(wParam); // control identifier
       HWND hWndCtrl = (HWND)lParam;   // control handle
       
       switch(wNotify)
       {
       case CBN_SELCHANGE:
          // ....
          break;
          // ...
          
       }
       return CMDIFrameWnd::OnCommand(wParam, Param);
    }
    Although, IMO it's better to separately map each notification handler for each control. It's easier to handle, read and maintain.
    Monday, October 9, 2006 9:35 AM