ITg
ITg

Reputation: 138

C++ textbox contents

How do I get the contents of a textbox in C++?

Upvotes: 3

Views: 1928

Answers (5)

Hugh Jorgan
Hugh Jorgan

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

Upvotes: 0

Hugh Jorgan
Hugh Jorgan

Reputation: 11

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

Upvotes: 1

Abyx
Abyx

Reputation: 12918

GetWindowText()

Upvotes: 1

John Dibling
John Dibling

Reputation: 101446

CWnd::GetWindowText()

Upvotes: 1

Brian R. Bondy
Brian R. Bondy

Reputation: 347196

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.

Upvotes: 7

Related Questions