zoukankan      html  css  js  c++  java
  • c++ vs2010 GetWindowText GetWindowTextW

    UpdateData(TRUE);//将控件上显示上的数据更新到关联变量
    UpdateData(FALSE);将关联变量的值更新到控件显示。
    当你改变控件对应的关联变量的值的时候,要使用UpdateData(FALSE)来更新显示。
    当你在界面上更改控件的值的时候,你要使用UpdateData(TRUE);将值更新到关联变量
    或者如果不使用关联变量,可以使用GetDlgItemText(IDC_EDIT,str);或SetDlgItemText(IDC_EDIT,str)来更改控件的值的时候,就不需要UpdateData()函数

    msdn中也确是这么定义的:

    int GetWindowText( LPTSTR lpszStringBuf, int nMaxCount ) const;

    void GetWindowTextW( CString& rString ) const;

    要实现一个计算加法的功能。三个文本编辑框,分别为IDC_EDIT1 , IDC_EDIT2 , IDC_EDIT3, 一个button控件,点击后可以将IDC_EDIT1中的输入数字加上IDC_EDIT2中的输入数字的结果显示到IDC_EDIT3中。


    GetWindowText和GetWindowTextW方法

    #include "Tchar.h"  // 需要包含此头文件

    void CT3View::OnBnClickedButtonResult()
    {
        
        int num1,num2,num3;
        TCHAR chr1[10],chr2[10],chr3[10];     //如果定义char类的话,编译提示出错。msdn中给的范例采用TCHAR.
        CString str1,str2,str3;
        GetDlgItem(IDC_EDIT1)->GetWindowText(chr1,10);
        GetDlgItem(IDC_EDIT2)->GetWindowText(chr2,10);
        str1.Format(_T("%s"),chr1);//把TCHAR转换为CString
        num1=_wtoi(str1);// 再把CString转换为int
    
        str2.Format(_T("%s"),chr2);
        num2=_wtoi(str2);
    
        num3=num1+num2;
    
        str3.Format(_T("%d"),num3);
        GetDlgItem(IDC_EDIT3)->SetWindowText(str3);
    }
    void CT3View::OnBnClickedButtonResult()
    {
        
        int num1,num2,num3;
        TCHAR chr1[10],chr2[10],chr3[10];     //如果定义char类的话,编译提示出错。msdn中给的范例采用TCHAR.
        CString str1,str2,str3;
        GetDlgItem(IDC_EDIT1)->GetWindowTextW(str1);
        GetDlgItem(IDC_EDIT2)->GetWindowTextW(str2);
        
        num1=_wtoi(str1);// 把CString转换为int
    
        num2=_wtoi(str2);
    
        num3=num1+num2;
    
        str3.Format(_T("%d"),num3);
        GetDlgItem(IDC_EDIT3)->SetWindowTextW(str3);
    }
  • 相关阅读:
    MySQL与PostgreSQL对比
    Elastic Job3.0
    Nacos Config动态刷新值
    clickhouse数据类型
    字符串和整数之间的转换
    STL之优先队列 priority_queue
    c++智能指针
    springcloud gateway: discovery: locator: enabled: true 解释
    工具资源下载链接 webstorm
    技术链接汇总
  • 原文地址:https://www.cnblogs.com/ike_li/p/2804825.html
Copyright © 2011-2022 走看看