Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Showing a Form As Always on Top

Posted on 2003-10-24
4
Medium Priority
?
698 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
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…
Suggested Courses

650 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