Private Sub oLblDisplay_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 2 Then Call Pop_menu End If
End SubPrivate Sub Pop_menu() Me.PopupMenu mnuMain
End Sub
他是要替换掉Windows系统菜单吧
Option Explicit 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, lprc As RECT) As Long Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long Private Declare Function GetSystemMenu Lib "user32" (ByVal Hwnd As Long, ByVal bRevert As Long) As Long Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Private Type POINTAPI X As Long Y As Long End Type Public Sub ShowSystemMenu(Hwnd As Long) On Error Resume Next Dim r As RECT Dim p As POINTAPI GetCursorPos p TrackPopupMenu GetSystemMenu(Hwnd, 0&), 0, p.X, p.Y, 0, Hwnd, r End Sub 窗口代码如下: Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 2 Then Call ShowSystemMenu(Me.Hwnd) End Sub
把ShowSystemMenu(Me.Hwnd) 放到按钮的Click事件中
'交换鼠标左右键 ' API函数SwapMouseButton可以很简单的实现鼠标左右键的交换.请看下例 '>>步骤1----建立新工程,在窗体上放置两个CommandButton按钮. '>>步骤2----添加如下代码: Private Declare Function SwapMouseButton Lib "user32" (ByVal bSwap As Long) As LongPrivate Sub Command1_Click() SwapMouseButton 1 End SubPrivate Sub Command2_Click() SwapMouseButton 0 End Sub '>>步骤3----编译运行,点击Command1和Command2,看看鼠标键的交换情况
根据你触摸屏的特点,只用一个键 Private Declare Function SwapMouseButton Lib "user32" (ByVal bSwap As Long) As LongPrivate Sub Command1_Click() SwapMouseButton 1 '切换 End SubPrivate Sub Command2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) SwapMouseButton 0 '恢复
在窗体代码的鼠标右键代码中添加
窗体.mpopupmenu 菜单名
就会显示弹出菜单
If Button = 2 Then
Call Pop_menu
End If
End SubPrivate Sub Pop_menu()
Me.PopupMenu mnuMain
End Sub
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, lprc As RECT) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function GetSystemMenu Lib "user32" (ByVal Hwnd As Long, ByVal bRevert As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type POINTAPI
X As Long
Y As Long
End Type Public Sub ShowSystemMenu(Hwnd As Long)
On Error Resume Next
Dim r As RECT
Dim p As POINTAPI
GetCursorPos p
TrackPopupMenu GetSystemMenu(Hwnd, 0&), 0, p.X, p.Y, 0, Hwnd, r
End Sub
窗口代码如下:
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then Call ShowSystemMenu(Me.Hwnd)
End Sub
' API函数SwapMouseButton可以很简单的实现鼠标左右键的交换.请看下例
'>>步骤1----建立新工程,在窗体上放置两个CommandButton按钮.
'>>步骤2----添加如下代码:
Private Declare Function SwapMouseButton Lib "user32" (ByVal bSwap As Long) As LongPrivate Sub Command1_Click()
SwapMouseButton 1
End SubPrivate Sub Command2_Click()
SwapMouseButton 0
End Sub
'>>步骤3----编译运行,点击Command1和Command2,看看鼠标键的交换情况
Private Declare Function SwapMouseButton Lib "user32" (ByVal bSwap As Long) As LongPrivate Sub Command1_Click()
SwapMouseButton 1 '切换
End SubPrivate Sub Command2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) SwapMouseButton 0 '恢复
End Sub
http://useway.blog.51cto.com/736087/176913
具体代码就不放上来了,就是用全局鼠标钩子监测到有鼠标的点击事件即切换左右键为正常的。