Tác giả: truongphu Sưu tầm và chỉnh sửa
Mô tả: Thêm Menu vào notepad. Chắc là quanghoa đang cần
Mã: Chọn hết
- Private 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
- Private Declare Function CreatePopupMenu Lib "user32" () As Long
- Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
- Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
- Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
- Const MF_ENABLED = &H0&: Const MF_POPUP = &H10&: Const MF_STRING = &H0&: Const WM_NCPAINT = &H85
-
- Private Sub Form_Load()
- Shell "Notepad"
- Dim newMenu&, notepad&, notepadMenu&
- newMenu = CreatePopupMenu
- Call AppendMenu(newMenu, MF_ENABLED Or MF_STRING, 0, "Item One")
- Call AppendMenu(newMenu, MF_ENABLED Or MF_STRING, 1, "Item Two")
- Call AppendMenu(newMenu, MF_ENABLED Or MF_STRING, 2, "Item Three")
- notepad = FindWindow("notepad", vbNullString)
- notepadMenu = GetMenu(notepad)
- Call AppendMenu(notepadMenu, MF_POPUP, newMenu, "Item List")
- Call SendMessage(notepad, WM_NCPAINT, 0&, 0&)
- Me.Show: Me.FontSize = 12: Me.FontBold = True
- Print "Notepad menu has Item List"
- End Sub