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
:D 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 :
12345678910111213141516171819202122
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 :
123
Private Sub Form_Load()
Call disableCloseButton(Me.hWnd)
End Sub