Bring another window to the top
Brad Wilson -- bradw@netnet.net
Thursday, January 11, 1996
Environment: NT 3.51 + VC++ 4.0 (no patches) + MFC 4.0
I'm having a not-so-fun time trying to figure out something that should be
extremely obvious. In my application, I want to only have one copy running.
In order to facilitate this, I have done this in InitInstance():
CWnd* wnd = FindWindow( 0, "My Application Title" );
if( wnd )
{
// do other fun stuff here ...
return FALSE;
}
The window search works fine. What I'm trying to get to happen, though,
is to activate (bring to front) the first window just before I return
FALSE. I have tried:
wnd -> SetActiveWindow( );
which should work, but doesn't do anything. Likewise:
wnd -> SetFocus( );
doesn't help anything. A call to:
wnd -> SetWindowPos( &wndTop, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
does bring the window to the foreground, but does not make that window
active. I have tried any number of combinations, but I just CANNOT
bring the window to the front of the Z-order and make it active. I
have tried running the application from File Manager (thinking VC++
might've been doing some focus-trickery), and File Manager minimizes
itself but its icon remains active (the window is on the screen and
visible, but inactive).
HELP! Why does this plague me so? :-)
Brad
--
class CBradWilson : public CWorldWatchProgrammingTeam {
public:
CString GetInetAddr() { return CString("bradw@exptech.com"); }
CString GetPhone() { return CString("+1 (810) 620-9803"); }
CString GetURL() { return CString("http://www.exptech.com"); }
CString GetDisclaimer() { return CString("All I say is fact :-p"); }
};
"Money is the living power that dies without its root. Money will not serve
the mind that cannot match it. Is this the reason why you call it evil?"
Brad Wilson -- bradw@netnet.net
Tuesday, January 16, 1996
>> Try SetForegroundWindow() I think it worked for me once.
On a hunch, just after I sent the message out, I found SetForegoundWindow()
by looking at the Win32 definition of SetActiveWindow(), write provided
this advice (which MFC did not):
"The SetActiveWindow function activates a window, but it only brings the
window to the foreground if the window is owned by the thread making the
call to SetActiveWindow().
"The SetForegroundWindow function, on the other hand, activates a window
and forces the thread that created the window into the foreground."
Since all the other times I used SetActiveWindow it was in the context
of the correct thread, I never knew its limitations.
Thanks!
Brad
--
class CBradWilson : public CWorldWatchProgrammingTeam {
public:
CString GetInetAddr() { return CString("bradw@exptech.com"); }
CString GetPhone() { return CString("+1 (810) 620-9803"); }
CString GetURL() { return CString("http://www.exptech.com"); }
CString GetDisclaimer() { return CString("All I say is fact :-p"); }
};
// QOTW: "There is no right or wrong ... just popular opinion"
| Вернуться в корень Архива
|