Trang 1 trên 1

Thêm Menu vào notepad

Đã gửi: T.Hai 26/05/2008 11:17 am
gửi bởi truongphu
Thủ thuật: Thêm Menu vào notepad
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

  1. 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
  2. Private Declare Function CreatePopupMenu Lib "user32" () As Long
  3. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  4. Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
  5. 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
  6. Const MF_ENABLED = &H0&: Const MF_POPUP = &H10&: Const MF_STRING = &H0&: Const WM_NCPAINT = &H85
  7.  
  8. Private Sub Form_Load()
  9. Shell "Notepad"
  10. Dim newMenu&, notepad&, notepadMenu&
  11. newMenu = CreatePopupMenu
  12. Call AppendMenu(newMenu, MF_ENABLED Or MF_STRING, 0, "Item One")
  13. Call AppendMenu(newMenu, MF_ENABLED Or MF_STRING, 1, "Item Two")
  14. Call AppendMenu(newMenu, MF_ENABLED Or MF_STRING, 2, "Item Three")
  15. notepad = FindWindow("notepad", vbNullString)
  16. notepadMenu = GetMenu(notepad)
  17. Call AppendMenu(notepadMenu, MF_POPUP, newMenu, "Item List")
  18. Call SendMessage(notepad, WM_NCPAINT, 0&, 0&)
  19. Me.Show: Me.FontSize = 12: Me.FontBold = True
  20. Print "Notepad menu has Item List"
  21. End Sub

Re: Thêm Menu vào notepad

Đã gửi: T.Hai 26/05/2008 1:21 pm
gửi bởi clarkkent
Wao ! Thử rồi, hay quá... :D