Article View: borland.public.cppbuilder.nativeapi
Article #8951Re: Process ID
From: Ed Mulroy [TeamB]
Date: Fri, 20 Aug 2004 18:12
Date: Fri, 20 Aug 2004 18:12
58 lines
3266 bytes
3266 bytes
Your code has this:
> HWND aHandle = ShellInfo.hProcess;
The item is of type HANDLE and is a process handle, the handle of the
process you have created. It is not a window handle or HWND. By
using that handle you can use WaitForSingleObject to determine when
the process you have created has finished.
> How to get Process ID from aHandle?
You can't. Under XP Service Pack 1 and above there is a GetProcessId
function to do it. Under NT there are undocumented calls to do it
which are "you hope it works" things. There is no legal way to do it
under Win 95, 98, 98SE, ME, NT, 2K or XP prior to SP1.
The problem you describe goes away if you start the program with
FindExecutable and CreateProcess which results in giving you both a
process id and a process handle.
Your newly added requirement of maximizing the created process' window
would then be done via EnumWindows and GetWindowThreadProcessId to
find the HWND's of the program.
. Ed
> zoom wrote in message
> news:4125fa10@newsgroups.borland.com...
> Thank you for your helps. I have tried the ShellExecuteEx in the
> following
> code. Code successfully starts the Notepad.exe but it fails to send
> message
> to it which I think due to not being able to get the handle to the
> executed
> app (notepad.exe). So can you see where I'm doing wrong?
>
> . . .
> SHELLEXECUTEINFO ShellInfo; // Name structure
> memset(&ShellInfo, 0, sizeof(ShellInfo)); // Set up memory block
> ShellInfo.cbSize = sizeof(ShellInfo); // Set up structure size
> ShellInfo.hwnd = NULL;//Handle; // Calling window handle
> ShellInfo.lpVerb = "open"; // Open the file with default program
> ShellInfo.lpFile = "Notepad.exe"; // File to open
> ShellInfo.nShow = SW_NORMAL; // Open in normal window
> ShellInfo.fMask = SEE_MASK_NOCLOSEPROCESS; // Necessary if you want
> to wait
> for spawned process (Is problem here?)
> bool Okay = ShellExecuteEx(&ShellInfo); // Call to function
>
> if (Okay) {
> //WaitForSingleObject(ShellInfo.hProcess, INFINITE); // wait
> forever
> for process to finish
> Sleep(1000);
> HWND aHandle = ShellInfo.hProcess;
> SendMessage( aHandle,WM_SYSCOMMAND,SC_MAXIMIZE,0 );
> How to get Process ID from aHandle?
> }
Technical Details
Message-ID:
<41263f29@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<41208174$1@newsgroups.borland.com> <41208c52@newsgroups.borland.com> <4125fa10@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,55da334e6f257007 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Ed Mulroy [TeamB]" <dont_email_me@invalid.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <41208174$1@newsgroups.borland.com> <41208c52@newsgroups.borland.com> <4125fa10@newsgroups.borland.com> Subject: Re: Process ID Date: Fri, 20 Aug 2004 14:12:43 -0400 Lines: 60 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 12.161.27.55 Message-ID: <41263f29@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1093025577 12.161.27.55 (20 Aug 2004 11:12:57 -0700) X-Authenticated-User: edmulroy Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail