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. Odd bug in CMFCToolbarComboBoxButton class

Odd bug in CMFCToolbarComboBoxButton class

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
5 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.
  • S Offline
    S Offline
    Santanu Lahiri
    wrote on last edited by
    #1

    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.

    P 2 Replies Last reply
    0
    • S Santanu Lahiri

      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.

      P Offline
      P Offline
      PatrikE
      wrote on last edited by
      #2

      I just encountered the same problem here! No solution so far. It is so frustrating to work with this feature pack...

      S 1 Reply Last reply
      0
      • S Santanu Lahiri

        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.

        P Offline
        P Offline
        PatrikE
        wrote on last edited by
        #3

        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

        S 1 Reply Last reply
        0
        • P PatrikE

          I just encountered the same problem here! No solution so far. It is so frustrating to work with this feature pack...

          S Offline
          S Offline
          Santanu Lahiri
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • P PatrikE

            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

            S Offline
            S Offline
            Santanu Lahiri
            wrote on last edited by
            #5

            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;
            		}
            	}
            }
            
            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