Can anyone help me make my program be on the top of all the other programs?
Printable View
Can anyone help me make my program be on the top of all the other programs?
Option Explicit
Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal HwndInsertAfter As Long, ByVal X As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const SWP_SHOWWINDOW = &H40
Private Const SWP_NOACTIVATE = &H10
Public Enum WindowPos
vbtopmost = -1&
vbNotTopMost = -2&
End Enum
Public Sub SetFormPosition(hWnd As Long, Position As WindowPos)
Const wFlags As Long = SWP_NOMOVE Or SWP_NOSIZE Or SWP_SHOWWINDOW Or SWP_NOACTIVATE
If Position = vbtopmost Or Position = vbNotTopMost Then
SetWindowPos hWnd, Position, 0, 0, 0, 0, wFlags
End If
End Sub
I know two ways of doing that.
1. Me.Zorder
2. Public Declare Function SetForegroundWindow lib "user32" Alias "SetForegroundWindow" (ByVal hwnd As Long) As Long
SetForegroundWindow(Me.Hwnd)
Hope will be helpful..
Quote:
Originally posted by iataman
I know two ways of doing that.
1. Me.Zorder
2. Public Declare Function SetForegroundWindow lib "user32" Alias "SetForegroundWindow" (ByVal hwnd As Long) As Long
SetForegroundWindow(Me.Hwnd)
Hope will be helpful..
Me.ZOrder will only putit on top of other forms and not other programs. This won't keep it on top.
SetForegroundWindow api function will only give the program focus putting it on top, but will not keep it on top either.