我试图从其他窗口动态获取文本(如果我在该窗口的文本字段中写入内容,然后启动我的程序,我必须看看我写了什么)。所以,如果我使用getWindowText ,它给了我一个静态的初始化文本框。所以这就是问题所在。它与间谍++相似。 下面的代码示例中,我做了什么:从文本框动态获取文本
#include <Windows.h>
#include <vector>
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;
int main()
{
HWND hWnd;
MSG msg;
vector<HWND> a;
hWnd = FindWindow(NULL, "SomeList");
vector<string> phrases;
char p[100];
if(!hWnd)
{
cout << "Window hasn't been found " << endl;
_getch();
exit(1);
}
hWnd = GetWindow(hWnd, GW_CHILD);
while (hWnd !=0)
{
hWnd = GetWindow(hWnd, GW_HWNDNEXT);
GetClassName(hWnd, p, 10);
string k(p);
if(k == "Edit")
a.push_back(hWnd);
GetWindowText(hWnd,p,100);
cout << p << endl;
}
phrases.resize(a.size());
for(auto i = a.begin();i != a.end();i++)
{
int index = 0;
GetWindowText(*i,p, 10);
string n(p);
if(n.size() != 0)
{
phrases[index] = n;
index++;
}
}
_getch();
return 0;
}
有什么实际问题? –
当我启动我的程序时,它不会读取我在文本框中写入的文本,它会读取已静态初始化的文本。我需要从文本框中读取文本,这些文本不是由SetWindowText初始化的,而是从我在窗口中写入的内容中获得的 – Psychoman
您正在为窗口的第一个子项瞄准编辑控件吗?如果是这样,你会直接跳过它。 –