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

Function SetForegroundWindow does not prop my application to the foreground!!!!

87 views
Skip to first unread message

James Bond

unread,
Mar 8, 2000, 3:00:00 AM3/8/00
to
Hi everybody,
I have this strange problem and I do not know how to solve it.
When my application is minimized, it's icon is shown in the SysTray.To
maximize it you have to click on that icon. Now, if there are other windows
open on desktop my application does not pop up to the front but it is under
other windows.
I know that my application is in active window because when I maximize it,
there is a flashing (3 seconds) bar on the taskbar.
What am I missing here?
My code:
Public Declare Function SetForegroundWindow Lib "user32" _
(ByVal hwnd As Long) As Long


Case WM_LBUTTONUP '514 restore form window
Me.WindowState = vbNormal
Result = SetForegroundWindow(Me.hwnd)
Me.Show

Result returns 0 so I assume function SetForegroundWindow(Me.hwnd)
executes properly, but still my application is not in foreground.
What's wrong?

007

Eling Homminga

unread,
Mar 9, 2000, 3:00:00 AM3/9/00
to
Maybe swap the statements
Result = SetForegroundWindow(Me.hwnd)
and
Me.Show
will do it for you.
HTH, Eling.

"James Bond" <jb...@her.majesty's.ss> wrote in message
news:6oAx4.1816$K5.3...@news2.rdc1.on.home.com...

James Bond

unread,
Mar 9, 2000, 3:00:00 AM3/9/00
to
Nada.
I tried already everything in reverse order.
I added new function:
Declare Function SetActiveWindow Lib "user32" Alias "SetActiveWindow" (ByVal

hwnd As Long) As Long
and tried to set application to active window.
Nothing works.
I noticed one thing though.
If I left click SysTray icon then my application flashes 3 times on the
taskbar and is not in foreground. You have to click icon on taskbar to move
it foreground.
But if I right click SysTray icon and choose Restore from pop menu then
application shows itself in foreground (not flashing on taskbar).
In both cases I am executing the same code. So this is not my code but
something in Windows.
James
Eling Homminga <ehom...@multiweb.nl> wrote in message
news:8a6o7k$cpq$1...@news.news-service.com...

James Bond

unread,
Mar 9, 2000, 3:00:00 AM3/9/00
to

Olaf Amm

unread,
Apr 4, 2000, 3:00:00 AM4/4/00
to
Hi,

i have exactly the same problem. It works fine with Win95, but not under Win98.
No solution yet. See my posting below for my guess where the problem comes from.

Olaf

---------------------------
Hello,

how can i set a window (from a VB5 program) on top of all others, using VB5 and
Win98? I have tried the "AppActivate" function and the "SetForegroundWindow" API
call, but while that works fine in Win95, in Win98 it does not work under all
circumstances. (Maybe there is a conflict with the "show desktop" function in
the Win98 task bar?)

Thanks for advice,
Olaf

---------------------------
James Bond schrieb:

Neila Nessa

unread,
Apr 4, 2000, 3:00:00 AM4/4/00
to
http://support.microsoft.com/support/kb/articles/Q97/9/25.ASP
(towards the bottom ;-)
Neila

Olaf Amm <Olaf...@fmi.fi> wrote in message news:38EA1710...@fmi.fi...

Gary Milton

unread,
Apr 5, 2000, 3:00:00 AM4/5/00
to
Olaf,

Microsoft changed the way SetForegroundWindow works under Win98 and Win2000.
Under the new operating systems, calling SetForegroundWindow or AppActivate
will simply just cause the window caption and/or taskbar button to flash as
a way af drawing attention to the window without actually putting it to the
foreground.

To get around this, you need to attach the thread of your window to the
thread of the foreground window before calling SetForegroundWindow. If you
do this, SetForeground window will then work as expected in all the
operating systems...

'Declares

Public Declare Function AttachThreadInput Lib "user32" _
(ByVal idAttach As Long, ByVal idAttachTo As Long, _
ByVal fAttach As Long)

Public Declare Function GetWindowThreadProcessId Lib "user32" _
(ByVal hWnd As Long, lpdwProcessId As Long) As Long

Public Declare Function SetForegroundWindowAPI Lib "user32" _
Alias "SetForegroundWindow" (ByVal hWnd As Long) As Long


'Code to force window to foreground on ALL operating systems
'(unless MS change something again!!)

lCurrentWindowThreadID = GetWindowThreadProcessId(Me.hWnd, ByVal 0&)
lForegroundWindowThreadID = GetWindowThreadProcessId(GetForegroundWindow(),
ByVal 0&)

If (lWindowThreadID <> lForegroundWindowThreadID) Then
Call AttachThreadInput(lForegroundWindowThreadID, _
lCurrentWindowThreadID, True) 'Attach thread

Call SetForegroundWindow(Me.hWnd)

Call AttachThreadInput(lForegroundWindowThreadID, _
lCurrentWindowThreadID, False) 'Detach thread
End If

If (GetForegroundWindow() <> Me.hWnd) Then
Call SetForegroundWindow(Me.hWnd)
End If


Hope this helps.

Cheers,
Gary

windows can no longer foc

0 new messages