Click to See Complete Forum and Search --> : Keeping a shelled app window on top
Rebis
Dec 8th, 2000, 09:02 AM
I know how to keep a window on top if it is in the same app
as the code (using API calls), and I know how to shell to
an app, but I don't know how to keep a window from an app
that isn't the the one with the code in on top.
Any ideas, anyone?
Use the SetWindowPos api function, same as with making your own form on top.
'Tip by Sam Huggill
Private Declare Function SetWindowPos Lib "user32" (ByVal _
hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As _
Long, y, ByVal cx As Long, ByVal cy As Long, ByVal wFlags _
As Long) As Long
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOACTIVATE = &H10
Private Const SWP_SHOWWINDOW = &H40
Private Const TOPMOST_FLAGS = SWP_NOMOVE Or SWP_NOSIZE
'Resets the windows position in the ZOrder
Private Sub MakeNormal(lngHwnd As Long)
SetWindowPos lngHwnd, HWND_NOTOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS
End Sub
'Places the window at the top of the ZOrder
'and keeps it there
Private Sub MakeTopMost(lngHwnd As Long)
SetWindowPos lngHwnd, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS
End Sub
Rebis
Dec 11th, 2000, 04:08 AM
I _know_ how to use SetWindowPos, I don't know how to get the hWnd for a window that is not part of the program.
Use the FindWindow api function.
Private Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" (ByVal lpClassName As String, ByVal _
lpWindowName As String) As Long
Private Sub Command1_Click()
'hWin = FindWindow(Class, Caption)
hWin = FindWindow("SciCalc", "Calculator")
If hWin <> 0 Then Msgbox "hWnd: " & hWin
End Sub
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.