Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Want to be on top

Posted on 2000-05-01
7
Medium Priority
?
143 Views
Last Modified: 2010-05-02
I want my program to be "on top".  How do I do this?
0
Comment
Question by:R_N_WARD
7 Comments
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2766399
Here ya go..


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
Private m_TopMost As Boolean

Property Let TopMost(New_Value As Boolean)

  Const HWND_TOPMOST = -1
  Const HWND_NOTOPMOST = -2

  m_TopMost = New_Value
  If New_Value Then
    Call SetWindowPos(Me.hWnd, HWND_TOPMOST, Me.left \ Screen.TwipsPerPixelX, Me.top \ Screen.TwipsPerPixelY, Me.Width \ Screen.TwipsPerPixelX, Me.Height \ Screen.TwipsPerPixelY, 0)
  Else
    Call SetWindowPos(Me.hWnd, HWND_NOTOPMOST, Me.left \ Screen.TwipsPerPixelX, Me.top \ Screen.TwipsPerPixelY, Me.Width \ Screen.TwipsPerPixelX, Me.Height \ Screen.TwipsPerPixelY, 0)
  End If
 
End Property
0
 
LVL 9

Expert Comment

by:Ruchi
ID: 2766400
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
Private Const HWND_TOPMOST = -1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1

Private Sub Command1_Click()
    Call SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
End Sub
0
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2766404
In case it wasn't obvious from my code, you set a form on top by adding the code to the form and then you can use the code "TopMost = True" from within the form or "TheNameOfTheForm.TopMost = True" from anywhere else.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 32

Accepted Solution

by:
Brendt Hess earned 60 total points
ID: 2766413
0
 

Author Comment

by:R_N_WARD
ID: 2766441
I'm sorry VBmaster, but when I put in your code I recived a compile error that stated that only comments may follow an end sub.  If I incorectly placed the code, please tell me so I can give you the points you desive.
0
 
LVL 9

Expert Comment

by:Ruchi
ID: 2766467
Did you try my code?
0
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2767014
In case you want to use the property-solution.. Make sure you go to the Declarations part of the form (top item in first combobox) before you add the code, it will remove that little error.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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

783 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