Link to home
Start Free TrialLog in
Avatar of wilsoada
wilsoada

asked on

Showing a Form As Always on Top

I dont know if this is possible I can not figure out how to do it at least. I am showing frmInfo.frm as frmInfo.Show but I don't want to hide the main form it is generated from. I want the frmInfo.frm to be on to of all other open applications and explorer browsers no matter what until the user closes the form. But I still want to be able to access the other forms. If this isn't very clear leave me a comment and I will try to clear it up better for you. basically I am trying to show information on a small form that is always visible until the user doesnt want it anymore but still be able to type in other applications.
Avatar of bobbit31
bobbit31
Flag of United States of America image

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 = 2
Private Const SWP_NOSIZE = 1
Private Const Flags = SWP_NOMOVE Or SWP_NOSIZE
Private Const HWND_TOP = 0
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2


Use the following:

Call SetWindowPos(Me.hwnd, HWND_TOP, 0, 0, 0, 0, Flags)
it'd be better if you put the following in a module though:

Public 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

Public Const SWP_NOMOVE = 2
Public Const SWP_NOSIZE = 1
Public Const Flags = SWP_NOMOVE Or SWP_NOSIZE
Public Const HWND_TOP = 0
Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2


then you can still do this in your Form_Load event

Call SetWindowPos(Me.hwnd, HWND_TOP, 0,0,0,0, Flags)
ASKER CERTIFIED SOLUTION
Avatar of Sethi
Sethi
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fantasy1001
fantasy1001

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 LongGlobal
Const SWP_NOMOVE As Long = 2Global
Const SWP_NOSIZE As Long = 1Global
Const FLAGS = SWP_NOMOVE Or SWP_NOSIZEGlobal
Const HWND_TOPMOST As Long = -1Global
Const HWND_NOTOPMOST As Long = -2

SetWindowPos Form.hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS