主题 |
1. 设置控件的标题文本 2. 获取控件的标题文本 |
Caption属性 |
取得一个窗体的标题(caption)文字,或者一个控件的内容
|
红色的部分就是 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);
|