用API函式CreatePopupMenu建的右鍵選單為什么在VB里可以,在VBA中是灰的?

Option Explicit
#If Win64 Then
Private Declare PtrSafe 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 PtrSafe Function CreatePopupMenu Lib "user32" () As Long
Private Declare PtrSafe 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 PtrSafe Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare PtrSafe Function DestroyMenu Lib "user32" (ByVal hMenu As Long) As Long
Private Declare PtrSafe Function GetFocus Lib "user32" () As Long
#Else
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 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 DestroyMenu Lib "user32" (ByVal hMenu As Long) As Long
Private Declare Function GetFocus Lib "user32" () As Long
#End If
Dim hMenu As Long
Private Const TPM_RETURNCMD = &H100
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Sub TextBox1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Dim Hwnd As Long
Dim Pt As POINTAPI, ID As Long
Hwnd = GetFocus()
GetCursorPos Pt
If Button = 2 Then
ID = TrackPopupMenu(hMenu, TPM_RETURNCMD, Pt.X, Pt.Y, 0, Hwnd, ByVal 0&)
PopMenuEvent ID
End If
End Sub
Private Sub UserForm_Initialize()
hMenu = CreatePopupMenu()
AppendMenu hMenu, &H0&, ByVal 1&, "選單1"
AppendMenu hMenu, &H0&, ByVal 2&, "選單2"
AppendMenu hMenu, &H0&, ByVal 3&, "選單3"
End Sub
Private Sub PopMenuEvent(ID As Long)
Select Case ID
Case 1
MsgBox "事件1"
Case 2
MsgBox "事件2"
Case 3
MsgBox "事件3"
Case Else
End Select
End Sub
Private Sub UserForm_Terminate()
DestroyMenu hMenu
End Sub
uj5u.com熱心網友回復:
還真有這事。
我用EnableMenuItem( )想把它改為“有效”,也沒起到作用。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/42038.html
標籤:VBA
上一篇:VB下列印不出內容
