API更改系統(tǒng)菜單條目
發(fā)表時間:2024-06-13 來源:明輝站整理相關軟件相關文章人氣:
[摘要]一個運用API 更改系統(tǒng)菜單,復制系統(tǒng)菜單的例子。(需要注意的是:如果要響應菜單項的單擊事件,可能要用到鉤子函數(shù)和更多的代碼)Option ExplicitPrivate Declare Function TrackPopupMenu Lib "user32" (ByVal h...
一個運用API 更改系統(tǒng)菜單,復制系統(tǒng)菜單的例子。(需要注意的是:如果要響應菜單項的單擊事件,可能要用到鉤子函數(shù)和更多的代碼)
Option Explicit
Private Declare Function TrackPopupMenu Lib "user32" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal x As Long, ByVal y As Long, ByVal nReserved As Long, ByVal hwnd As Long, ByVal lprc As Any) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) 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 Any) As Long
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Declare Function InsertMenu Lib "user32" Alias "InsertMenuA" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As Any) As Long
Private Const TPM_LEFTALIGN = &H0&
Private hsysmenu As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Function num(i As Integer) As String
num = Mid(" 長恨歌 漢皇重色思傾國,御宇多年求不得。楊家有女初長成,養(yǎng)在深閨人未識。天生麗質難自棄,一朝選在君王側;仨恍Π倜纳,六宮粉黛無顏色。春寒賜浴華清池,溫泉水滑洗凝脂。侍兒扶起嬌無力,始是新承恩澤時。云鬢花顏金步搖,芙蓉帳暖度春宵。春宵苦短日高起,從此君王不早朝。", 8 * i + 1, 8)
End Function
Private Sub Form_Load()
Dim i As Integer
hsysmenu = GetSystemMenu(hwnd, False) '系統(tǒng)菜單句柄
InsertMenu hsysmenu, 0, &H800, &H0, "" '加入分割符
For i = 0 To 5
ModifyMenu hsysmenu, i, &H4410, 0, num(i+1) '改變菜單條目
Next
For i = 6 To 15
InsertMenu hsysmenu, i, &H400, &H0, num(i+1) '插入菜單條目
Next 'i=6 對應條目為關閉按鈕,如此設置是為了留下該條目
InsertMenu hsysmenu, 0, &H800, &H0, "" '加入分割符
InsertMenu hsysmenu, 0, &H400, &H0, num(0)
Me.Move Screen.Width / 2 - 3000, Screen.Height / 2 - 2000, 6000, 4000 ' 窗體居中
Me.Caption = "請用鼠標右鍵調出系統(tǒng)菜單。!"
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim Pts As POINTAPI
GetCursorPos Pts '獲取鼠標位置
If Button = 2 Then TrackPopupMenu hsysmenu, TPM_LEFTALIGN, Pts.x, Pts.y, 0, Me.hwnd, ByVal 0&
'在鼠標點擊處彈出更改后的系統(tǒng)菜單
End Sub