Excel Chart_MouseUp 同一场景下未被困的事件被对应的MouseDown事件所困
Excel Chart_MouseUp event not trapped under the same scenario trapped by the corresponding MouseDown event
我和问题Excel Chart_MouseUp event not trapped一模一样,但是没有给出答案
我对按下 shift-ctrl-左鼠标(触发 MouseDown 事件)、移动鼠标左键(触发 MouseMove 事件)、松开 shift-ctrl-左鼠标(未触发 MouseUp 事件)的顺序感兴趣
怎么可能触发了 MouseDown 事件而相应的 MouseUp 事件没有触发(在相同情况下)!!!
我该如何解决这个问题?
在此先感谢您能给我的帮助
即使我在这里没有收到关于这个主题的答案,希望这对其他人有用,我还是附上了 Peter Thornton 给我的解决方案,我非常感谢给出的建议。
有一个不同的方法,不知道为什么我之前没有想到它 --> 用计时器检查鼠标左键的状态
下面是我专门写的代码
Private Declare PtrSafe Function SetTimer Lib "User32" (ByVal hwnd As LongPtr, ByVal nIDEvent As LongPtr, ByVal uElapse As Long, ByVal lpTimerFunc As LongPtr) As LongPtr
Private Declare PtrSafe Function KillTimer Lib "User32" (ByVal hwnd As LongPtr, ByVal nIDEvent As LongPtr) As Long
Private Declare PtrSafe Function GetAsyncKeyState Lib "User32" (ByVal vKey As Long) As Integer
Private Declare PtrSafe Function GetSystemMetrics32 Lib "User32" Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long
Private Const HWND_ZERO As LongPtr = 0
Private Const TIMER_MILLISECS = 150&
Private Const VK_LBUTTON = &H1 'Left mouse button
Private Const VK_RBUTTON = &H2 'Right mouse button
Private Const SM_SWAPBUTTON = 23& 'Left and Right mouse buttons are logically swapped (Left mouse button is the default Primary button)
Private mTimerID As LongPtr
Public Sub StartTimer()
' call StartTimer in the chart's MouseDown event
If mTimerID Then
Call EndTimer
End If
mTimerID = SetTimer(HWND_ZERO, mTimerID, TIMER_MILLISECS, AddressOf TimerProcedure)
End Sub
Private Function TimerProcedure() As LongPtr
Dim Ch As Chart
Dim obj As Variant
Dim ret As Integer
On Error Resume Next
If mTimerID = 0 Then
Call EndTimer
Else
'map the mouse logical Primary Button to the mouse phisical Left or Right Buttons
If Not GetSystemMetrics32(SM_SWAPBUTTON) Then ret = GetAsyncKeyState(VK_LBUTTON) Else ret = GetAsyncKeyState(VK_RBUTTON)
'the condition is satisfied if the mouse Left Button state is correctly trapped and the Left Button is released
If Not ret And 32768 Then
Call EndTimer
mTimerID = 0
Call UserDefinedChartMouseUp() procedure
End If
End If
End Function
Private Sub EndTimer()
On Error Resume Next
Call KillTimer(HWND_ZERO, mTimerID)
End Sub
我和问题Excel Chart_MouseUp event not trapped一模一样,但是没有给出答案
我对按下 shift-ctrl-左鼠标(触发 MouseDown 事件)、移动鼠标左键(触发 MouseMove 事件)、松开 shift-ctrl-左鼠标(未触发 MouseUp 事件)的顺序感兴趣
怎么可能触发了 MouseDown 事件而相应的 MouseUp 事件没有触发(在相同情况下)!!!
我该如何解决这个问题?
在此先感谢您能给我的帮助
即使我在这里没有收到关于这个主题的答案,希望这对其他人有用,我还是附上了 Peter Thornton 给我的解决方案,我非常感谢给出的建议。
有一个不同的方法,不知道为什么我之前没有想到它 --> 用计时器检查鼠标左键的状态
下面是我专门写的代码
Private Declare PtrSafe Function SetTimer Lib "User32" (ByVal hwnd As LongPtr, ByVal nIDEvent As LongPtr, ByVal uElapse As Long, ByVal lpTimerFunc As LongPtr) As LongPtr
Private Declare PtrSafe Function KillTimer Lib "User32" (ByVal hwnd As LongPtr, ByVal nIDEvent As LongPtr) As Long
Private Declare PtrSafe Function GetAsyncKeyState Lib "User32" (ByVal vKey As Long) As Integer
Private Declare PtrSafe Function GetSystemMetrics32 Lib "User32" Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long
Private Const HWND_ZERO As LongPtr = 0
Private Const TIMER_MILLISECS = 150&
Private Const VK_LBUTTON = &H1 'Left mouse button
Private Const VK_RBUTTON = &H2 'Right mouse button
Private Const SM_SWAPBUTTON = 23& 'Left and Right mouse buttons are logically swapped (Left mouse button is the default Primary button)
Private mTimerID As LongPtr
Public Sub StartTimer()
' call StartTimer in the chart's MouseDown event
If mTimerID Then
Call EndTimer
End If
mTimerID = SetTimer(HWND_ZERO, mTimerID, TIMER_MILLISECS, AddressOf TimerProcedure)
End Sub
Private Function TimerProcedure() As LongPtr
Dim Ch As Chart
Dim obj As Variant
Dim ret As Integer
On Error Resume Next
If mTimerID = 0 Then
Call EndTimer
Else
'map the mouse logical Primary Button to the mouse phisical Left or Right Buttons
If Not GetSystemMetrics32(SM_SWAPBUTTON) Then ret = GetAsyncKeyState(VK_LBUTTON) Else ret = GetAsyncKeyState(VK_RBUTTON)
'the condition is satisfied if the mouse Left Button state is correctly trapped and the Left Button is released
If Not ret And 32768 Then
Call EndTimer
mTimerID = 0
Call UserDefinedChartMouseUp() procedure
End If
End If
End Function
Private Sub EndTimer()
On Error Resume Next
Call KillTimer(HWND_ZERO, mTimerID)
End Sub