Modify the system menu, mouse right health bullet, execute system menu event

zhaozj2021-02-16  45

(for reference only)

Add a new item to the system menu, and perform the corresponding event, pop up the system menu in the form, and execute the event 'form Option Explicit

Private Sub Form_Load () On Error Resume Next lhSysMenu = GetSystemMenu (hwnd, 0 &) lRet = AppendMenu (lhSysMenu, MF_SEPARATOR, 0 &, vbNullString) lRet = AppendMenu (lhSysMenu, MF_STRING, IDM_ABOUT, "About ...") Show ProcOld = SetWindowLong (HWND, GWL_WNDPROC, Addressof WINDOWPROC) End Sub

Private Sub Form_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single) Dim r As RECT Dim p As POINTAPI If Button = vbRightButton Then GetCursorPos p TrackPopupMenu lhSysMenu, 0, pX, pY, 0, Me.hwnd, R end ifend sub

Private Sub Form_Unload (Cancel AS Integer) Setwindowlong Hwnd, GWL_WndProc, Procoldend Sub

'------------------------------------- ------------ 'Module Option Explicitpublic Declare Function TRACKPOPMENU LIB "User32" (Byval WFlags As Long, Byval X As Long, Byval Y As Long, BYVAL NRESERVED AS Long, ByVal hwnd As Long, lprc As RECT) As LongPublic Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As LongPublic Declare Function SetWindowLong Lib "user32" Alias ​​"SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long ) As LongPublic Declare Function CallWindowProc Lib "user32" Alias ​​"CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As LongPublic Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As String) As LongPublic Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As LongPublic Type RECT Le ft As Long Top As Long Right As Long Bottom As LongEnd TypePublic Type POINTAPI X As Long Y As LongEnd TypePublic ProcOld As LongPublic Const TPM_LEFTALIGN = & H0 & Public Const WM_SYSCOMMAND = & H112Public Const MF_SEPARATOR = & H800 & Public Const MF_STRING = & H0 & Public Const GWL_WNDPROC = (-4) Public Const IDM_ABOUT as long = 1010public const wm_command = & h111public lhsysmenu as long, Lret As Long

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

New Post(0)