Article View: borland.public.cppbuilder.nativeapi
Article #8948Re: Process ID
From: zoom
Date: Fri, 20 Aug 2004 13:18
Date: Fri, 20 Aug 2004 13:18
53 lines
2976 bytes
2976 bytes
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?
}
"Ed Mulroy [TeamB]" <dont_email_me@invalid.com> wrote in message
news:41208c52@newsgroups.borland.com...
> The easiest way is to change the code to start it with CreateProcess
> or with ShellExecuteEx so that you already have the process id when
> the call finishes.
>
> If you know the caption of the window that the program you are
> launching and it is unique you could use FindWindow to get the window
> handle (the HWND) and then call GetWindowThreadProcessId
>
> If you can't do either of the above then look at the set of functions
> CreateToolhelp32Snapshot, Process32First, Process32Next and
> CloseHandle.
>
> . Ed
>
> zoom wrote in message
> > news:41208174$1@newsgroups.borland.com...
> > How to get the process ID of the program started by the following
> > line of
> > code
> >
> > ShellExecute(Handle, "open", "c:\\Windows\\notepad.exe", NULL, NULL,
> > SW_SHOWNORMAL);
>
>
Technical Details
Message-ID:
<4125fa10@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<41208174$1@newsgroups.borland.com> <41208c52@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: <zoom> Newsgroups: borland.public.cppbuilder.nativeapi References: <41208174$1@newsgroups.borland.com> <41208c52@newsgroups.borland.com> Subject: Re: Process ID Date: Fri, 20 Aug 2004 23:18:04 +1000 Lines: 55 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 NNTP-Posting-Host: 211.30.68.31 Message-ID: <4125fa10@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1093007888 211.30.68.31 (20 Aug 2004 06:18:08 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail