CWnd::SetWindowText

设置窗口的标题到指定的文本。

void SetWindowText(
   LPCTSTR lpszString 
);

参数

  • lpszString
    指向 CString 作为新标题或控件文本或Null终止的字符串将使用的对象。

备注

如果窗口是控件,在控件内的文本设置。

此功能使 WM_SETTEXT 发送到此窗口。

示例

// set the text in IDC_EDITNAME
CWnd* pWnd = GetDlgItem(IDC_EDITNAME);
pWnd->SetWindowText(_T("Gerald Samper"));

// Get the text back. CString is convenient, because MFC
// will automatically allocate enough memory to hold the
// text--no matter how large it is.

CString str;
pWnd->GetWindowText(str);
ASSERT(str == _T("Gerald Samper"));

// The LPTSTR override works, too, but it might be too short.
// If we supply a buffer that's too small, we'll only get those
// characters that fit.

TCHAR sz[10];
int nRet = pWnd->GetWindowText(sz, 10);

// Nine characters, plus terminating null
ASSERT(_tcscmp(sz, _T("Gerald Sa")) == 0);
ASSERT(nRet == 9);

// You can query the length of the text without the length of
// the string using CWnd::GetWindowTextLength()
nRet = pWnd->GetWindowTextLength();
ASSERT(nRet == 13);

要求

Header: afxwin.h

请参见

参考

CWnd 类

层次结构图

CWnd::GetWindowText

SetWindowText