15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Initializing a combo box and a radio button?

Jeff Wishnie -- jwishnie@swellsoft.com
Thursday, April 04, 1996

Config: Win95, MFC/VisC++ 4.1

This seems very straightforward to me, but obviously I am missing some gotcha.

Here's the situation--I have a dialog (a CPropertyPage to be specific) which
contains two radio-buttons (in a group) and two Combo boxes:

----------------------------
|                          |
| O Button-1      Combo-1  |
|                          |
| O Button-2      Combo-2  |
|                          |
----------------------------

The behavior I want is that when Button-1 is selected, Combo-1 is enabled
and Combo-2 is diabled and vice-versa.

I know how to receive the click-events to set the enabling/disabling. What I
can't get to work is the initialization. That is, when the property page
opens, neither radio button is checked and nothing is displayed in the combo
boxes (which have been filled with data in DevStudio).

My on init dialog is as follows:

// CButton mButton1, mButton2;
// CComboBox mCombo1, mCombo2;

BOOL CMyPropertyPage::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();

	mButton1.SetCheck(1); // set the first button checked
	mCombo1.SetCurSel(0); // set the combo box to display the first item on the
list
        mCombo2.EnableWindow(FALSE); // disable Combo 2 
	return TRUE;  
}

Why doesn't this work? Why don't the radio buttons and combo boxes display
anything?

It seems so straightforward...

Thanks for any help!

- Jeff
jwishnie@swellsoft.com
415 552-3125(w)




Marty Fried -- mfried@linex.com
Friday, April 05, 1996

[Mini-digest: 3 responses]

At 07:37 PM 4/4/96 -0800, Jeff Wishnie wrote:
>Config: Win95, MFC/VisC++ 4.1
>
>This seems very straightforward to me, but obviously I am missing some gotcha.
>
>Here's the situation--I have a dialog (a CPropertyPage to be specific) which
>contains two radio-buttons (in a group) and two Combo boxes:
>
>The behavior I want is that when Button-1 is selected, Combo-1 is enabled
>and Combo-2 is diabled and vice-versa.
>
>My on init dialog is as follows:
>
>// CButton mButton1, mButton2;
>// CComboBox mCombo1, mCombo2;
>
>BOOL CMyPropertyPage::OnInitDialog() 
>{
>	CPropertyPage::OnInitDialog();
>
>	mButton1.SetCheck(1); // set the first button checked
>	mCombo1.SetCurSel(0); // set the combo box to display the first item on the
>list
>        mCombo2.EnableWindow(FALSE); // disable Combo 2 
>	return TRUE;  
>}

You need to do an UpdateData(FALSE) after setting the variables to update the
controls with this new data.  This is done automatically by the default
OnInitDialog, but you can't access any window handles before this call, so
you will need to do it yourself.

The same holds for OnOK handler, but in reverse.  The default handler calls
UpdateData(TRUE), so if you need to access any data before calling the default,
you need to call it yourself.
________________________________
 Marty Fried (mfried@linex.com)
 Marin County, California


-----From: LeRoy Baxter 

I think there may be something left out here.  If you are attaching variables
to the controls via DDX/DDV (ie. in the Class Wizard), then you don't want
to do the SetCheck() - you just need to set the variable attached to the
radiobutton(s) - and the combobox.EnableWindow()  should work.
I you are not attaching as above, then you probably need to subclass, or
to use more direct access - such as GetDlgItem(IDC_COMBO1)->EnableWindow()
-----From: marksi@eskimo.com (Mark Simonton)

Have you tried GetDlgItem(ID) to get a pointer to the item and then set the
check?  It's sort of SDKish, but it works.  there might also be a way to do
this with DDX, but I'm not up to writing one of these, not without lots of
reading and searching the MSDN-CD (a very valuable resource).



Barry Tannenbaum -- barry@dddv.com
Saturday, April 06, 1996

At 07:37 PM 4/4/96 -0800, you wrote:
>Config: Win95, MFC/VisC++ 4.1
>
>This seems very straightforward to me, but obviously I am missing some gotcha.
>
>Here's the situation--I have a dialog (a CPropertyPage to be specific) which
>contains two radio-buttons (in a group) and two Combo boxes:
>
>----------------------------
>|                          |
>| O Button-1      Combo-1  |
>|                          |
>| O Button-2      Combo-2  |
>|                          |
>----------------------------
>
>The behavior I want is that when Button-1 is selected, Combo-1 is enabled
>and Combo-2 is diabled and vice-versa.
>
>I know how to receive the click-events to set the enabling/disabling. What I
>can't get to work is the initialization. That is, when the property page
>opens, neither radio button is checked and nothing is displayed in the combo
>boxes (which have been filled with data in DevStudio).
>
>My on init dialog is as follows:
>
>// CButton mButton1, mButton2;
>// CComboBox mCombo1, mCombo2;
>
>BOOL CMyPropertyPage::OnInitDialog() 
>{
>	CPropertyPage::OnInitDialog();
>
>	mButton1.SetCheck(1); // set the first button checked
>	mCombo1.SetCurSel(0); // set the combo box to display the first item on the
>list
>        mCombo2.EnableWindow(FALSE); // disable Combo 2 
>	return TRUE;  
>}
>
>Why doesn't this work? Why don't the radio buttons and combo boxes display
>anything?

Your first problem is that you should be using CheckRadioButton to select
among the radio buttons in your group.

The second is that you won't get a call to your OnChecked routine.  Your
OnInitDialog routine has to call it directly.

        - Barry

--------------------------------------------------------------------------------

3DV Technology, Inc              Phone: (603) 595-2200, X228
410 Amherst St., Suite 150       Fax:   (603) 595-2228
Nashua, NH  03063                Net:   barry@dddv.com





| Вернуться в корень Архива |