Solved

Want to be on top

Posted on 2000-05-01
7
131 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 32

Accepted Solution

by:
bhess1 earned 30 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS Date Picker 64 bit 32 bit issue 12 61
RUNRMTCMD from AS/400 12 69
Powerpoint 2013: Change cell reference in excel link 3 84
Problem to line 23 55
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…

830 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