Solved

Showing a Form As Always on Top

Posted on 2003-10-24
4
659 Views
Last Modified: 2010-05-19
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.
0
Comment
Question by:wilsoada
  • 2
4 Comments
 
LVL 18

Expert Comment

by:bobbit31
Comment Utility
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)
0
 
LVL 18

Expert Comment

by:bobbit31
Comment Utility
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)
0
 
LVL 18

Accepted Solution

by:
Sethi earned 125 total points
Comment Utility
Option Explicit

Private Const HWND_BOTTOM = 1
Private Const HWND_NOTOPMOST = -2
Private Const HWND_TOP = 0
Private Const HWND_TOPMOST = -1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1

Private Declare Function GetActiveWindow Lib "user32" () As Long

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

'Pass the form's hwnd.  The first routine ensures the form will
'always be on top.  The second reverts back to the normal state


Public Sub MakeWindowAlwaysTop(hwnd As Long)
 SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, _
   SWP_NOMOVE + SWP_NOSIZE
End Sub

Public Sub MakeWindowNotTop(hwnd As Long)
  SetWindowPos hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, _
     SWP_NOMOVE + SWP_NOSIZE
End Sub
0
 
LVL 5

Expert Comment

by:fantasy1001
Comment Utility
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
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now