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. Comboboxx issue in MFC

Comboboxx issue in MFC

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++databasebusinessannouncement
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.
  • A Offline
    A Offline
    Amrit Agr
    wrote on last edited by
    #1

    I have a combobox in a mfc application. I created it at runtime with following code - if (!m_sortBox.Create(WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST, rect, this, eSortBox)) return FALSE; Now the requirements, if user is selecting an item from combobox like , if combo box have focus & user is pressing up/down arrow key, it should NOT update the data. If user is pressing enter key after selecting a item, it should update data. So i didn't handled OnSelchange here. For enter key requirement, I checked enter key event in preTranslateMsg & checking if combo box have focus, it should trigger the function, who will eventually update the data. if (pMsg->message == WM_CHAR && pMsg->wParam == VK_RETURN) { CWnd *pActiveWnd = CWnd::FromHandle(GetFocus()->GetSafeHwnd()); CWnd* pcbSortBoxWnd = CWnd::FromHandle(m_sortBox.GetSafeHwnd()); //If sort combo box has focus and user press Enter key, it should trigger OnComboSelChange event //Eventually it will update the data. if (pcbSortBoxWnd == pActiveWnd) OnSortChange(); } I also handled ON_CBN_CLOSEUP(eSortBox, OnSortChange) So that mouse functionality will work(because with mouse, data should get update) Now my logic is working but its crashing in some cases. Like - If I press Alt + Down arrow key, which will expand combobox, I select an item(with help of arrow keys) and press enter. Sometimes its getting crash. please help me out. Regards, Amrit Agrawal

    L 1 Reply Last reply
    0
    • A Amrit Agr

      I have a combobox in a mfc application. I created it at runtime with following code - if (!m_sortBox.Create(WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST, rect, this, eSortBox)) return FALSE; Now the requirements, if user is selecting an item from combobox like , if combo box have focus & user is pressing up/down arrow key, it should NOT update the data. If user is pressing enter key after selecting a item, it should update data. So i didn't handled OnSelchange here. For enter key requirement, I checked enter key event in preTranslateMsg & checking if combo box have focus, it should trigger the function, who will eventually update the data. if (pMsg->message == WM_CHAR && pMsg->wParam == VK_RETURN) { CWnd *pActiveWnd = CWnd::FromHandle(GetFocus()->GetSafeHwnd()); CWnd* pcbSortBoxWnd = CWnd::FromHandle(m_sortBox.GetSafeHwnd()); //If sort combo box has focus and user press Enter key, it should trigger OnComboSelChange event //Eventually it will update the data. if (pcbSortBoxWnd == pActiveWnd) OnSortChange(); } I also handled ON_CBN_CLOSEUP(eSortBox, OnSortChange) So that mouse functionality will work(because with mouse, data should get update) Now my logic is working but its crashing in some cases. Like - If I press Alt + Down arrow key, which will expand combobox, I select an item(with help of arrow keys) and press enter. Sometimes its getting crash. please help me out. Regards, Amrit Agrawal

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Amrit Agr wrote:

      Sometimes its getting crash

      Then you need to use your debugger to try and identify where the crash occurs, and why.

      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