void CMyOptsDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Radio(pDX, IDC_RADIO1, m_eRdoGrpFrab); // <<--- Note
DDX_Text(pDX, IDC_EDIT3, m_sLogFile);
}
You now have a member variable named m_eRdoGrpFrab that can be set to 0, 1, or 2 (Standard, Partial, or Custom). When you run the dialog, you'll simply set it like so:
CMyOptsDlg dlg;
dlg.m_eRdoGrpFrab= 0; // or 0,1, or 2
int nResp= dlg.DoModal();
if (nResp == IDOK) {
... etc...
And when the dialog is closed, that variable will be set with the new, user-selected value (0, 1, or 2).
//int m_eRdoGrpFrab; // the Wizard added this... change to:
typedef enum { FrabStd=0, FrabPartial=1, FrabCustom=2 } FrabOpts;
FrabOpts m_eRdoGrpFrab;
...and change the DDX_Radio line in DoDataExchange() to:
DDX_Radio(pDX, IDC_RADIO1, (int&)m_eRdoGrpFrab); // <<--- Note (int&) cast
Now you can use code like:
dlg.m_eRdoGrpFrab= CMyOptsDlg::FrabPartial;
...
if (dlg.m_eRdoGrpFrab==CMyOptsDlg::FrabCustom ) {
...
void CMyOptsDlg::OnBnClickedRadio1(){ DoEnabling(); }
void CMyOptsDlg::OnBnClickedRadio2(){ DoEnabling(); }
void CMyOptsDlg::OnBnClickedRadio3(){ DoEnabling(); }
I long-ago wrote a function that would let me easily disable (and enable) a sequential range of dialog controls. Here's that code, along with the code for DoEnabling:
//--------------------- Utilities for disabling a range of dialog items (labels and controls)
void EnableDlgItm( CDialog* pDlg, int nId, BOOL fEnable/*=TRUE*/ )
{
CWnd* pwnd= pDlg->GetDlgItem( nId );
if (pwnd ) {
pwnd->EnableWindow( fEnable );
}
}
void EnableDlgItmRange( CDialog* pDlg, int nIdFirst/*=-1*/, int nIdLast/*=-1*/, BOOL fEnable/*=TRUE*/ )
{
CWnd* pwnd;
if ( nIdFirst == -1 ) { // IDC_STATIC
pwnd= pDlg->GetWindow( GW_CHILD ); // first Child
nIdFirst= pwnd->GetDlgCtrlID();
}
pwnd= pDlg->GetDlgItem( nIdFirst );
while ( pwnd ) {
pwnd->EnableWindow( fEnable );
pwnd= pwnd->GetWindow( GW_HWNDNEXT );
if ( pwnd ) pwnd->EnableWindow( fEnable );
if ((nIdLast != -1) && (pwnd && pwnd->GetDlgCtrlID() == nIdLast)) {
break;
}
}
}
//--------------------------- Using this in the dialog
void CMyOptsDlg::DoEnabling()
{
UpdateData(TRUE); //--- find out what's been selected
//----------------------------- disable some items when "Custom" is not selected
BOOL fEnab= (m_eRdoGrpFrab == FrabCustom);
EnableDlgItmRange( this, IDC_LblCustomStart, IDC_LblCustomEnd, fEnab );
}
And one last thing:
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)