Checkbox/radio-style button in CDialogBar
Michael E. Kropp -- mkropp@imagesw1.MV.COM
Thursday, June 13, 1996
Environment: MSVC 4.1, Win95
My app has a dialog bar that contains, among many other things, some =
bitmap buttons that need to act like either radio buttons or checkboxes. =
This is relatively easy to do for button is toolbars but dialog bars =
seem to be a whole different case. How can this be done?
Mike Kropp
Image Software
Roger Onslow -- Roger_Onslow@compsys.com.au
Monday, June 17, 1996
[Mini-digest: 3 responses]
Mike,
>I found the solution. It seems that radio buttons now have the capability of
having a pushbutton-like style. I changed the appropriate buttons to radio
buttons and all >went smoothly. I found this while considering changing the
buttons to owner-draw radio buttons. Apparently MS did the work for me.
>
>Thanks for your suggestion. I was also considering something similar to that
as well.
Interesting lateral solution...
Don't make the buttons behave like radio buttons,
Make the radio buttons look like buttons!!
I thought you wanted them to be CBitmapButtons.
Does this solution allow you that flexibility??
Roger Onslow
-- Computer Systems Australia
-----From: "Michael E. Kropp"
I found the solution. It seems that radio buttons now have the =
capability of having a pushbutton-like style. I changed the appropriate =
buttons to radio buttons and all went smoothly. I found this while =
considering changing the buttons to owner-draw radio buttons. =
Apparently MS did the work for me.
Thanks for your suggestion. I was also considering something similar to =
that as well.
-- Mike Kropp
Image Software
-----From: Roger Onslow/Newcastle/Computer Systems Australia/AU
I had a look at Technical note TN031: (to do with updaing buttons
in a CDialogBar)
>>CCmdUI Support for CDialogBar
>>Dialog bar buttons should be updated through the
>>ON_UPDATE_COMMAND_UI handler mechanism. At idle time, the dialog
>>bar will call the ON_UPDATE_COMMAND_UI handler with the command
>>ID of all the buttons that have a ID >= 0x8000 (that is, in the
>>range of command IDs).
>>The ON_UPDATE_COMMAND_UI handler can call:
>> Enable: to enable or disable the button.
>> SetText: to change the text of the button.
>>
>>Customization can be done through standard window manager APIs.
hmmm... seems your're right -- cannot call SetCheck or SetRadio
An alternative that I use in my modeless property pages is
something like this:
class CMyPropertyPage : public CPropertyPage {
...
//{{AFX_DATA(CMyPropertyPage)
enum { IDD = IDD_MYPROPPAGE };
CBitmapButton m_OnRadio;
CBitmapButton m_OffRadio;
//}}AFX_DATA
...
};
void CMyPropertyPage::DoDataExchange(CDataExchange* pDX) {
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(QIDPenPropPage)
DDX_Control(pDX, IDC_ON, m_OnRadio);
DDX_Control(pDX, IDC_OFF, m_OffRadio);
//}}AFX_DATA_MAP
}
void CMyPropertyPage::UpdateButtons() {
BOOL bRadioIsOn = // whatever determines state
m_OnRadio.Check(bRadioIsOn);
m_OffRadio.Check(!bRadioIsOn);
}
I call UpdateButtons() whenever "whatever determines state" is
changed. Perhaps one can call UpdateButtons from within the
ON_UPDATE_COMMAND_UI handler, getting the best of both worlds
Hope this helps,
Roger Onslow
Senior Software Engineer
Computer Systems Australia
Ph: +61 49 577155
Fax: +61 49 675554
eMail: RogerO@compsys.com.au
(now WWW -- yet!)
Dan Opperman -- DOpperman@msn.com
Saturday, June 15, 1996
On the Radio Button Properties Style page in the dialog resource editor:
Check Push-like
Check Icon
Then load the icons when you initialize the dialog (of course, you'll want to
add some error checking):
BOOL CSomeDlg::OnInitDialog()
{
...
((Cbutton*)GetDlgItem(IDC_RADIO1))->SetIcon(AfxGetApp()->LoadIcon(IDI_SOMEICON
);
...
}
The push-like and icon properties are not supported in NT 3.51. If you don't
check the version you'll end up with nasty looking 2D controls (yuck!).
Also, icons have transparent parts so they tend to work better then bitmaps.
If you use the small icons (16x16) your buttons will look similar to tool bar
buttons. On the other hand, if you use bitmaps, you'll have to owner draw them
to get the correct background color, but these would work correctly in NT.
Hope this helps,
Daniel Opperman
----------
From: owner-mfc-l@netcom.com on behalf of Michael E. Kropp
Sent: Thursday, June 13, 1996 2:30 AM
To: 'mfc-l'
Subject: Checkbox/radio-style button in CDialogBar
Environment: MSVC 4.1, Win95
My app has a dialog bar that contains, among many other things, some =
bitmap buttons that need to act like either radio buttons or checkboxes. =
This is relatively easy to do for button is toolbars but dialog bars =
seem to be a whole different case. How can this be done?
Mike Kropp
Image Software
| Вернуться в корень Архива
|