Article View: borland.public.cppbuilder.nativeapi
Article #2172Re: Foreground another application
From: JD
Date: Fri, 20 Apr 2007 20:55
Date: Fri, 20 Apr 2007 20:55
37 lines
2253 bytes
2253 bytes
"Andreas Osswald" <noname@noname.de> wrote:
>
>I want to bring another app (ext_app) to foreground. I do it like this:
>
>ExtHandle = FindWindow("CalssName","Caption");
>PostMessage(ExtHandle,WM_SYSCOMMAND,SC_RESTORE,0);
>SetForegroundWindow(ExtHandle);
I would expect this to be problematic because you're posting
the restore which IMO will not get processed until after you
have tried to being it to front.
> But if I want to minimize the ext_app (which was restore/comes
> to foreground) it doesn't work. I can click to the minimize
> button but nothing happens. I use the system menu but
> nothing happens too. After I restore the ext_app by my
> application I can't minimize the ext_app anymore.
You can if you right click it's TaskBar Icon and play with it.
The problem is that you're confusing Windows with respect to
the actual window state by minimizing a minimized window or
restoring a restored window.
Bob is correct that you need to use IsIconic and that you're
calling it with the wrong HWND. IsIconic doesn't work with
child windows so you need to call it on the Application's
Handle.
Once you get the Target HWND, add this:
HWND hWnd = reinterpret_cast<HWND>( ::GetWindowLong(TargetHwnd, GWL_HWNDPARENT) );
if( IsIconic(hWnd) ) ::ShowWindow( hWnd, SW_RESTORE );
::SetForegroundWindow( hWnd );
~ JD
Technical Details
Message-ID:
<462928d0$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<4625ec79$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,25ea57fd64e945c2 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "JD" <nospam@nospam.com> Sender: "JD" <nospam@nospam.com> Reply-To: "JD" <nospam@nospam.com> Subject: Re: Foreground another application Newsgroups: borland.public.cppbuilder.nativeapi X-User-Info: 152.163.100.144 X-Forwarded-For: 172.145.176.100 References: <4625ec79$1@newsgroups.borland.com> NNTP-Posting-Host: 207.105.83.66 Message-ID: <462928d0$1@newsgroups.borland.com> Date: 20 Apr 2007 13:55:44 -0700 X-Trace: newsgroups.borland.com 1177102544 207.105.83.66 (20 Apr 2007 13:55:44 -0700) Lines: 38 Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail