MFC中并没有提供现成的CRadio类,其实对一组Radio进行操作的话,使用API函数CheckRadioButton即可。 BOOL CheckRadioButton( HWND hDlg, // handle to dialog box int nIDFirstButton, // identifier of first radio button in group int nIDLastButton, // identifier of last radio button in group int nIDCheckButton // identifier of radio button to select );
能否给出一个具体的例程?我想得到哪一个radio box被选中。
如果在程序中标识各radio box?帮助中所说的integer identifier是指什么?
如果你要获得哪一个按钮被选中,则需要用一个循环遍历这组Radio的ID,在循环中使用IsDlgButtonChecked函数。 int GetCheckedRadio(HWND hDlg, int nFirst, int nLast) { int nResult; for (int i = nFirst; i <= nLast; i++) if (BST_CHECKED == IsDlgButtonChecked(hDlg, i)) nResult = i; return nResult; }
BOOL CheckRadioButton( HWND hDlg, // handle to dialog box
int nIDFirstButton, // identifier of first radio button in group
int nIDLastButton, // identifier of last radio button in group
int nIDCheckButton // identifier of radio button to select
);
int GetCheckedRadio(HWND hDlg, int nFirst, int nLast)
{
int nResult;
for (int i = nFirst; i <= nLast; i++)
if (BST_CHECKED == IsDlgButtonChecked(hDlg, i))
nResult = i;
return nResult;
}