Show form on top of everything

Hello all,

I need to have a VB6 form on top of all application open on my PC, to be sure that i see it.

So when i'm calling the form, i'm using this code:
Call ShowDialogInformation(txtHeader, txtMessage)

The form as this code:
Private Sub Form_Load()
 
  ' Make this form hidden until the client
  ' informs it to display on the screen.
  Me.Hide
 
  ' Set the header color
  LabelHeader.ForeColor = vbRed
  LabelHeader.Caption = vbNullString
 
  ' Set the message color
  LabelMessage.ForeColor = vbBlack
  LabelMessage.Caption = vbNullString
 
 
End Sub


How can i do this please.

Thanks for your help
LVL 11
Wilder1626Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Death259Commented:
The attribute you are wanting is TopMost. You can set this in the form properties, or programmatically by using FormName.TopMost = true
0
Death259Commented:
You could probably also just do Me.TopMost = true
0
Wilder1626Author Commented:
Hello,
I did it, but i have a compile error: Method or Data not found

Private Sub Form_Load()
Form1.TopMost = True


  ' Make this form hidden until the client
  ' informs it to display on the screen..
  Me.Hide
 
  ' Set the header color
  LabelHeader.ForeColor = vbRed
  LabelHeader.Caption = vbNullString
 
  ' Set the message color
  LabelMessage.ForeColor = vbBlack
  LabelMessage.Caption = vbNullString
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Death259Commented:
Try it with Me.TopMost = True
0
Wilder1626Author Commented:
I have the same error.

It highlight: .TopMost =
0
Brook BraswellApplication Development ManagerCommented:
if your code is as such
Private Sub Form_Load()
Form1.TopMost = True
then should not the code be Form rather than Form1?

Private Sub Form_Load()
Form.TopMost = True

0
RobinSoftware EngineerCommented:
In VB6, the form does not have a .TopMost property.

Use the SetWindowPos API function for this:
Private Const SWP_NOMOVE = 2
Private Const SWP_NOSIZE = 1
Private Const Flags = SWP_NOMOVE Or SWP_NOSIZE
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
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

Public Sub SetWindowOnTop(ByVal p_hWnd As Long, Optional ByVal p_bOnTop As Boolean = True)
    If p_bOnTop Then
        Call SetWindowPos(p_hWnd, HWND_TOPMOST, 0, 0, 0, 0, Flags)
    Else
        Call SetWindowPos(p_hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, Flags)
    End If
End Sub

Open in new window

0
RobinSoftware EngineerCommented:
And call it like:

Call SetWindowOnTop(Me.hWnd, True)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nffvrxqgrcfqvvcCommented:

How To Create a Form That Always Stays on Top
http://support.microsoft.com/kb/184297
Add the microsoft code to a module. Then in the Form_Load() make the call..
call SetTopMostWindow(Me.hwnd, True)

0
nffvrxqgrcfqvvcCommented:
Sorry robin... I never refreshed.
0
Wilder1626Author Commented:
I have put this code under General Declaration:
Private Const SWP_NOMOVE = 2
Private Const SWP_NOSIZE = 1
Private Const Flags = SWP_NOMOVE Or SWP_NOSIZE
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
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

Public Sub SetWindowOnTop(ByVal p_hWnd As Long, Optional ByVal p_bOnTop As Boolean = True)
    If p_bOnTop Then
        Call SetWindowPos(p_hWnd, HWND_TOPMOST, 0, 0, 0, 0, Flags)
    Else
        Call SetWindowPos(p_hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, Flags)
    End If
End Sub


After, under:
Private Sub Form_Load()
Me.TopMost = True


But again, same error.
0
Death259Commented:
Get rid of the me.topmost
0
RobinSoftware EngineerCommented:
@egl1044: no problem.

Set the form topmost by calling:

Private Sub Form_Load()
   Call SetWindowOnTop(Me.hWnd, True)
End Sub

0
Wilder1626Author Commented:
Ok, now, no more errors but it is not on top of everything. It's always under all oder form.

I really dont understand.

I've tried both solution, and same results

0
nffvrxqgrcfqvvcCommented:
Make sure you test it as an executable and not from the VB IDE. Do you see the same behavior?
0
Wilder1626Author Commented:
Yes yes yes.

It's perfect.

Thanks to both of you.
0
Wilder1626Author Commented:
Thanks to both of you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.