C++ textbox contents
How d开发者_Python百科o I get the contents of a textbox in C++?
Use the Win32 API GetWindowText passing in the text box's window handle.
If you want to get the text from another process use WM_GETTEXT instead with SendMessage.
CWnd::GetWindowText()
GetWindowText()
Correction to last post:
//unicode std::string or std::wstring
typedef std::basic_string<TCHAR> unicode_string;
unicode_string GetWinString(HWND h)
{
int len = ::GetWindowTextLength(h);
if (len)
{
std::vector<TCHAR> tmp(len + 1,_T('\0'));
::GetWindowText(h,&tmp[0],len + 1);
return &tmp[0];
}
return _T("");
}
//unicode std::string or std::wstring
typedef std::basic_string<TCHAR> unicode_string;
unicode_string GetWinString(HWND h)
{
int len = ::GetWindowTextLength(h);
if (len)
{
std::vector<TCHAR> tmp(len + 1,_T('\0'));
::GetWindowText(h,&tmp[0],len + 1);
return &tmp[0];
}
return _T("");
}
精彩评论