0

I've run a small application from CreateProcess using WaitForInputIdle straight after but I can't seem to get the correct window handle for the newly created process via EnumWindows and GetWindowThreadProcessId, the .exe I run as a process looks like this:

101 DIALOGEX 0, 0, 333, 180
STYLE WS_POPUP
EXSTYLE WS_EX_TOOLWINDOW
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK
FONT 8, "MS Sans Serif"
{
   CONTROL "", 1012, EDIT, ES_CENTER | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE, 5, 38,  195, 11 , 0x00000020
   CONTROL "", 1013, EDIT, ES_CENTER | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE, 6, 4, 195, 11 , 0x00000020
   CONTROL "", 1011, EDIT, ES_CENTER | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE, 5, 21, 195, 11 , 0x00000020
}

I'm assuming '101' would be the main window so that would be the handle I get however GetDlgItem fails to retrieve the child windows with error 1400 (Invalid window handle) then trying ShowWindow with the found handle fails also.

Does anyone with any experience of this kind of thing know why I get a handle that's not for any known window?

Also I assumed the CreateProcess function would put the newly created process in the list of apps/processes running with the parent application in task manager but it put's it as a background process on it's own, how do I add the process to list of processes running from the parent application?

enter image description here

Col_Blimp
  • 779
  • 2
  • 8
  • 26

1 Answers1

4

The resource ID 101 is not useful to you here. That is used to retrieve the resource from the executable, but it will not help you find the window handle.

What you need to do is:

  1. Use EnumWindows to enumerate top-level windows.
  2. Call GetWindowThreadProcessId on each top-level window to find the process ID that owns the window.
  3. Stop enumerating when you find a top-level window with a process ID that matches the process ID returned by the call to CreateProcess.
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490