Solved

Want to be on top

Posted on 2000-05-01
7
128 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

760 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

19 Experts available now in Live!

Get 1:1 Help Now