Article View: borland.public.cppbuilder.nativeapi
Article #1330Re: How to bring window (TForm) front
From: Jyrki Holopainen
Date: Tue, 18 Sep 2007 16:43
Date: Tue, 18 Sep 2007 16:43
30 lines
2427 bytes
2427 bytes
Dennis Jones wrote:
> HWND MainFormHWnd = FindWindow( "TMyMainForm", NULL );
>
> // get the main form's parent window handle (we'll assume
> MainFormHWnd
> // is not NULL, since we wouldn't even be here unless another
> instance
> // of the application were actually running)
> HWND hAppWnd = (HWND)GetWindowLong( MainFormHWnd, GWL_HWNDPARENT );
>
> if ( IsIconic( hAppWnd ) )
> {
> ShowWindow( hAppWnd, SW_RESTORE );
> }
> SetForegroundWindow( hAppWnd );
My problem was that under Windows XP a process cannot necessarily move
it's own window to foreground. The Win-API documentation that comes with
BCB6 does not mention this. This is described for example in
http://msdn2.microsoft.com/en-us/library/ms633539.aspx.
The code above works well if it is run at the program that gives
commands to program that is already running. Since these are two
separate processes, the SetForegroundWindow() function works. I had the
respective code at the part that was already running (logical place),
and that was the reason why it did not work.
Thanks everybody for the help!
/Jyrki
Technical Details
Message-ID:
<46f0005d@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!feeder3.cambrium.nl!feeder2.cambrium.nl!feed.tweaknews.nl!193.201.147.80.MISMATCH!news.astraweb.com!newsrouter-eu.astraweb.com!newsfeed2.ip.tiscali.net!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!t-online.de!newsfeed.freenet.de!newspeer1.nwr.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<46eecb19@newsgroups.borland.com> <46eed78e@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,67bd98c5f67e7407 X-Google-Attributes: gid10cc67,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Date: Tue, 18 Sep 2007 19:43:26 +0300 From: Jyrki Holopainen <New.Address@spammers.com> Reply-To: "JyrkiBorland AT halo.pp.fi.remove" User-Agent: Thunderbird 2.0.0.6 (Windows/20070728) MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: How to bring window (TForm) front References: <46eecb19@newsgroups.borland.com> <46eed78e@newsgroups.borland.com> In-Reply-To: <46eed78e@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 91.152.173.240 Message-ID: <46f0005d@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1190133853 91.152.173.240 (18 Sep 2007 09:44:13 -0700) Lines: 30 Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!feeder3.cambrium.nl!feeder2.cambrium.nl!feed.tweaknews.nl!193.201.147.80.MISMATCH!news.astraweb.com!newsrouter-eu.astraweb.com!newsfeed2.ip.tiscali.net!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!t-online.de!newsfeed.freenet.de!newspeer1.nwr.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail