Solved

Want to be on top

Posted on 2000-05-01
7
129 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
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.

 
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

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

911 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