Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

BringWindowToTop???

181 views
Skip to first unread message

Dave

unread,
Oct 22, 2006, 2:32:18 PM10/22/06
to
I naively assumed BringWindowToTop would do just that but it seems to do
nothing. I have got a mini application with WinSock to communicate on my
internal network. I want the receiving window to pop up when a message is
received and I used BringWindowToTop but it stayed at the bottom! I also
tried SetWindowPos with various parameters - what can I do to get my window
to pop up??

Dave


expvb

unread,
Oct 22, 2006, 6:16:54 PM10/22/06
to
"Dave" <dave...@btinternet.com> wrote in message
news:Ogukohg9...@TK2MSFTNGP05.phx.gbl...

Windows generally doesn't let you switch your application into the
foreground, as if the user pressed Alt+Tab. It's called hijacking the user
interface. Imagine if viruses utilized it. Use either "Me.ZOrder", or
SetForegroundWindow(Recommended). I think when you use SetForegroundWindow,
the window is either activated, or flashed in task bar if the user was
working on another application.


J French

unread,
Oct 23, 2006, 2:19:06 AM10/23/06
to
On Sun, 22 Oct 2006 19:32:18 +0100, "Dave" <dave...@btinternet.com>
wrote:

You need Karl Petersen's ForceFore which sneaks round the problem by
impersonating the foreground Thread

http://www.mvps.org/vb/code/ForceFore.zip


Dave

unread,
Oct 23, 2006, 2:54:28 AM10/23/06
to

"Dave" <dave...@btinternet.com> wrote in message
news:Ogukohg9...@TK2MSFTNGP05.phx.gbl...

Thanks for the responses. SetForegroundWindow is no good as it just flashes
in the task bar as was said.

I found the way to do it for those interested. You call SetWinPos with
HWND_TOPMOST. That automatically activates the window. However, it would
mean the window would stay on top permanently. Therefore, immediately after
that call you call SetWinPos with HWND_NOTOPMOST which leaves the window on
top, but allows it to go down the z-order.

That works, but can anyone see any problems with doing it??

Dave


Murtuza

unread,
Oct 26, 2006, 2:44:36 PM10/26/06
to
You can use SetForeGroundWindow for this purpose. There are some wired
complexities with this function. To bring up a window using
setforegroundwindo one of these conditions must be satisfied
i.e. Your window should be the foreground window or
Your window should have keyboard input focus or
The window you are trying to bring up should be in the same
process as your window or
Your window process and the window process of target window
should share the same keyboard input status.

To accomplish the task with these constrains, you can go around this
trick

- Obtain the handle to the window you want to bring up using GetWindow
or FindWindow or any such API Call

- Find out the process id of the window you want to bring up as well as
the process id of your window using GetWindowThreadProcessId API call

- Attach the input status of your window to the target window using the
thread ID of both the windows you derived in step 2 with help of
AttachThreadInput api call

- invoke SetForegroundWindow on the target window, this time, it should
bring the window up and activate it

- Detach the input status of both threads using AttachThreadInput API
by setting the parameter to 0

Thats it, you are done.

One more simple way is to send two messages in sequence to the target
window using the SendMessage API

SendMessage(TargetWindowHandle,&HF120&,&H112,0&)
SendMessage(TargetWindowHandle,&H6,0,1)

These are WM_SYSCOMMAND paired with SC_RESTORE and the second is
WM_ACTIVATE.

If you are still facing the problem, please feel free to ask again.

0 new messages