这个要先取得每个菜单项的句柄,再在Hook中判断才行.

解决方案 »

  1.   


      我有个更好的:在frmMain中添加一个Command1:Option Explicit
    DefLng A-Z
    Private Sub Command1_Click()Dim lprc As RECT'// Show the system menu below this command button
    Call GetWindowRect(Command1.hWnd, lprc)
    Call SendMessage(Me.hWnd, WM_GETSYSMENU, 0, ByVal MAKELONG(lprc.Left, lprc.Bottom + 2))
    End SubPrivate Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)Dim lppt As POINTAPI'// Show the system menu at the cursor position
    '// Note that the coordinates the message accepts are relative to the screen
    If Button = vbRightButton Then
        Call GetCursorPos(lppt)
        Call SendMessage(Me.hWnd, WM_GETSYSMENU, 0, ByVal MAKELONG(lppt.X, lppt.Y))
    End IfEnd Sub以下在模块中:Option Explicit
    DefLng A-ZType RECT
       Left As Long
       Top As Long
       Right As Long
       Bottom As Long
    End TypeType POINTAPI
        X As Long
        Y As Long
    End TypeDeclare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" (lpDest As Any, lpSource As Any, ByVal nCount As Long)
    Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long'// Undocumented window message.
    Public Const WM_GETSYSMENU = &H313Public Function LOWORD(dwValue As Long) As Long
        CopyMemory LOWORD, dwValue, 2
    End FunctionPublic Function MAKELONG(wLow As Long, wHigh As Long) As Long
        MAKELONG = LOWORD(wLow) Or (&H10000 * LOWORD(wHigh))
    End Function
      

  2.   

    要响应系统菜单的事件,需处理窗口的消息函数,就是很多人吹嘘的子分类技术,你可以到各论坛看看,或查API的书籍!