Dave
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.
You need Karl Petersen's ForceFore which sneaks round the problem by
impersonating the foreground Thread
http://www.mvps.org/vb/code/ForceFore.zip
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
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.