ActiveX untuk Form “Agar Selalu di Atas”

Kali ini saya akan mencoba membuat sebuah ActiveX utnuk form “Agar Selalu di Atas”. Dari namanya saja sudah jelas nantinya bertujuan agar form yg ‘ditempeli’ ActiveX ini dapat diatur agar tampil selalu di atas (Alway on Top)

Buat project pada “ActiveX Control”, ubah nama” Project1″ menjadi “INOCHISoftware”. Ubah nama “UserControl1” menjadi “inochiOnTop”. Ubah properti UserControl “InvisibleAtRuntime” dari “False” menjadi “True”.

Tambahkan sebuah class module. Ubah nama menjadi “clsForm”. Ubah properti classmodule “Instancing” menjadi “1-Private”. Ketik kode di bawah ini di class module (clsForm)!

Option Explicit

Private WithEvents mParentForm As Form

Public Property Set ParentForm(vData As Form)
    Set mParentForm = vData
End Property

Public Property Get ParentForm() As Form
    Set ParentForm = mParentForm
End Property

Ketik kode di bawah ini di UserControl (inochiOnTop):

Option Explicit

Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, _
ByVal hWndInsertAfter As Long, ByVal x As Long, y, ByVal cx As Long, _
ByVal cy As Long, ByVal wFlags As Long) As Long

Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOACTIVATE = &H10
Private Const SWP_SHOWWINDOW = &H40
Private Const TOPMOST_FLAGS = SWP_NOMOVE Or SWP_NOSIZE
Private m_OnTop As Boolean
Private m_Form As New clsForm

Private Sub MakeNormal(lngHwnd As Long)
    SetWindowPos lngHwnd, HWND_NOTOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS
End Sub

Private Sub MakeTopMost(lngHwnd As Long)
    SetWindowPos lngHwnd, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS
End Sub

Property Get OnTop() As Boolean
    OnTop = m_OnTop
End Property

Property Let OnTop(ByVal vNewValue As Boolean)
    m_OnTop = vNewValue
    Set m_Form.ParentForm = Parent
    If m_OnTop = True Then
        MakeTopMost m_Form.ParentForm.hwnd
    Else
        MakeNormal m_Form.ParentForm.hwnd
    End If
End Property

Private Sub UserControl_Initialize()
    m_OnTop = True
End Sub

Compile menjadi “INOCHISoftware.ocx”. Buatlah projek baru, coba terapkan ActiveX buatan Anda tadi!
Contoh penerapan:

Sisipkan kontrol inochiOnTop di Form, kemudian ketik kode di bawah ini:

Private Sub Command1_Click()
    Static bytGanti As Byte
    If bytGanti = 0 Then
        inochiOnTop1.OnTop = True
        bytGanti = 1
    Else
        inochiOnTop1.OnTop = False
        bytGanti = 0
    End If
End Sub

Contoh bisa diambil di sini:

OnTop

Perihal Novian Agung
Pengangguran

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: