清泛IT社区

标题: 如何获取控件的值? [打印本页]

作者: 清泛网    时间: 2016-02-04 13:40
标题: 如何获取控件的值?
最简单直观的:
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 );








欢迎光临 清泛IT社区 (https://bbs.tsingfun.com/) Powered by Discuz! X3.3