Discussion:
Windows.SetForeGroundWindow() method not working as assumed
(too old to reply)
Tim R.
2007-11-20 18:50:05 UTC
Permalink
Raw Message
Good afternoon all,

I am using the API method Windows.SetForeGroundMethod() to attempt to
set make my program become the focused (and seen) form on my screen. I
have entered the code as Windows.SetForeGroundWindow(Form1.handle);
and it is obviously doing something, because the tab in the toolbox
flashes, but it does not come to the foreground of the screen (like
when someone messages you on MSN messenger. The window flashes, but
does not actually come to the foreground). Is there any API method
that I have to use to force the program to come to the foreground?

Thanks for the help

Tim
b***@hotmail.com
2008-01-08 21:35:46 UTC
Permalink
Raw Message
Post by Tim R.
Good afternoon all,
I am using the API method Windows.SetForeGroundMethod() to attempt to
set make my program become the focused (and seen) form on my screen. I
have entered the code as Windows.SetForeGroundWindow(Form1.handle);
and it is obviously doing something, because the tab in the toolbox
flashes, but it does not come to the foreground of the screen (like
when someone messages you on MSN messenger. The window flashes, but
does not actually come to the foreground). Is there any API method
that I have to use to force the program to come to the foreground?
Thanks for the help
Tim
The documentation for the SetForegroundWindow() states the following:


To force a window to the foreground, however, use
SetForegroundWindow(). SetForegroundWindow() activates a window and
forces the window into the foreground.

NOTE: If the target window was not created by the calling thread, the
active window status of the calling thread is set to NULL, and the
active window status of the thread that created the target window is
set to the target window.

Read the NOTE above carefully. Windows OS assign a default window to
each thread. The state of this window may be set to NULL and the
status of the main thread's window to what it was before - not-
foreground.

In fact, Microsoft has altered the behavior of SetForegroundWindow()
under Windows 2000 ("The OS Formerly
Known as NT5"). If the application is currently in the foreground,
this API still behaves as it always did. Then one could bring any
window to the front--both those belonging to one's own application and
those of other applications. However, if one's app doesn't hold the
foreground [which is our case] newer versions of Windows simply call
FlashWindow() to achieve the flashing effect.

Look at the VB code here: http://vb.mvps.org/articles/ap199902.pdf
Loading...