Monday, May 28, 2012

Menjadikan Form Berada Paling Depan

Fungsi di bawah ini merupakana cara menampilkan form agar berada paling depan (Form On Top/Top Most)
Option Explicit 

Public 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

Public Const
HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const SWP_NOACTIVATE = &H10
Public Const SWP_SHOWWINDOW = &H40
Public Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE

Public Function
TopMost(frm As Form, bTopMost As Boolean)
If bTopMost Then
Call
SetWindowPos(frm.hWnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
Else
Call
SetWindowPos(frm.hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS)
End If
End Function
Contoh penggunaan menjadikan form berada paling depan
Private Sub Form_Load()
TopMost Me, True
End Sub