Re: can't bring "single instance" tray app to foreground
- From: "David Ching" <dc@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 03 Jul 2007 01:56:36 GMT
"Frank Cusack" <fcusack@xxxxxxxxxxx> wrote in message
news:m2fy46ia1i.fsf@xxxxxxxxxxxxxxxxxx
I'm using the single instance class found at
<http://www.codeproject.com/threads/simplesingleinstanceapp.asp>.
When the first instance of my app receives the notification that
another instance was launched, it shows a dialog displaying the args
received. The problem is that this dialog does not become the
frontmost/active window.
I'm doing something like this:
void CTrayApp::OnSecondInstance(UINT, LPARAM)
{
m_pMainWnd->SetForegroundWindow();
AfxMessageBox(GetSecondInstanceCmdLine(), IDOK);
}
which throws up the dialog but it's behind the active window
(generally the windows explorer file browser).
I guess it makes sense that SetForegroundWindow() isn't doing
anything since (because this is a trap app) the main window
was hidden.
void CTrayApp::InitInstance()
{
...
m_pMainWnd->ShowWindow(SW_HIDE);
}
Now if, in OnSecondInstance(), I do ShowWindow(SW_RESTORE), my app
does come to the foreground, but I have a big blank main window
there now.
Any hints, or is what I'm trying to do even possible? Normally
when my app is launched with args, it needs to import a file and
that requires interaction with the user. That interaction involves
a dialog, so there is a window besides the main window that I can
bring to the foreground, but currently I use a modal dialog (using
DoModal()). If I used a modeless dialog could I just bring that
to the foreground after it is created? I'd rather stick to the
modal dialog for simplicity.
You need to do two things. First, the second instance of your app needs to
call AllowSetForegroundWindow() so that the first instance (another process)
is allowed to bring windows to the top.
Second, the first instance needs to create dialogs with the "Set Foreground"
style. In the dialog editor, this is a property you can set. For
AfxMessageBox(), the second parameter can be MB_OK | MB_SETFOREGROUND. In
your code, you should replace IDOK with MB_OK.
Cheers,
David
.
- Follow-Ups:
- Re: can't bring "single instance" tray app to foreground
- From: Frank Cusack
- Re: can't bring "single instance" tray app to foreground
- References:
- can't bring "single instance" tray app to foreground
- From: Frank Cusack
- can't bring "single instance" tray app to foreground
- Prev by Date: An easy way to Read and Write to SQL Server using MFC???
- Next by Date: Re: can't bring "single instance" tray app to foreground
- Previous by thread: can't bring "single instance" tray app to foreground
- Next by thread: Re: can't bring "single instance" tray app to foreground
- Index(es):
Relevant Pages
|