Solved

Showing a Form As Always on Top

Posted on 2003-10-24
4
664 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

863 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

20 Experts available now in Live!

Get 1:1 Help Now