2010-09-23 66 views

回答

7

使用Win32 API GetWindowText传递文本框的窗口句柄。

如果要从其他进程获取文本,请使用WM_GETTEXT而不是SendMessage

+0

如果字符串中我有 “1 + 1”,你知道我怎么可能使它做1 + 1? – ITg 2010-09-23 17:59:13

+0

@ITg:您可能需要将字符串解析为部分,然后进行计算。 – 2010-09-23 18:02:27

+0

好的,感谢您的帮助 – ITg 2010-09-23 18:05:45

1

GetWindowText函数()

0
//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

您的帖子下方有一个“修改”选项;请不要发布其他答案。 – MSalters 2010-10-04 08:53:34