Odd bug in CMFCToolbarComboBoxButton class
-
Hello, I am trying to use this control in a toolbar. For the most part the code works. However, I am running into this odd problem that I am getting partial text back when I call GetText. The app requires that when I click a different button in the toolbar, I check the combo box and retrieve the text from it for processing. That is when this bug surfaces. The last character is getting truncated. If I retrieve the text in response to the Enter key handler for the combo box, I get the full text using the same GetText call. Here is the code...most all of it is lifted from the samples. CObList listButtons; if (CMFCToolBar::GetCommandButtons(ID_EDT_FIND_NDC, listButtons) > 0) { for (POSITION posCombo = listButtons.GetHeadPosition(); pSrcCombo == NULL && posCombo != NULL; ) { CMFCToolBarComboBoxButton* pCombo = DYNAMIC_DOWNCAST(CMFCToolBarComboBoxButton, listButtons.GetNext(posCombo)); if (pCombo != NULL) pSrcCombo = pCombo; } } if (pSrcCombo != NULL) { ASSERT_VALID(pSrcCombo); LPCTSTR lpszSelItem = pSrcCombo->GetText(); ... } So if the combo box has the text '1234567890', I am getting back '123456789' in one case, and '1234567890' in another case, depending on whether I press the other button or press the Enter key. Has anyone encountered this, and can someone suggest a solution? Thanks for your time.
-
Hello, I am trying to use this control in a toolbar. For the most part the code works. However, I am running into this odd problem that I am getting partial text back when I call GetText. The app requires that when I click a different button in the toolbar, I check the combo box and retrieve the text from it for processing. That is when this bug surfaces. The last character is getting truncated. If I retrieve the text in response to the Enter key handler for the combo box, I get the full text using the same GetText call. Here is the code...most all of it is lifted from the samples. CObList listButtons; if (CMFCToolBar::GetCommandButtons(ID_EDT_FIND_NDC, listButtons) > 0) { for (POSITION posCombo = listButtons.GetHeadPosition(); pSrcCombo == NULL && posCombo != NULL; ) { CMFCToolBarComboBoxButton* pCombo = DYNAMIC_DOWNCAST(CMFCToolBarComboBoxButton, listButtons.GetNext(posCombo)); if (pCombo != NULL) pSrcCombo = pCombo; } } if (pSrcCombo != NULL) { ASSERT_VALID(pSrcCombo); LPCTSTR lpszSelItem = pSrcCombo->GetText(); ... } So if the combo box has the text '1234567890', I am getting back '123456789' in one case, and '1234567890' in another case, depending on whether I press the other button or press the Enter key. Has anyone encountered this, and can someone suggest a solution? Thanks for your time.
-
Hello, I am trying to use this control in a toolbar. For the most part the code works. However, I am running into this odd problem that I am getting partial text back when I call GetText. The app requires that when I click a different button in the toolbar, I check the combo box and retrieve the text from it for processing. That is when this bug surfaces. The last character is getting truncated. If I retrieve the text in response to the Enter key handler for the combo box, I get the full text using the same GetText call. Here is the code...most all of it is lifted from the samples. CObList listButtons; if (CMFCToolBar::GetCommandButtons(ID_EDT_FIND_NDC, listButtons) > 0) { for (POSITION posCombo = listButtons.GetHeadPosition(); pSrcCombo == NULL && posCombo != NULL; ) { CMFCToolBarComboBoxButton* pCombo = DYNAMIC_DOWNCAST(CMFCToolBarComboBoxButton, listButtons.GetNext(posCombo)); if (pCombo != NULL) pSrcCombo = pCombo; } } if (pSrcCombo != NULL) { ASSERT_VALID(pSrcCombo); LPCTSTR lpszSelItem = pSrcCombo->GetText(); ... } So if the combo box has the text '1234567890', I am getting back '123456789' in one case, and '1234567890' in another case, depending on whether I press the other button or press the Enter key. Has anyone encountered this, and can someone suggest a solution? Thanks for your time.
At least this works for me: In the Code, where a character is truncated replace the call to pSrcCombo->GetText() with something like this: CComboBox* a_pComboBox(pSrcCombo->GetComboBox()); ASSERT(a_pComboBox); CString a_strAddressTextInCombo; a_pComboBox->GetWindowText(a_strAddressTextInCombo); Maybe in your code you have to distinguish somehow where the call comes from... Or you could try if the above code works for both scenarios. Hope I could help, Patrik
-
I just encountered the same problem here! No solution so far. It is so frustrating to work with this feature pack...
Yes, I finally got frustrated enough to think up alternatives. I had already coded to find the CMFCToolbarComboBoxButton object (Code from MSDN actually), so now I went ahead and code along the following lines:
if (pSrcCombo != NULL) { ASSERT\_VALID(pSrcCombo); CMFCToolBarComboBoxEdit \*pEdit = (CMFCToolBarComboBoxEdit \*) pSrcCombo->GetEditCtrl(); if (pEdit) { CString strSelItem=\_T(""); pEdit->GetWindowText (strSelItem); pSrcCombo->AddItem (strSelItem); ... } }
Using the Edit Control seems to have solved the problem for me. At the MFCToolbarComboBoxButton level, there is no option for a fix that I have found. Perhaps subclassing the control and intercepting the GetText() call may work, but I have not tried it.
modified on Tuesday, October 20, 2009 4:07 PM
-
At least this works for me: In the Code, where a character is truncated replace the call to pSrcCombo->GetText() with something like this: CComboBox* a_pComboBox(pSrcCombo->GetComboBox()); ASSERT(a_pComboBox); CString a_strAddressTextInCombo; a_pComboBox->GetWindowText(a_strAddressTextInCombo); Maybe in your code you have to distinguish somehow where the call comes from... Or you could try if the above code works for both scenarios. Hope I could help, Patrik
Yes, a code sample in the MSDN website gives details on how to identify the control that you are using.
CMFCToolBarComboBoxButton\* pSrcCombo = NULL; CObList listButtons; if (CMFCToolBar::GetCommandButtons(ID\_EDT\_FIND\_NDC, listButtons) > 0) { for (POSITION posCombo = listButtons.GetHeadPosition(); pSrcCombo == NULL && posCombo != NULL;) { CMFCToolBarComboBoxButton\* pCombo = DYNAMIC\_DOWNCAST(CMFCToolBarComboBoxButton, listButtons.GetNext(posCombo)); if (pCombo != NULL && CMFCToolBar::IsLastCommandFromButton(pCombo)) { pSrcCombo = pCombo; } } }