Re: can't bring "single instance" tray app to foreground

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



"Frank Cusack" <fcusack@xxxxxxxxxxx> wrote in message
news:m2ir91zy2o.fsf@xxxxxxxxxxxxxxxxxx

I meant I added it to AfxMessageBox().


I guess I'm not understanding what you want to have happen when the second
instance detects the first instance. You want some window to display, but
your main window is meant to be hidden. You keep mentioning some "dialog"
but then your code has AfxMessageBox(). So could you please clarify what
exactly you want to come to the foreground?


Damn, confused myself again. I meant, I have the first (already running,
now in the background) instance bring itself to the foreground. It does
this when the new instance posts the message to it. But it doesn't
make it to the foreground unless I do ShowWindow(SW_RESTORE) which is
terrible.


Yes, you don't want to call ShowWindow(SW_RESTORE) on your main window,
because that is meant to be hidden. I think the only reason for the main
window is because something must "own" the tray icon. But this main window
is never to be displayed because it has no useful content. You are right
that the first instance needs to bring the desired window (either dialog or
messagebox) to the foreground... or create itself anew with the foreground
style.


As long as the second instance (foreground app) calls
AllowSetForegroundWindow(), then the first instance can bring it's
window/dialog to the foreground. The concept is that only the app with
the
foreground focus can give it away, by calling AllowSetForegroundWindow.
Any
other process, including the first instance of your app, will be blocked
from having SetForegroundWindow() take effect... at least if the
"foreground
lock timeout", a user setting, is enabled.

hmm, are you saying ASWF() has to be called in the newly launched 2nd
instance? I was only calling it in the first (now running in bg)
instance. If it's that easy of a fix, that will be very cool.

If that's the case, I completely misunderstood how ASWF() works.


Yes, the second instance must be the one to call ASFW(), as it is the one
with the focus, and is the only one that can then allow other apps to
"steal" it.


-- David


.



Relevant Pages

  • Re: App does not become frontmost?? Delay in InitInstance
    ... > user started it and steal the foreground away from the window the user is ... > so they won't wonder if your app has hung. ... Sure enuf, after a 35 second delay, I could see what they were seeing. ...
    (microsoft.public.vc.mfc)
  • Re: Pass in additional command line arguments to a single instance app
    ... Explorer to send the filename to my app. ... I use the existence of a window with a particular class name as the indicator that a "first instance" is running. ... An instance can not start (create the window), exit, or check for existence of the window unless it can acquire the mutex. ...
    (microsoft.public.vc.language)
  • Re: BringWindowToFront/SetForegroundWindow problem
    ... full-screen window and pushing it to the bottom before trying to bring up the previous app. ... means you no longer have the foreground window status, and thus lose some ability to bring another ... the message loop has activated to handle the Registered Window Message. ...
    (microsoft.public.vc.mfc)
  • Re: cant bring "single instance" tray app to foreground
    ... frontmost/active window. ... anything since (because this is a trap app) the main window ... bring to the foreground, but currently I use a modal dialog (using ... call AllowSetForegroundWindowso that the first instance ...
    (microsoft.public.vc.mfc)
  • Re: cant bring "single instance" tray app to foreground
    ... frontmost/active window. ... anything since (because this is a trap app) the main window ... the second instance of your app needs to ... call AllowSetForegroundWindowso that the first instance ...
    (microsoft.public.vc.mfc)