WEB开发网
开发学院软件开发VC VC学习:对话框 阅读

VC学习:对话框

 2010-11-01 08:07:59 来源:WEB开发网   
核心提示:GetDlgItem(IDC_EDIT3)->SetWindowText(ch3);//法二:GetDlgItemTextint num1, num2, num3;char ch1[10], ch2[10], ch3[10];GetDlgItemText(IDC_EDIT1,ch1,10);//GetDlgIte

GetDlgItem(IDC_EDIT3)->SetWindowText(ch3);

//法二:GetDlgItemText

int num1, num2, num3;

char ch1[10], ch2[10], ch3[10];

GetDlgItemText(IDC_EDIT1,ch1,10);//GetDlgItem和GetWindowText的组合

GetDlgItemText(IDC_EDIT2,ch2,10);

num1 = atoi(ch1);

num2 = atoi(ch2);

num3 = num1 + num2;

itoa(num3,ch3,10);

SetDlgItemText(IDC_EDIT3,ch3);

//法三:GetDlgItemInt

int num1, num2, num3;

num1 = GetDlgItemInt(IDC_EDIT1);//返回指定控件的文本,并将其转换为一个整型数值。可以实现负值的操作

num2 = GetDlgItemInt(IDC_EDIT2);

num3 = num1 + num2;

SetDlgItemInt(IDC_EDIT3,num3);

//▲法四:将控件与整型变量关联

//将三个编辑框分别与对话框类的三个成员变量相关联,然后再通过这些成员变量来检索和设置编辑框的文本

UpdateData();

m_num3 = m_num1 + m_num2;

UpdateData(FALSE);

//DDX:Dialog Data Exchange对话框数据交换    DDV:Dialog Data Validation对话框数据校验

//▲法五:将控件与控件变量关联

//编辑框与控件变量关联,这些控件变量就是控件本身

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);

//法六:SendMessage

int num1, num2, num3;

char ch1[10], ch2[10], ch3[10];

::SendMessage(GetDlgItem(IDC_EDIT1)->m_hWnd, WM_GETTEXT, 10,(LPARAM)ch1);//Platform SDK和CWnd类都提供SendMessage函数,加上::调用Platform SDK的函数

::SendMessage(m_edit2.m_hWnd, 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);    

//法七:SendDlgItemMessage

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);//EM_开头的消息是指编辑框控件消息(Edit Control Message)

m_edit3.SetFocus();

}

/*■6.<<对话框伸缩功能的实现>>*/

void CTestDlg::OnButton1()

{

// TODO: Add your control notification handler code here

CString str;

if(GetDlgItemText(IDC_BUTTON1, str), str == "收缩<<")

{

SetDlgItemText(IDC_BUTTON1,"扩展>>");

}

else

{

SetDlgItemText(IDC_BUTTON1,"收缩<<");

}

static CRect rectLarge;

static CRect rectSmall;

if(rectLarge.IsRectNull())

{

CRect rectSeparator;

GetWindowRect(&rectLarge);

GetDlgItem(IDC_SEPARATOR)->GetWindowRect(&rectSeparator);

rectSmall.left=rectLarge.left;

上一页  1 2 3 4  下一页

Tags:VC 对话框

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接