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