Tambahkan Program ke menu berikutnya

Senin, 27 Desember 2010
Kode ini menunjukkan kamu bagaimana cara menambahkan menu untuk program lain di visual basic. Satu-satunya hal apa yang akan terjadi ketika kamu mengklik pada item. Untuk membuat sesuatu yang terjadi ketika kamu mengklik pada item kamu harus mempunyai subclass menu (aku akan membantu dengan itu tetapi saya tidak punya kontrol subclassing, atau setidaknya tidak sekarang). Menempatkan ini dalam file *. bas kamu:




Public Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As Any) As Long
Public Declare Function CreatePopupMenu Lib "user32" () As Long
Public Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function GetMenuItemID Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Public Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long
Public Declare Function GetMenuString Lib "user32" Alias "GetMenuStringA" (ByVal hMenu As Long, ByVal wIDItem As Long, ByVal lpString As String, ByVal nMaxCount As Long, ByVal wFlag As Long) As Long
Public Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Public Const MF_ENABLED = &H0&
Public Const MF_POPUP = &H10&
Public Const MF_STRING = &H0&
Public Const WM_NCPAINT = &H85


kemudian kamu masukan kode ini didalam sebuah tombol.

'Cari jendela aplikasi notepad
Dim notepad As Long Dim notepad As Long
notepad = FindWindow("notepad", vbNullString) notepad = FindWindow ("notepad", vbNullString)

'Tambahkan menu kami ke jendela yang kami temukan di atas
Dim notepadMenu As Long Dim notepadMenu As Long
notepadMenu = GetMenu(notepad) notepadMenu = GetMenu (notepad)
Call AppendMenu(notepadMenu, MF_POPUP, newMenu, "Item List") Call AppendMenu (notepadMenu, MF_POPUP, newMenu, "Item List")

'Pastikan bahwa pengguna melihat menu baru segera
Call SendMessage(notepad, WM_NCPAINT, 0&, 0&) Call SendMessage (notepad, WM_NCPAINT, 0 &, 0 &)

Movie Category 1