How do I get the contents of a textbox in C++?
+6
A:
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.
Brian R. Bondy
2010-09-23 17:43:18
If in the string I had "1 + 1", do you know how I could make it do 1 + 1?
ITg
2010-09-23 17:59:13
@ITg: You will probably need to parse the string into parts and then do your calculation.
Brian R. Bondy
2010-09-23 18:02:27
ok, thanks for your help
ITg
2010-09-23 18:05:45
A:
//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("");
}
Hugh Jorgan
2010-09-23 21:42:30
A:
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("");
}
Hugh Jorgan
2010-10-04 08:32:02
There's an "edit" option below your posts; please don't post additional answers.
MSalters
2010-10-04 08:53:34