Getting an HWND from a process started with CreateProcess
I'm working on a simple console application. It takes some command line parameters containing a path of a Win32 executable. What I need to do is execute that program, maximize the window, then capture its contents and output it to a file. My question is, after creating the process, how should I go about getting the HWND for the process' main window? After that, maximizing the window and capturing the contents shouldn't be a problem, but I'm not sure how to go out there and get the window handle. I'd appreciate any input you guys have on this. Thanks.
I cannot see the window belonging to CreateProcess
I cannot see the window that belongs to MyApp.exe, actually i include on the EnumWindowsProc the GetWindowsText function to see what windows is getting the enumwindows.
ByThe way : When i execute my app from windows explorer I can see it on my Program that use the EnumWindows.....
Am i missing something on the CreateProcess ??
I call CreateProcess in this way :
CreateProcess( "MyApp.exe",
NULL, // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
NULL, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ) // Pointer to PROCESS_INFORMATION structure.
)
and this on my Enum Stuff :
bool CALLBACK EnumWindowsProc(HWND hwnd, LPARAM param)
{DWORD pID;
char szBuffer[MAX_PATH];
GetWindowText(hwnd,szBuffer,200);
DWORD TpID = GetWindowThreadProcessId(hwnd, &pID);
ShowMessage(szBuffer);
if (TpID == (DWORD)param)
{
Application->MessageBox(sMsg.c_str(),"Entro a ID Iguales",MB_OK);
FormMain->TargetHWND = hwnd;
return false;
}
return true;
}