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. MFC DDX_Radio causes debug assertion failure when DoDataExchange is called

MFC DDX_Radio causes debug assertion failure when DoDataExchange is called

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++debugging
8 Posts 4 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.
  • J Offline
    J Offline
    janaswamy uday
    wrote on last edited by
    #1

    Hi All, I am having Three Radio Buttons in a Dialog Based Application. The Name of the Radio Buttons are IDC_RADIO1,IDC_RADIO2 and IDC_RADIO3. I have Grouped the First Radio Button IDC_RADIO1. I have Disabled the First Radio Button which is Grouped. Now When I change the selection of First Radio Button to Second Radio Button I am getting Assertion. I have google and found that this a Microsoft Issue which is mentioned as same in this link. [Q114980: FIX: Disabled DDX Radio Button Causes Infinite Loop | KnowledgeBase Archive] https://jeffpar.github.io/kbarchive/kb/114/Q114980/ Let me know if any solutions regarding this. Thanks in Advance

    V J 2 Replies Last reply
    0
    • J janaswamy uday

      Hi All, I am having Three Radio Buttons in a Dialog Based Application. The Name of the Radio Buttons are IDC_RADIO1,IDC_RADIO2 and IDC_RADIO3. I have Grouped the First Radio Button IDC_RADIO1. I have Disabled the First Radio Button which is Grouped. Now When I change the selection of First Radio Button to Second Radio Button I am getting Assertion. I have google and found that this a Microsoft Issue which is mentioned as same in this link. [Q114980: FIX: Disabled DDX Radio Button Causes Infinite Loop | KnowledgeBase Archive] https://jeffpar.github.io/kbarchive/kb/114/Q114980/ Let me know if any solutions regarding this. Thanks in Advance

      V Offline
      V Offline
      Victor Nijegorodov
      wrote on last edited by
      #2

      janaswamy uday wrote:

      [Q114980: FIX: Disabled DDX Radio Button Causes Infinite Loop | KnowledgeBase Archive] https://jeffpar.github.io/kbarchive/kb/114/Q114980/ Let me know if any solutions regarding this.

      But it was very good written in the article you have mentioned!

      Quote:

      RESOLUTION ========== To work around this problem, do one of the following: - Arrange the group so that the first radio button is not disabled when any of the other controls in the group are enabled. -or- - Call EnableWindow() to enable the radio button before DDX_Radio() is called [for example, in DoDataExchange()]. -or- - Write your own DDX_Radio() replacement, as shown in the sample code in the "MORE INFORMATION" section, below. STATUS ====== Microsoft has confirmed this to be a problem in Microsoft Foundation Classes, versions 2.0 and 2.5. This problem was corrected in MFC version 3.0 MORE INFORMATION ================ One solution is to write your own DDX_Radio() replacement, which uses ::GetWindow() to iterate through all the controls on the dialog box until it encounters one with style "WS_GROUP" or a handle of "NULL". The following sample code is a substitute for DDX_Radio(): Sample Code ----------- // DDX_MyRadio(), which is a modified DDX_Radio(). // void AFXAPI DDX_MyRadio(CDataExchange* pDX, int nIDC, int& value) // must be first in a group of auto radio buttons { HWND hWndCtrl = pDX->PrepareCtrl(nIDC); ASSERT(::GetWindowLong(hWndCtrl, GWL_STYLE) & WS_GROUP); ASSERT(::SendMessage(hWndCtrl, WM_GETDLGCODE, 0, 0L) & DLGC_RADIOBUTTON); if( pDX->m_bSaveAndValidate ) value = -1; // value if none found // walk all children in group int iButton = 0; do { if( ::SendMessage(hWndCtrl, WM_GETDLGCODE, 0, 0L) & DLGC_RADIOBUTTON ) { // control in group is a radio button if( pDX->m_bSaveAndValidate ) { if( ::SendMessage(hWndCtrl, BM_GETCHECK, 0, 0L) != 0 ) { ASSERT(value == -1); // only set once value = iButton; } } else { // select button ::Se

      J 1 Reply Last reply
      0
      • V Victor Nijegorodov

        janaswamy uday wrote:

        [Q114980: FIX: Disabled DDX Radio Button Causes Infinite Loop | KnowledgeBase Archive] https://jeffpar.github.io/kbarchive/kb/114/Q114980/ Let me know if any solutions regarding this.

        But it was very good written in the article you have mentioned!

        Quote:

        RESOLUTION ========== To work around this problem, do one of the following: - Arrange the group so that the first radio button is not disabled when any of the other controls in the group are enabled. -or- - Call EnableWindow() to enable the radio button before DDX_Radio() is called [for example, in DoDataExchange()]. -or- - Write your own DDX_Radio() replacement, as shown in the sample code in the "MORE INFORMATION" section, below. STATUS ====== Microsoft has confirmed this to be a problem in Microsoft Foundation Classes, versions 2.0 and 2.5. This problem was corrected in MFC version 3.0 MORE INFORMATION ================ One solution is to write your own DDX_Radio() replacement, which uses ::GetWindow() to iterate through all the controls on the dialog box until it encounters one with style "WS_GROUP" or a handle of "NULL". The following sample code is a substitute for DDX_Radio(): Sample Code ----------- // DDX_MyRadio(), which is a modified DDX_Radio(). // void AFXAPI DDX_MyRadio(CDataExchange* pDX, int nIDC, int& value) // must be first in a group of auto radio buttons { HWND hWndCtrl = pDX->PrepareCtrl(nIDC); ASSERT(::GetWindowLong(hWndCtrl, GWL_STYLE) & WS_GROUP); ASSERT(::SendMessage(hWndCtrl, WM_GETDLGCODE, 0, 0L) & DLGC_RADIOBUTTON); if( pDX->m_bSaveAndValidate ) value = -1; // value if none found // walk all children in group int iButton = 0; do { if( ::SendMessage(hWndCtrl, WM_GETDLGCODE, 0, 0L) & DLGC_RADIOBUTTON ) { // control in group is a radio button if( pDX->m_bSaveAndValidate ) { if( ::SendMessage(hWndCtrl, BM_GETCHECK, 0, 0L) != 0 ) { ASSERT(value == -1); // only set once value = iButton; } } else { // select button ::Se

        J Offline
        J Offline
        janaswamy uday
        wrote on last edited by
        #3

        Hi I have worked but this is not working. My Requirement is to Disable the Group Radio button but still I am getting Assertion even after doing with //{{AFX_DATA_MAP(CMyDialog) DDX_MyRadio(pDX, IDC_RADIO1, m_iRadio); //}}AFX_DATA_MAP and the below Function // DDX_MyRadio(), which is a modified DDX_Radio(). // void AFXAPI DDX_MyRadio(CDataExchange* pDX, int nIDC, int& value) // must be first in a group of auto radio buttons { HWND hWndCtrl = pDX->PrepareCtrl(nIDC); ASSERT(::GetWindowLong(hWndCtrl, GWL_STYLE) & WS_GROUP); ASSERT(::SendMessage(hWndCtrl, WM_GETDLGCODE, 0, 0L) & DLGC_RADIOBUTTON); if( pDX->m_bSaveAndValidate ) value = -1; // value if none found // walk all children in group int iButton = 0; do { if( ::SendMessage(hWndCtrl, WM_GETDLGCODE, 0, 0L) & DLGC_RADIOBUTTON ) { // control in group is a radio button if( pDX->m_bSaveAndValidate ) { if( ::SendMessage(hWndCtrl, BM_GETCHECK, 0, 0L) != 0 ) { ASSERT(value == -1); // only set once value = iButton; } } else { // select button ::SendMessage( hWndCtrl, BM_SETCHECK, (iButton == value), 0L ); } iButton++; } else { TRACE( "Warning: skipping non-radio button in group.\n" ); } hWndCtrl = ::GetWindow( hWndCtrl, GW_HWNDNEXT ); } while(hWndCtrl!=NULL && !(GetWindowLong(hWndCtrl,GWL_STYLE)&WS_GROUP)); } Thanks

        V 1 Reply Last reply
        0
        • J janaswamy uday

          Hi I have worked but this is not working. My Requirement is to Disable the Group Radio button but still I am getting Assertion even after doing with //{{AFX_DATA_MAP(CMyDialog) DDX_MyRadio(pDX, IDC_RADIO1, m_iRadio); //}}AFX_DATA_MAP and the below Function // DDX_MyRadio(), which is a modified DDX_Radio(). // void AFXAPI DDX_MyRadio(CDataExchange* pDX, int nIDC, int& value) // must be first in a group of auto radio buttons { HWND hWndCtrl = pDX->PrepareCtrl(nIDC); ASSERT(::GetWindowLong(hWndCtrl, GWL_STYLE) & WS_GROUP); ASSERT(::SendMessage(hWndCtrl, WM_GETDLGCODE, 0, 0L) & DLGC_RADIOBUTTON); if( pDX->m_bSaveAndValidate ) value = -1; // value if none found // walk all children in group int iButton = 0; do { if( ::SendMessage(hWndCtrl, WM_GETDLGCODE, 0, 0L) & DLGC_RADIOBUTTON ) { // control in group is a radio button if( pDX->m_bSaveAndValidate ) { if( ::SendMessage(hWndCtrl, BM_GETCHECK, 0, 0L) != 0 ) { ASSERT(value == -1); // only set once value = iButton; } } else { // select button ::SendMessage( hWndCtrl, BM_SETCHECK, (iButton == value), 0L ); } iButton++; } else { TRACE( "Warning: skipping non-radio button in group.\n" ); } hWndCtrl = ::GetWindow( hWndCtrl, GW_HWNDNEXT ); } while(hWndCtrl!=NULL && !(GetWindowLong(hWndCtrl,GWL_STYLE)&WS_GROUP)); } Thanks

          V Offline
          V Offline
          Victor Nijegorodov
          wrote on last edited by
          #4

          Then try to use another "workaround"!

          J 1 Reply Last reply
          0
          • V Victor Nijegorodov

            Then try to use another "workaround"!

            J Offline
            J Offline
            janaswamy uday
            wrote on last edited by
            #5

            Hi Victor, Could you please let me know the possible solution. This is very Urgent requirement to me. Help me out please. Thanks

            Richard Andrew x64R 1 Reply Last reply
            0
            • J janaswamy uday

              Hi Victor, Could you please let me know the possible solution. This is very Urgent requirement to me. Help me out please. Thanks

              Richard Andrew x64R Offline
              Richard Andrew x64R Offline
              Richard Andrew x64
              wrote on last edited by
              #6

              Try one of the other workarounds.

              The difficult we do right away... ...the impossible takes slightly longer.

              1 Reply Last reply
              0
              • J janaswamy uday

                Hi All, I am having Three Radio Buttons in a Dialog Based Application. The Name of the Radio Buttons are IDC_RADIO1,IDC_RADIO2 and IDC_RADIO3. I have Grouped the First Radio Button IDC_RADIO1. I have Disabled the First Radio Button which is Grouped. Now When I change the selection of First Radio Button to Second Radio Button I am getting Assertion. I have google and found that this a Microsoft Issue which is mentioned as same in this link. [Q114980: FIX: Disabled DDX Radio Button Causes Infinite Loop | KnowledgeBase Archive] https://jeffpar.github.io/kbarchive/kb/114/Q114980/ Let me know if any solutions regarding this. Thanks in Advance

                J Offline
                J Offline
                Jochen Arndt
                wrote on last edited by
                #7

                There must be another reason for the assertion because you are very probable not using MFC 2.x shipped with the Microsoft C compiler versions 1.x:

                Last Modified: 07-MAY-2001


                The information in this article applies to:

                • The Microsoft Foundation Classes (MFC), used with:
                  • Microsoft Visual C++ for Windows, 16-bit edition, versions 1.0, 1.5
                  • Microsoft Visual C++, 32-bit Editions, version 1.0

                Quote:

                Now When I change the selection of First Radio Button to Second Radio Button I am getting Assertion

                How do you change the selection? Where does the assertion occur (MFC source file name, line, and in which function)? Anyway, a radio button group is intended to have exactly one member checked. When activating a button, all other buttons will be unchecked. But a disabled button can't be checked or unchecked. If you need to disable a radio button, you must first ensure that it is not checked (usually by checking another button of the group). The same applies when disabling a button in the template: It must not be set to checked.

                J 1 Reply Last reply
                0
                • J Jochen Arndt

                  There must be another reason for the assertion because you are very probable not using MFC 2.x shipped with the Microsoft C compiler versions 1.x:

                  Last Modified: 07-MAY-2001


                  The information in this article applies to:

                  • The Microsoft Foundation Classes (MFC), used with:
                    • Microsoft Visual C++ for Windows, 16-bit edition, versions 1.0, 1.5
                    • Microsoft Visual C++, 32-bit Editions, version 1.0

                  Quote:

                  Now When I change the selection of First Radio Button to Second Radio Button I am getting Assertion

                  How do you change the selection? Where does the assertion occur (MFC source file name, line, and in which function)? Anyway, a radio button group is intended to have exactly one member checked. When activating a button, all other buttons will be unchecked. But a disabled button can't be checked or unchecked. If you need to disable a radio button, you must first ensure that it is not checked (usually by checking another button of the group). The same applies when disabling a button in the template: It must not be set to checked.

                  J Offline
                  J Offline
                  janaswamy uday
                  wrote on last edited by
                  #8

                  Hi Jochen Arndt, Thank you very much for your support. I got it now and I am not getting any assertion after "you must first ensure that it is not checked (usually by checking another button of the group)." Thank you very much once again.

                  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