Assalamualaikum, wr,wb..
Membuat menu dengan gambar
Sekarang saya akan menjelaskan cara membuat menu di Visual Basic dengan tambahan gambar pada setiap submenunya. Karna fasilitas standar untuk membuat menu tidak disertai dengan pasilitas tambahan gambar. Baiklah kita langsung saja, simak caranya berikut ini- Buka program Visual basic anda dan mulailah dengan buat form baru
- Klik kanan pada area form dan pilih Editor menu, atau anda bisa memilih Editor menu di menu Tool.
3. Buat daftar menunya, sesuai dengan yang anda butuhkan. Contoh ilustrasinya seperti gambar dibawah ini
4. Lalu masukan objek ImageList dari objek bar, dan tempatkan pada form
5. klik pada objek ImageList tersebut lalu pilih propertis Custom yang ada disebelah kanan
6. Masukan gambar-gambar yang dibutuhkan, urutannya disesuaikan dengan index submenu yang akan diberi gambar, dengan memilih tombol Insert Picture.
7. Buatlah CommondButton dan ganti propertis Captionnya sesuai dengan keinginan anda.
8. Selanjutnya masukan kode pada bagian Declarations
Option Explicit
Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Private Declare Function GetMenuItemID Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Private Declare Function ModifyMenu Lib "user32" Alias "ModifyMenuA" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpString As String) As Long
Private Declare Function SetMenuItemBitmaps Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal hBitmapUnchecked As Long, ByVal hBitmapChecked As Long) As Long
Private Declare Function GetMenuCheckMarkDimensions Lib "user32" () As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function CreateBitmap Lib "gdi32" (ByVal nWidth As Long, ByVal nHeight As Long, ByVal nPlanes As Long, ByVal nBitCount As Long, lpBits As Any) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function PatBlt Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal dwRop As Long) As Long
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Private Declare Function GetMenuItemID Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Private Declare Function ModifyMenu Lib "user32" Alias "ModifyMenuA" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpString As String) As Long
Private Declare Function SetMenuItemBitmaps Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal hBitmapUnchecked As Long, ByVal hBitmapChecked As Long) As Long
Private Declare Function GetMenuCheckMarkDimensions Lib "user32" () As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function CreateBitmap Lib "gdi32" (ByVal nWidth As Long, ByVal nHeight As Long, ByVal nPlanes As Long, ByVal nBitCount As Long, lpBits As Any) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function PatBlt Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal dwRop As Long) As Long
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
9. Lalu double klik pada CommondButton dan masukan kode dibawah ini pada event click.
Private Sub Command1_Click()
Dim i%
Dim hMenu, hSubMenu, menuID, x
hMenu = GetMenu(hwnd)
hSubMenu = GetSubMenu(hMenu, 0)
For i = 1 To 4
menuID = GetMenuItemID(hSubMenu, i - 1)
x = SetMenuItemBitmaps(hMenu, menuID, &H4, img.ListImages(i).Picture, img.ListImages(i).Picture)
Next
menuID = GetMenuItemID(hSubMenu, 5)
x = SetMenuItemBitmaps(hMenu, menuID, 0, img.ListImages(5).Picture, 0&)
End Sub
Dim i%
Dim hMenu, hSubMenu, menuID, x
hMenu = GetMenu(hwnd)
hSubMenu = GetSubMenu(hMenu, 0)
For i = 1 To 4
menuID = GetMenuItemID(hSubMenu, i - 1)
x = SetMenuItemBitmaps(hMenu, menuID, &H4, img.ListImages(i).Picture, img.ListImages(i).Picture)
Next
menuID = GetMenuItemID(hSubMenu, 5)
x = SetMenuItemBitmaps(hMenu, menuID, 0, img.ListImages(5).Picture, 0&)
End Sub
10. Jalankan program dengan menekan tombol F5 pada keyboard, dan lihat hasilnya.. Keren kan...
Ini contoh hasilnya,
Demikianlah Tutorial membuat menu dengan gambar, selamat mencoba.
Wassalam.. n smoga bermanfaat..
0 komentar:
Posting Komentar