c++编程:获取控件上的文本值---例子是CEdit 的七种方法(转载)
2011-09-28 17:10
531 查看
获取控件上的文本值---例子是CEdit 的七种方法
2010年03月23日 星期二 11:22
![](http://p.blog.csdn.net/images/p_blog_csdn_net/qq7187057/CEdit.JPG)
1.
int num1,num2,num3;
char ch1[10],ch2[10],ch3[10];
GetDlgItem(IDC_EDIT1)->GetWindowText(ch1,10);
GetDlgItem(IDC_EDIT2)->GetWindowText(ch2,10);
num1=atoi(ch1);
num2=atoi(ch2);
num3=num1+num2;
itoa(num3,ch3,10);
GetDlgItem(IDC_EDIT3)->SetWindowText(ch3);
2.
int num1,num2,num3;
char ch1[10],ch2[10],ch3[10];
GetDlgItemText(IDC_EDIT1,ch1,10);
GetDlgItemText(IDC_EDIT2,ch2,10);
num1=atoi(ch1);
num2=atoi(ch2);
num3=num1+num2;
itoa(num3,ch3,10);
SetDlgItemText(IDC_EDIT3,ch3);
3.
int num1,num2,num3;
num1=GetDlgItemInt(IDC_EDIT1);
num2=GetDlgItemInt(IDC_EDIT2);
num3=num1+num2;
SetDlgItemInt(IDC_EDIT3,num3);
4.//定义成员变量..变量与控 件关连
/**
//{{AFX_DATA(CTestDlg)
enum { IDD = IDD_DIALOG1 };
int m_num1;
int m_num2;
int m_num3;
//}}AFX_DATA
void CTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTestDlg)
DDX_Text(pDX, IDC_EDIT1, m_num1);
DDV_MinMaxInt(pDX, m_num1, 0, 100);
DDX_Text(pDX, IDC_EDIT2, m_num2);
DDV_MinMaxInt(pDX, m_num2, 0, 100);
DDX_Text(pDX, IDC_EDIT3, m_num3);
//}}AFX_DATA_MAP
}
**/
UpdateData();
m_num3=m_num1+m_num2;
UpdateData(FALSE);
/*
CWnd::UpdateData
BOOL UpdateData( BOOL bSaveAndValidate = TRUE );
Return Value
Nonzero if the operation is successful; otherwise 0. If bSaveAndValidate is TRUE, then a return value of nonzero means that the data is successfully validated.
Parameters
bSaveAndValidate
Flag that indicates whether dialog box is being initialized (FALSE) or data is being retrieved (TRUE).
Remarks
Call this member function to initialize data in a dialog box, or to retrieve and validate dialog data.
The framework automatically calls UpdateData with bSaveAndValidate set to FALSE when a modal dialog box is created in the default implementation of CDialog::OnInitDialog. The call occurs before the dialog box is visible. The default implementation of CDialog::OnOK calls this member function with bSaveAndValidate set to TRUE to retrieve the data, and if successful, will close the dialog box. (If the Cancel button is clicked in the dialog box, the dialog box is closed without the data being retrieved.)
*/
5.//定义控件变量..变量与控件关连
//{{AFX_DATA(CTestDlg)
enum { IDD = IDD_DIALOG1 };
CEdit m_edit3;
CEdit m_edit2;
CEdit m_edit1;
//}}AFX_DATA
void CTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTestDlg)
DDX_Control(pDX, IDC_EDIT3, m_edit3);
DDX_Control(pDX, IDC_EDIT2, m_edit2);
DDX_Control(pDX, IDC_EDIT1, m_edit1);
//}}AFX_DATA_MAP
}
int num1,num2,num3;
char ch1[10],ch2[10],ch3[10];
m_edit1.GetWindowText(ch1,10);
m_edit2.GetWindowText(ch2,10);
num1=atoi(ch1);
num2=atoi(ch2);
num3=num1+num2;
itoa(num3,ch3,10);
m_edit3.SetWindowText(ch3);
6.
int num1,num2,num3;
char ch1[10],ch2[10],ch3[10];
//::SendMessage(GetDlgItem(IDC_EDIT1)->m_hWnd,WM_GETTEXT,10, (LPARAM)ch1);//方法一
//::SendMessage(m_edit1.m_hWnd,WM_GETTEXT,10, (LPARAM)ch1);//方法二
//GetDlgItem(IDC_EDIT1)->SendMessage(WM_GETTEXT,10, (LPARAM)ch1);//方法三
m_edit1.SendMessage(WM_GETTEXT,10,(LPARAM)ch1);//方法四
m_edit2.SendMessage(WM_GETTEXT,10,(LPARAM)ch2);
num1=atoi(ch1);
num2=atoi(ch2);
num3=num1+num2;
itoa(num3,ch3,10);
m_edit3.SendMessage(WM_SETTEXT,0,(LPARAM)ch3);
7.
int num1,num2,num3;
char ch1[10],ch2[10],ch3[10];
SendDlgItemMessage(IDC_EDIT1,WM_GETTEXT,10,(LPARAM)ch1);
SendDlgItemMessage(IDC_EDIT2,WM_GETTEXT,10,(LPARAM)ch2);
num1=atoi(ch1);
num2=atoi(ch2);
num3=num1+num2;
itoa(num3,ch3,10);
SendDlgItemMessage(IDC_EDIT3,WM_SETTEXT,0,(LPARAM)ch3);
SendDlgItemMessage(IDC_EDIT3,EM_SETSEL,0,-1);
2010年03月23日 星期二 11:22
1.
int num1,num2,num3;
char ch1[10],ch2[10],ch3[10];
GetDlgItem(IDC_EDIT1)->GetWindowText(ch1,10);
GetDlgItem(IDC_EDIT2)->GetWindowText(ch2,10);
num1=atoi(ch1);
num2=atoi(ch2);
num3=num1+num2;
itoa(num3,ch3,10);
GetDlgItem(IDC_EDIT3)->SetWindowText(ch3);
2.
int num1,num2,num3;
char ch1[10],ch2[10],ch3[10];
GetDlgItemText(IDC_EDIT1,ch1,10);
GetDlgItemText(IDC_EDIT2,ch2,10);
num1=atoi(ch1);
num2=atoi(ch2);
num3=num1+num2;
itoa(num3,ch3,10);
SetDlgItemText(IDC_EDIT3,ch3);
3.
int num1,num2,num3;
num1=GetDlgItemInt(IDC_EDIT1);
num2=GetDlgItemInt(IDC_EDIT2);
num3=num1+num2;
SetDlgItemInt(IDC_EDIT3,num3);
4.//定义成员变量..变量与控 件关连
/**
//{{AFX_DATA(CTestDlg)
enum { IDD = IDD_DIALOG1 };
int m_num1;
int m_num2;
int m_num3;
//}}AFX_DATA
void CTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTestDlg)
DDX_Text(pDX, IDC_EDIT1, m_num1);
DDV_MinMaxInt(pDX, m_num1, 0, 100);
DDX_Text(pDX, IDC_EDIT2, m_num2);
DDV_MinMaxInt(pDX, m_num2, 0, 100);
DDX_Text(pDX, IDC_EDIT3, m_num3);
//}}AFX_DATA_MAP
}
**/
UpdateData();
m_num3=m_num1+m_num2;
UpdateData(FALSE);
/*
CWnd::UpdateData
BOOL UpdateData( BOOL bSaveAndValidate = TRUE );
Return Value
Nonzero if the operation is successful; otherwise 0. If bSaveAndValidate is TRUE, then a return value of nonzero means that the data is successfully validated.
Parameters
bSaveAndValidate
Flag that indicates whether dialog box is being initialized (FALSE) or data is being retrieved (TRUE).
Remarks
Call this member function to initialize data in a dialog box, or to retrieve and validate dialog data.
The framework automatically calls UpdateData with bSaveAndValidate set to FALSE when a modal dialog box is created in the default implementation of CDialog::OnInitDialog. The call occurs before the dialog box is visible. The default implementation of CDialog::OnOK calls this member function with bSaveAndValidate set to TRUE to retrieve the data, and if successful, will close the dialog box. (If the Cancel button is clicked in the dialog box, the dialog box is closed without the data being retrieved.)
*/
5.//定义控件变量..变量与控件关连
//{{AFX_DATA(CTestDlg)
enum { IDD = IDD_DIALOG1 };
CEdit m_edit3;
CEdit m_edit2;
CEdit m_edit1;
//}}AFX_DATA
void CTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTestDlg)
DDX_Control(pDX, IDC_EDIT3, m_edit3);
DDX_Control(pDX, IDC_EDIT2, m_edit2);
DDX_Control(pDX, IDC_EDIT1, m_edit1);
//}}AFX_DATA_MAP
}
int num1,num2,num3;
char ch1[10],ch2[10],ch3[10];
m_edit1.GetWindowText(ch1,10);
m_edit2.GetWindowText(ch2,10);
num1=atoi(ch1);
num2=atoi(ch2);
num3=num1+num2;
itoa(num3,ch3,10);
m_edit3.SetWindowText(ch3);
6.
int num1,num2,num3;
char ch1[10],ch2[10],ch3[10];
//::SendMessage(GetDlgItem(IDC_EDIT1)->m_hWnd,WM_GETTEXT,10, (LPARAM)ch1);//方法一
//::SendMessage(m_edit1.m_hWnd,WM_GETTEXT,10, (LPARAM)ch1);//方法二
//GetDlgItem(IDC_EDIT1)->SendMessage(WM_GETTEXT,10, (LPARAM)ch1);//方法三
m_edit1.SendMessage(WM_GETTEXT,10,(LPARAM)ch1);//方法四
m_edit2.SendMessage(WM_GETTEXT,10,(LPARAM)ch2);
num1=atoi(ch1);
num2=atoi(ch2);
num3=num1+num2;
itoa(num3,ch3,10);
m_edit3.SendMessage(WM_SETTEXT,0,(LPARAM)ch3);
7.
int num1,num2,num3;
char ch1[10],ch2[10],ch3[10];
SendDlgItemMessage(IDC_EDIT1,WM_GETTEXT,10,(LPARAM)ch1);
SendDlgItemMessage(IDC_EDIT2,WM_GETTEXT,10,(LPARAM)ch2);
num1=atoi(ch1);
num2=atoi(ch2);
num3=num1+num2;
itoa(num3,ch3,10);
SendDlgItemMessage(IDC_EDIT3,WM_SETTEXT,0,(LPARAM)ch3);
SendDlgItemMessage(IDC_EDIT3,EM_SETSEL,0,-1);
相关文章推荐
- c++编程:获取控件上的文本值---例子是CEdit 的七种方法(转载)
- 获取控件上的文本值---例子是CEdit 的七种方法
- VC获取控件文本的几种方法
- VC 获取静态文本控件和文本框控件上的文本方法
- C#获取当前路径的七种方法 【转载】
- CEdit 获取文本的7种方法
- VC 获取静态文本控件和文本框控件上的文本方法
- 孙鑫VC++深入详解:Lesson7 Part2---访问静态文本控件的七种方法
- MFC总结(9) ---- CEdit 获取文本的7种方法
- dom(一)——获取文本内容的方法
- 关于用 apache cxf中对于不是返回200错误的处理 ,获取错误描述文本的方法
- android developer tips---干掉adb侵入者命令和activity中获取控件宽高方法
- C#获取Excel各类信息的方法(转载)
- Flex的NumericStepper控件中如何通过textAlign样式设置文本对齐方式的例子
- Flex中通过设置textAlign和headerStyleName样式设置DateChooser控件头部年月文本对齐方式的例子
- js 获取div里的值 2种方法给父窗口控件赋值和取值
- vc 多个菜单 绑定一个 方法 获取对应控件id
- Android中的获取控件矩阵gethitrect方法
- VC窗体透明而控件不透明以及Static文本背景透明方法
- javascript获取asp.net服务器端控件的值(2009-10-31 15:24:26)转载标签:杂谈 分类:技术分类