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
"James Bond" <jb...@her.majesty's.ss> wrote in message
news:6oAx4.1816$K5.3...@news2.rdc1.on.home.com...
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:
Olaf Amm <Olaf...@fmi.fi> wrote in message news:38EA1710...@fmi.fi...
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