Win32API函数SetWindowText怎样更新编辑框的内容
2个回答
2016-03-12 · 做真实的自己 用良心做教育
千锋教育
千锋教育专注HTML5大前端、JavaEE、Python、人工智能、UI&UE、云计算、全栈软件测试、大数据、物联网+嵌入式、Unity游戏开发、网络安全、互联网营销、Go语言等培训教育。
向TA提问
关注
展开全部
首先给编辑框关联一个CEdit类型的变量。(右键编辑框,添加变量就可以)
然后调用SetWindowText函数,传入CString类型的参数。
函数原型:
CWnd::SetWindowText
void SetWindowText( LPCTSTR lpszString );
范例(来源于MSDN):
Example
// set the text in IDC_MYEDIT
CWnd* pWnd = GetDlgItem(IDC_MYEDIT);
pWnd->SetWindowText(_T("Hockey is best!"));
// 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("Hockey is best!"));
// 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(lstrcmp(sz, _T("Hockey is")) == 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 == 15);
然后调用SetWindowText函数,传入CString类型的参数。
函数原型:
CWnd::SetWindowText
void SetWindowText( LPCTSTR lpszString );
范例(来源于MSDN):
Example
// set the text in IDC_MYEDIT
CWnd* pWnd = GetDlgItem(IDC_MYEDIT);
pWnd->SetWindowText(_T("Hockey is best!"));
// 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("Hockey is best!"));
// 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(lstrcmp(sz, _T("Hockey is")) == 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 == 15);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询