Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Proper implementation of ComboBox

Proper implementation of ComboBox

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++announcement
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    Xian
    wrote on last edited by
    #1

    MFC - Ok I have a combobox (m_cFilters) and in it I have Filters like: All Files (*.*) Text Files (*.tx) ...etc. I want to grab the part between the parenthesis and store it in a var after the combo box is changed (DropDown combo, btw). I tried mapping the standard combo messages but after the functions return they do not update the combo box. What is the proper way to get the effect I am looking for? Is there an easier way to grab data like this other than straight from the combo string? Thanks. ---- Xian

    B 1 Reply Last reply
    0
    • X Xian

      MFC - Ok I have a combobox (m_cFilters) and in it I have Filters like: All Files (*.*) Text Files (*.tx) ...etc. I want to grab the part between the parenthesis and store it in a var after the combo box is changed (DropDown combo, btw). I tried mapping the standard combo messages but after the functions return they do not update the combo box. What is the proper way to get the effect I am looking for? Is there an easier way to grab data like this other than straight from the combo string? Thanks. ---- Xian

      B Offline
      B Offline
      Brendan Tregear
      wrote on last edited by
      #2

      I haven't done much work with combo box controls, but I had a similar situation with a list control where i needed to store extra data besides what is displayed. I think you can use the CComboBoxEx object which use the COMBOEXITEM structure instead of LVITEM. You can store a pointer to a filter string (or a pointer to a structure if you need to store more) typedef struct { TCHAR szFilter[256]; //eg "*.* } FILTERDATA, *PFILTERDATA; Then just add the structure when adding your items, for list control: PFILTERDATA pData = new FILTERDATA; strcpy(pData->szFilter, szMyFilter); COMBOEXITEM item; memset(&item, 0, sizeof(item)); item.mask = CBEIF_LPARAm | CBEIF_TEXT; item.lparam = (LPARAM) pData; item.iItem = -1; item.pszText = new TCHAR[sizeof(szMyDisplay)]; item.cchText = sizeof(szMyDisplay); nItem = m_cFilters.InsertItem(0, &item); Then when your user selects something do: COMBOEXITEM cbi; ZeroMemory(&cbi, sizeof(COMBOEXITEM)); cbi.iItem = hitTest.iItem; cbi.mask = CBEIF_PARAM; m_cFilters.GetItem(&cbi); PFILTERDATA pTemp = cbi.lParam; CString strTemp; strTemp.Format("Filter is %s", pTemp->szFilter); or maybe there's an easier way :) btw don't forget to delete the lparam pointer. probably best to subclass the entire control so you can delete the memory in teh destructor

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups