Powered in VB to add a pop-up menu

xiaoxiao2021-03-06  65

'Code by 魑 魑 魍魉' Mailto: DemonStudio@hotmail.com

Private Declare Function SendMessage Lib "User32" Alias ​​"SendMessagea" (Byval WMSG As Long, Byval WParam As Long, LParam As Any) As longconst wm_syscommand = & h112

Const mf_checked = & h8 & const mf_append = & h100 & const tpM_LEFTALIGN = & H0 & const tpm_returncmd = & h100

Const mf_disabled = & h2 & const mf_grayed = & h1 & const mf_separe = & h800 & const mf_string = & h0 &

Private Type POINTAPI x As Long y As LongEnd TypePrivate Declare Function CreatePopupMenu Lib "user32" () As LongPrivate 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 LongPrivate Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As LongPrivate Declare Function AppendMenu Lib "user32" Alias ​​"AppendMenuA" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As Any) As LongPrivate Declare Function DestroyMenu Lib "user32" (ByVal hMenu As Long) As LongPrivate Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As LongPrivate Declare Function CreateMenu Lib "User32" () AS Long

Dim Hmenu, SMENU As Long

PRIVATE SUB FORM_LOAD () HMENU = CREATEPOPUPMENU ()

Appendmenu HMENU, MF_STRING, 1, "111111" appendmenu hmenu, mf_string, 2, "211111" appendmenu hmenu, mf_string, 3, "311111" appendmenu HMENU, MF_STRINU HMENU, MF_STRING, 4, "411111"

sMenu = GetSystemMenu (Me.hwnd, False) AppendMenu sMenu, MF_STRING, 99, "About" End SubPrivate Sub Form_MouseUp (Button As Integer, Shift As Integer, x As Single, y As Single) Dim aaa As Long Dim Pt As POINTAPI GetCursorPos Pt if Button = 2 THEN AAA = TrackPopupmenu (Smenu, TPM_LEFTALIGN OR & H100, PT.X, Pt.y, 0, Me.hwnd, Byval 0 & Me.caption = AAA IF AAA = 99 TEN 'MSGBOX "Demon!" ELSE 'SendMessage Me.hwnd, WM_SYSCOMMAND, aaa, 0 & End If Else Me.Caption = TrackPopupMenu (hMenu, TPM_LEFTALIGN Or & H100, Pt.x, Pt.y, 0, Me.hwnd, ByVal 0 &) End IfEnd SubPrivate Sub Form_Unload (Cancel As integer) DestroyMenu Hmenu Destroymenu Smenuend Sub

The effect is as follows:

转载请注明原文地址:https://www.9cbs.com/read-119286.html

New Post(0)