typedef unsigned int UINT;
表明是否按下各种键的状态标志。UINT类型在WINDOWS API中有定义,它对应于32位无符号整数。
void CEx_ResearchDlg::OnOk()
{
// TODO: Add your control notification handler code here
CString str,strCtrl;
str="你的年龄:";
UINT nID=GetCheckedRadioButton(IDC_AGE_1,IDC_AGE_4);
GetDlgItemText(nID,strCtrl);
str=str+strCtrl;
//获取第二个问题的用户选择
str=str+"\n你使用的接入方式:";
nID=GetCheckedRadioButton(IDC_CNT_1,IDC_CNT_4);
GetDlgItemText(nID,strCtrl);
str=str+strCtrl;
//获取第三个问题的用户选择
str=str+"\n你上网主要是:\n";
UINT nCheckIDs[4]={IDC_NET_1,IDC_NET_2,IDC_NET_3,IDC_NET_4};
CButton*pBtn;
for(int i=0;i<4;i++)
{
pBtn=(CButton*)GetDlgItem(nCheckIDs[i]);
if(pBtn->GetCheck())
{
pBtn->GetWindowText(strCtrl);
str=str+strCtrl;
str=str+" ";
}
}
MessageBox(str);
CDialog::OnOK();
}
GetDlgItemText(nID,strCtrl);(作用:获取对话框中指定控件的窗口文本。在单选按钮和复选按钮中,控件的窗口文本指的是他们的标题属性内容)第一个参数表示:制定控件标识;第二个是返回窗口文本
GetWindowText(strCtrl);
函数功能:该函数将指定窗口的标题条文本(如果存在)拷贝到一个缓存区内。如果指定的窗口是一个控制,则拷贝控制的文本。但是,GetWindowTeXt不能接收在其他应用程序中的控制文本。
函数原型:Int GetWindowText(HWND hWnd,LPTSTR lpString,Int nMaxCount);
参数:
hWnd:带文本的窗口或控制的句柄。
IpString:指向接收文本的缓冲区的指针。
nMaxCount:指定要保存在缓冲区内的字符的最大个数,其中包含NULL字符。如果文本超过界限,它就被截断。
返回值:如果函数成功,返回值是拷贝的字符串的字符个数,不包括中断的空字符;如果窗口无标题栏或文本,或标题栏为空,或窗口或控制的句柄无效,则返回值为零。若想获得更多错误信息,请调用GetLastError函数。
函数不能返回在其他应用程序中的编辑控制的文本。
备注:如果目标窗口属于当前进程,GetWindowText函数给指定的窗口或控制发送WM_GETTEXT消息。如果目标窗口属于其他进程,并且有一个窗口标题,则GetWindowTeXt返回窗口的标题文本,如果窗口无标题,则函数返回空字符串。
速查:Windows NT:3.1以上版本;Windows:95以上版本:Windows CE:1.0以上版本;头文件:Winuser.h;库文件:user32.lib:Unicode:在Windows NT上实现为Unicode和ANSI两种版本。
int GetWindowText(
LPTSTR lpszStringBuf,
int nMaxCount
) const;
void GetWindowText(
CString& rString
) const;
Parameters
lpszStringBuf
Points to the buffer that is to receive the copied string of the window's title.
nMaxCount
Specifies the maximum number of characters to be copied to the buffer, including the terminating null character. If the string is longer than the number of characters specified in nMaxCount, it is truncated.
rString
A CString object that is to receive the copied string of the window's title.
Return Value
Specifies the length, in characters, of the copied string, not including the terminating null character. It is 0 if CWnd has no caption or if the caption is empty.
Remarks
If the CWnd object is a control, the GetWindowText member function copies the text within the control instead of copying the caption.
This member function causes the WM_GETTEXT message to be sent to the CWnd object.