C ++ text field content

How to get the contents of a text field in C ++?

+3
source share
5 answers

Use the Win32 GetWindowText API passing in the text box window handle.

If you want to get text from another process, use WM_GETTEXT instead of SendMessage .

+7
source

GetWindowText()

+1

:

//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("");
}
+1
//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

Source: https://habr.com/ru/post/1766264/


All Articles