C++ Caption

主题

1. 设置控件的标题文本

2. 获取控件的标题文本

 
 

Caption属性

取得一个窗体的标题(caption)文字,或者一个控件的内容

 
011914347902645.png
011914367742773.png
红色的部分就是 Caption 标题
 

SetWindowText

BOOL SetWindowText(          

    HWND hWnd,

    LPCTSTR lpString

);

 
 

SetDlgItemText

void SetDlgItemText(
        int nID,           //控件的ID号
        LPCTSTR lpszString //字符串
 );
 

设置控件的标题文本 使用API SetWindowText

//使用CWnd
CWnd *pWnd;
pWnd = GetDlgItem( IDC_BUTTON1 ); //按钮1的ID
pWnd->SetWindowText( "ABC" );
 
//设置主窗体的标题
SetWindowText(_T("MFC"));
 
//设置按钮的文本
GetDlgItem(IDC_BUTTON1)->SetWindowText(_T("BTN1"));
//或
SetDlgItemText(IDC_BUTTON1,"ABCD");
 
//设置多选框的文字 (关联变量)
m_CHK1.SetWindowText(_T("CheckBox1"));
//或
SetDlgItemText(IDC_CHECK1,"ABCD");
 
 
 
 
 

GetWindowText

 
int GetWindowText(         
    HWND hWnd,
    LPTSTR lpString,
    int nMaxCount
);

 
 

GetDlgItemText

int GetDlgItemText(
    int nID,
    LPTSTR lpStr,
    int nMaxCount
) const;
 
int GetDlgItemText(
     int nID,
     CString& rString
) const;
 
 

获取控件的标题文本 使用API GetWindowText可以实现

 

//获取到按钮1的文本 并设置给主窗体的标题
CString str;
this->GetDlgItem(IDC_BUTTON1)->GetWindowText(str);
this->SetWindowText(str);
 
                
CString s;
GetDlgItemText(IDC_BUTTON1,s);
MessageBox(s);
 
 




转载于:https://www.cnblogs.com/xe2011/p/3885705.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值