MFC DDX_Radio causes debug assertion failure when DoDataExchange is called
-
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
-
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
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
-
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
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
-
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
Then try to use another "workaround"!
-
Then try to use another "workaround"!
Hi Victor, Could you please let me know the possible solution. This is very Urgent requirement to me. Help me out please. Thanks
-
Hi Victor, Could you please let me know the possible solution. This is very Urgent requirement to me. Help me out please. Thanks
Try one of the other workarounds.
The difficult we do right away... ...the impossible takes slightly longer.
-
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
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.
- The Microsoft Foundation Classes (MFC), used with:
-
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.
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.
- The Microsoft Foundation Classes (MFC), used with: