Solved

Showing a Form As Always on Top

Posted on 2003-10-24
4
666 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
ID: 9617994
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
ID: 9618002
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
ID: 9618516
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
ID: 9618737
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

813 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

11 Experts available now in Live!

Get 1:1 Help Now