Home > Visual Basic > Menonaktifkan tombol Minimize, Maximize dan Close

Menonaktifkan tombol Minimize, Maximize dan Close

January 15, 2010

Yaph kali kita akan membahas artikel sederhana dan mudah-mudahan bisa menambah referensi bagi Anda yang baru belajar vb, kita langsung saja lihat gambar berikut :

dan kita akan mencoba menonaktifkan/mendisable ketiga tombol diatas.

1. Menonaktifkan tombol Minimize

2. Menonaktifkan tombol Maximize

3. Menonaktifkan tombol Close

😀 gimana? Pasti bingung mencari properties CloseButton ? Yaph form di vb memang tidak menyediakan properties CloseButton sehingga untuk menonaktifkan tombol tersebut kita akan menggunakan fungsi API.

Berikut deklarasi lengkap fungsi API, konstanta dan prosedur disableCloseButton :

Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long
Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long

Private Const MF_REMOVE = &H1000&
Private Const MF_BYPOSITION = &H400&

Private Sub disableCloseButton(ByVal hWnd As Long)
    Dim ret1 As Long
    Dim ret2 As Long

    ret1 = GetSystemMenu(hWnd, False)
    If ret1 <> 0 Then
        ret2 = GetMenuItemCount(ret1)
        If ret2 <> 0 Then
            RemoveMenu ret1, ret2 - 1, MF_REMOVE Or MF_BYPOSITION
            RemoveMenu ret1, ret2 - 2, MF_REMOVE Or MF_BYPOSITION
            DrawMenuBar hWnd
        End If
    End If
End Sub

Selanjutnya kita tinggal panggil di event Form_Load :

Private Sub Form_Load()
    Call disableCloseButton(Me.hWnd)
End Sub

Selamat mencoba🙂

  1. August 4, 2010 at 4:07 pm

    nemu juga source kode ini. thanks yups fren….

    • August 4, 2010 at 9:50 pm

      Yuph sama2x🙂

  2. August 24, 2011 at 12:23 am

    mantab om😀

    • August 24, 2011 at 2:13 am

      Yoi om🙂

  1. No trackbacks yet.
Comments are closed.
%d bloggers like this: