Wir verwenden GMA MouseHook für ein ausgeklügeltes Outlook VSTO AddIn. Wegen der Kompliziertheit unseres AddIns haben wir uns bei bestimmten Problemen irgendwie in eine Ecke entwickelt.MouseUp/MouseClick nach MouseDown verhindern
Unser Problem: Wir haben Outlook maximiert und das Mail.Compose-Fenster ist darüber hinaus maximiert. Wenn wir auf die Schließen-Schaltfläche im Mail.Compose-Fenster klicken, rufen wir im MouseDown-Event den eigentlichen Fensterabschluss auf. Jetzt wird das Mail.Compose-Fenster geschlossen und die MouseUp + MouseClick-Ereignisse werden auf die Schließen-Schaltfläche des zugrunde liegenden Outlook-Hauptfensters ausgelöst.
Ich habe versucht, die MouseEventArgs 'e.Handled = True, aber es führt immer noch die MouseUp + MouseClick Ereignisse nach.
Irgendwelche Ideen, wie man das löst?
EDIT Danke mehrdad safa für mich in die richtige Richtung! Hier ist, wie ich mein Problem gelöst:
Zuerst habe ich (zB kopiert und aus dem Internet eingefügt) diese Klasse:
Imports System.Runtime.InteropServices
Public Class MouseInterceptor
Public Delegate Function CallBack(_
ByVal nCode As Integer, _
ByVal wParam As IntPtr, _
ByVal lParam As IntPtr) As Integer
'Declare the mouse hook constant.
'For other hook types, obtain these values from Winuser.h in Microsoft SDK.
Dim WH_MOUSE As Integer = 7
Shared hHook As Integer = 0
'Keep the reference so that the delegate is not garbage collected.
Private hookproc As CallBack
'Import for the SetWindowsHookEx function.
<DllImport("User32.dll", CharSet:=CharSet.Auto, CallingConvention:=CallingConvention.StdCall)> _
Public Overloads Shared Function SetWindowsHookEx _
(ByVal idHook As Integer, ByVal HookProc As CallBack, _
ByVal hInstance As IntPtr, ByVal wParam As Integer) As Integer
End Function
'Import for the CallNextHookEx function.
<DllImport("User32.dll", CharSet:=CharSet.Auto, CallingConvention:=CallingConvention.StdCall)> _
Public Overloads Shared Function CallNextHookEx _
(ByVal idHook As Integer, ByVal nCode As Integer, _
ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Integer
End Function
'Import for the UnhookWindowsHookEx function.
<DllImport("User32.dll", CharSet:=CharSet.Auto, CallingConvention:=CallingConvention.StdCall)> _
Public Overloads Shared Function UnhookWindowsHookEx _
(ByVal idHook As Integer) As Boolean
End Function
'Point structure declaration.
<StructLayout(LayoutKind.Sequential)> Public Structure Point
Public x As Integer
Public y As Integer
End Structure
'MouseHookStruct structure declaration.
<StructLayout(LayoutKind.Sequential)> Public Structure MouseHookStruct
Public pt As Point
Public hwnd As Integer
Public wHitTestCode As Integer
Public dwExtraInfo As Integer
End Structure
Public Shared Function MouseHookProc(_
ByVal nCode As Integer, _
ByVal wParam As IntPtr, _
ByVal lParam As IntPtr) As Integer
Dim MyMouseHookStruct As New MouseHookStruct()
If (nCode < 0) Then
Return CallNextHookEx(hHook, nCode, wParam, lParam)
End If
MyMouseHookStruct = CType(Marshal.PtrToStructure(lParam, MyMouseHookStruct.GetType()), MouseHookStruct)
Return CallNextHookEx(hHook, nCode, wParam, lParam)
End Function
Dann habe ich es nur rufen in meinem MouseDown- Ereignis das Fenster vor der Schließung:
MouseInterceptor.MouseHookProc(0, "0x201", 0)
der erste param teilt den Haken, wenn das System mit anderen Ereignissen fortgesetzt werden soll, wenn der Wert < 0. Also ist I 0 nach MouseDown- zu stoppen verwenden. Der zweite Parameter bedeutet "Linke Maustaste gedrückt", der Thirs-Parameter zeigt an, ob es sich um einen Einzel- oder Doppelklick handelt. Ich habe es jetzt bei 0 gelassen.
Gern geschehen! Gern geschehen. –