Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2007 Sep : SetForegroundwindow to DOS program

www.cryer.info
Managed Newsgroup Archive

SetForegroundwindow to DOS program

Subject:SetForegroundwindow to DOS program
Posted by:"Joe H" (joedot..@att.net)
Date:10 Sep 2007 06:54:18

I'm stuck. I've searched google and the ng's for hours to no avail. I'm
trying to launch a dos program from a Delphi app using createprocess
which works fine. I capture the processid and the handle at this time.
I use processid and the CreateToolHelpSnapshot to enumerate all windows
to see if my processid is running in order to prevent launching the
program a second time and that works fine as well. Then I want to send
keys to that program to cause it to shut down when the user stops the
delphi program. I'm using SetForegroundWindow and sendinput for that.

The sent keys never make it to the dos program because
setForegroundWindow fails to work, even though my process launched the
dos program. I've seen many examples on Google that used this api
function supposedly to switch focus to a dos program but it flat does
not work.

Anybody know of another way to change the focus to a DOS window so it
can receive keyboard input? Like I said, I know the processid and the
thread handle.  I've tried the hProcess to use as the window handle,
and the hThread. Maybe stupid question but is the HWND different from
either of these? and if so is there a way to get the window handle from
the ProcessID, threadID, hthread or hprocess which are all defined when
CreateProcess runs?

Replies:

www.cryer.info
Managed Newsgroup Archive