 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Andreas Osswald Guest
|
Posted: Wed Apr 18, 2007 3:02 pm Post subject: Foreground another application |
|
|
Hello,
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);
The minimized ext_app comes to foreground, it works.
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.
Regards
Andreas |
|
| Back to top |
|
 |
Bob Gonder Guest
|
Posted: Wed Apr 18, 2007 6:56 pm Post subject: Re: Foreground another application |
|
|
Andreas Osswald wrote:
| Quote: | 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);
|
Try it this way:
if( IsIconic( h ) )
{ ShowWindow( h, SW_RESTORE );
}else{
SetForegroundWindow( h );
}; |
|
| Back to top |
|
 |
Andreas Osswald Guest
|
Posted: Wed Apr 18, 2007 9:38 pm Post subject: Re: Foreground another application |
|
|
Is doesn't work!
the function IsIconic returns always zero whether the application is
minimized or not.
After I use the ShowWindow function I can't re minimize the application.
regards
Andreas
"Bob Gonder" <notbg (AT) notmindspring (DOT) invalid> schrieb im Newsbeitrag
news:sm8c235a13e21geu4lp54r7rorcgee163e (AT) 4ax (DOT) com...
| Quote: | Andreas Osswald 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);
Try it this way:
if( IsIconic( h ) )
{ ShowWindow( h, SW_RESTORE );
}else{
SetForegroundWindow( h );
};
|
|
|
| Back to top |
|
 |
Bob Gonder Guest
|
Posted: Thu Apr 19, 2007 2:51 am Post subject: Re: Foreground another application |
|
|
Andreas Osswald wrote:
| Quote: | Is doesn't work!
the function IsIconic returns always zero whether the application is
minimized or not.
After I use the ShowWindow function I can't re minimize the application.
|
I just rechecked my console app that uses that code.
I use EnumWindows(EnumProc,0); to get a list of hwnds that the user
can select. I then run that handle through the code I gave, and even
restored minimized windows can be minimized again.
If that code isn't working for you then either the hwnds aren't the
proper ones, or VCL is otherwise screwing with you. |
|
| Back to top |
|
 |
JD Guest
|
Posted: Sat Apr 21, 2007 1:55 am Post subject: Re: Foreground another application |
|
|
"Andreas Osswald" <noname (AT) noname (DOT) de> wrote:
| Quote: |
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.
| Quote: | 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 |
|
| Back to top |
|
 |
JD Guest
|
Posted: Sat Apr 21, 2007 1:59 am Post subject: Re: Foreground another application |
|
|
Bob Gonder <notbg (AT) notmindspring (DOT) invalid> wrote:
| Quote: |
[...] or VCL is otherwise screwing with you.
|
For shame, for shame, for shame!
Please see my reply to Andreas.
I had a very similar problem long ago and posted several times
and no one could help. Then one day ... YOU pointed out that
IsIconic wants the Application's Handle! Getting too old for
this <g> ?
~ JD |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Sat Apr 21, 2007 2:22 am Post subject: Re: Foreground another application |
|
|
"JD" <nospam (AT) nospam (DOT) com> wrote in message
news:462928d0$1 (AT) newsgroups (DOT) borland.com...
| Quote: | HWND hWnd = reinterpret_cast<HWND>( ::GetWindowLong(TargetHwnd,
GWL_HWNDPARENT) ); |
Use GetParent() instead:
HWND hWnd = ::GetParent(TargetHwnd);
Also, keep in mind that in BDS 2007, the TApplication object no longer
controls the taskbar button. I'm not sure if the TApplication window
is even still the parent for TForm windows anymore.
Gambit |
|
| Back to top |
|
 |
JD Guest
|
Posted: Wed Apr 25, 2007 1:58 am Post subject: Re: Foreground another application |
|
|
"Remy Lebeau \(TeamB\)" <no.spam (AT) no (DOT) spam.com> wrote:
| Quote: |
Use GetParent() instead:
|
Funny ... I do use GetParent else where .... but other than
the extra typing, is there any difference?
| Quote: | Also, keep in mind that in BDS 2007, the TApplication object
no longer controls the taskbar button. I'm not sure if the
TApplication window is even still the parent for TForm
windows anymore.
|
I've been diverted time and time again with BCB6 stuff and I'm
angry about that! Thanks for the heads-up. I'll look at it as
soon as I get BDS installed (which looks like some time after
the next BDS is released).
~ JD |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|