Home > Software engineering >  Why the right-click menu CreatePopupMenu built using API function in VB can, in the VBA is grey?
Why the right-click menu CreatePopupMenu built using API function in VB can, in the VBA is grey?

Time:09-17

Why the right-click menu CreatePopupMenu built using API function in VB can, in the VBA is grey?


 
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
# the 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=& amp; H100
Private Type POINTAPI
X As Long
Y As Long
End Type


Private Sub TextBox1_MouseUp (ByVal Button As an Integer, ByVal Shift As an Integer, ByVal X As Single, ByVal Y As Single)
Dim Hwnd As Long
Dim Pt As POINTAPI, ID As Long
The Hwnd=GetFocus ()
The GetCursorPos Pt
If the Button=2 Then
ID=TrackPopupMenu (hMenu TPM_RETURNCMD, Pt. X, Pt. J Y, 0, Hwnd, ByVal 0 & amp;)
PopMenuEvent ID
End the If
End Sub

Private Sub UserForm_Initialize ()
HMenu=CreatePopupMenu ()
The AppendMenu hMenu, & amp; H0 & amp; , ByVal 1 & amp; , "menu 1
"The AppendMenu hMenu, & amp; H0 & amp; , ByVal 2 & amp; 2 "menu.
The AppendMenu hMenu, & amp; H0 & amp; , ByVal 3 & amp; 3 "menu.
End Sub

Private Sub PopMenuEvent (ID As Long)
Select a Case ID
Case 1
MsgBox "event 1
"Case 2
MsgBox "event 2"
Case 3
MsgBox "event 3"
In Case the Else
End the Select

End Sub

Private Sub UserForm_Terminate ()
DestroyMenu hMenu
End Sub

CodePudding user response:

Do have this,


I use EnableMenuItem () want to change it to "effective", also did not play a role,
  •  Tags:  
  • VBA
  • Related