获取控件的值的几种方法总结
清泛原创
最简单直观的:
CString str;
GetDlgItemText(IDC_EDIT_TEST, str);
int d=atoi(str.GetBuffer(0));
更优雅的:
.h:int m_editTest;
.cpp:
void CxxDlg::DoDataExchange(CDataExchange* pDX)
{
DDX_Text(pDX, IDC_EDIT_TEST, m_editTest);
}
这样就绑定了控件和一个数据变量,当控件数据发生变化Updatedata(TRUE)后就会反映到变量上。其他类型变量也一样。
Updatedata(TRUE) :将控件的值赋值给成员变量;
Updatedata(FALSE) : 将成员变量的值赋值给控件。
void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, BYTE& value );
void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, short& value );
void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, int& value );
void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, UINT& value );
void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, long& value );
void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, DWORD& value );
void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, CString& value );
void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, float& value );
void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, double& value );
void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, COleCurrency& value );
void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, COleDateTime& value );
CString str;
GetDlgItemText(IDC_EDIT_TEST, str);
int d=atoi(str.GetBuffer(0));
更优雅的:
.h:int m_editTest;
.cpp:
void CxxDlg::DoDataExchange(CDataExchange* pDX)
{
DDX_Text(pDX, IDC_EDIT_TEST, m_editTest);
}
这样就绑定了控件和一个数据变量,当控件数据发生变化Updatedata(TRUE)后就会反映到变量上。其他类型变量也一样。
Updatedata(TRUE) :将控件的值赋值给成员变量;
Updatedata(FALSE) : 将成员变量的值赋值给控件。
void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, BYTE& value );
void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, short& value );
void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, int& value );
void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, UINT& value );
void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, long& value );
void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, DWORD& value );
void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, CString& value );
void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, float& value );
void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, double& value );
void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, COleCurrency& value );
void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, COleDateTime& value );