对话框控件访问七种方式

 

 

/*    第1种
 int num1, num2, num3;
 char ch1[10], ch2[10], ch3[10];
 this->GetDlgItem(IDC_EDIT1)->GetWindowText(ch1, 10);
 this->GetDlgItem(IDC_EDIT2)->GetWindowText(ch2, 10);
 num1 = atoi(ch1);
 num2 = atoi(ch2);
 num3 = num1 + num2;
 itoa(num3, ch3, 10);
 this->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种
 UpdateData();
 m_num3 = m_num1 + m_num2;
 UpdateData(FALSE);*/


/*第5种
 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, 1, 3);
 m_edit3.SetFocus();

你可能感兴趣的:(对话框控件访问七种方式)