开发者

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("");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜