Article View: borland.public.cppbuilder.nativeapi
Article #13293Re: ShowWindow question
From: Bob Gonder
Date: Sat, 18 Oct 2003 22:39
Date: Sat, 18 Oct 2003 22:39
58 lines
2655 bytes
2655 bytes
Martin C wrote:
>HWND __fastcall TForm1::SearchProgramHandl(AnsiString ExeNameToHide)
>{
> HANDLE SysResHandl, RProgHandl;
> PROCESSENTRY32 Proc;
> String SRExename;
>
> RProgHandl=0;
>
> SysResHandl = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
>
> if (SysResHandl == INVALID_HANDLE_VALUE)
> { return 0; } else { }
>
> try
> {
> Proc.dwSize = sizeof(Proc);
> if(Process32First(SysResHandl, &Proc))
> {
> do
> {
Should check that dwSize includes szExeFile ( > 9*4 )
> SRExename = ExtractFileName(Proc.szExeFile); //Get the First Exe
I don't do VCL. I'll assume you've checked the result of the Extract.
Wonder why you didn't Extract the NameToHide too.
> if(UpperCase(Trim(ExeNameToHide))==UpperCase(Trim(SRExename)) )
That's a boat load of copying, and then you throw it all way, very
inefficient.
> { RProgHandl = OpenProcess(PROCESS_ALL_ACCESS, true,
>Proc.th32ProcessID); // Get Exe Handle
What happens if this fails? Need error handling here.
Also, shouldn't you break the loop when you've found it?
> }
> else
> { RProgHandl=0;
Why are you resetting this?
> }
I think you're supposed to reset dwSize here, as it can change.
> }while(Process32Next(SysResHandl, &Proc));
> }
> else
> { RProgHandl=0;
And again? You cleared this at the top.
> }
> }
>
> return RProgHandl;
Ok, now you have the ProcessHandle for the app in question.
But, don't you want a WindowHandle to pass to ShowWindow()?
Technical Details
Message-ID:
<pee3pv8pp2m367s11uq91tmls2fl4alf8c@4ax.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!news-out.visi.com!petbe.visi.com!ash.uu.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<3f90a515@newsgroups.borland.com> <srq1pvg3emp51jq97kjt2tkaqv8uoa5cpm@4ax.com> <3f91b0b3@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,644d4ac8e2f18824 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-10-18 15:54:23 PST From: Bob Gonder <notbg@notmindspring.invalid> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: ShowWindow question Date: Sat, 18 Oct 2003 15:39:49 -0700 Organization: MindSpring Enterprises, Inc. Reply-To: notbg@notmindspring.invalid Message-ID: <pee3pv8pp2m367s11uq91tmls2fl4alf8c@4ax.com> References: <3f90a515@newsgroups.borland.com> <srq1pvg3emp51jq97kjt2tkaqv8uoa5cpm@4ax.com> <3f91b0b3@newsgroups.borland.com> X-Newsreader: Forte Agent 1.91/32.564 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 67.31.166.11 X-Trace: newsgroups.borland.com 1066516790 67.31.166.11 (18 Oct 2003 15:39:50 -0700) Lines: 60 Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!news-out.visi.com!petbe.visi.com!ash.uu.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail