I'm trying to get text from other window dynamically( if I write something in a textfield of that window and then launch my program, I must see what I wrote ).So if I use getWindowText, it gives me a static initialized textbox.So that's the problem.It's similar ,what spy++ does. Here's the code example what I done:
#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;
}
GetWindowText documentation:
Example: