CodeItBetter Programming Another VB Programming Blog

How to Keep a form always on top even when you click on another window.

Posted on September 20, 2011
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
'Forms - How to Keep a form always on top even when you click on another window.
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
Const HWND_TOPMOST = -1
Const SWP_SHOWWINDOW = &H40
 
Private Sub Form_Load()
    Dim TempValue As Long
    Dim MyWidth As Long, MyHeight As Long
    Dim MyTop As Long, MyLeft As Long
    MyWidth = (Screen.Width / 2)
    MyWidth = MyWidth / Screen.TwipsPerPixelX
    MyHeight = Screen.Height / 2
    MyHeight = MyHeight / Screen.TwipsPerPixelY
    MyLeft = Screen.Width / (4 * Screen.TwipsPerPixelX)
    MyTop = Screen.Height / (4 * Screen.TwipsPerPixelY)
    'Call SetWindowPos API function
    TempValue = SetWindowPos(Me.hwnd, HWND_TOPMOST, MyLeft, MyTop, MyWidth, MyHeight, SWP_SHOWWINDOW)
End Sub
Filed under: Forms Leave a comment
Comments (1) Trackbacks (0)
  1. Dunt work dude…..


Leave a comment


 

No trackbacks yet.