1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
int g_ChildNum;
HWND g_ChildWnd;
BOOL CALLBACK EnumChildWindowsCB( HWND hWnd, LPARAM lParam )
{
// every application is different, after some experimenting notepad's first child window
// is the edit control you type into.
if( !g_ChildNum )
g_ChildWnd = hWnd;
g_ChildNum++;
return TRUE;
}
void SendKeysToNotepad()
{
HINSTANCE hInst = ShellExecute( NULL, _T("open"), _T("notepad"), NULL, NULL, SW_SHOWNORMAL );
if( (int)hInst <= 32 )
return;
// wait some time to make sure window is completly created.
Sleep( 1000 );
HWND hWnd = FindWindow( NULL, _T("Untitled - Notepad") );
if( !hWnd )
return;
// The top window is not the edit control you type into.
// Need to find, this is a hack and different for every application.
EnumChildWindows( hWnd, EnumChildWindowsCB, 0 );
SendMessage( g_ChildWnd, WM_CHAR, 'H', 0 );
SendMessage( g_ChildWnd, WM_CHAR, 'e', 0 );
SendMessage( g_ChildWnd, WM_CHAR, 'l', 0 );
SendMessage( g_ChildWnd, WM_CHAR, 'l', 0 );
SendMessage( g_ChildWnd, WM_CHAR, 'o', 0 );
}
|