I am using a number of 3rd party ActiveX controls on my form. My application has multiple forms, and say these ActiveX controls are on myAxHostingForm. Moving the mouse over some of the controls gives myAxHostingForm focus. I want to stop this.
I have tried an empty event handler
For Each c In Me.ChildControls(Of AxHost)() ' custom extension method returning controls of type provided
AddHandler c.MouseMove,
Sub(s As Object, m As MouseEventArgs)
End Sub
Next
I get the following exception:
System.NotSupportedException was caught
HResult=-2146233067
Message=Event MouseMove is not valid on this ActiveX control.
Source=System.Windows.Forms
StackTrace:
at System.Windows.Forms.AxHost.add_MouseMove(MouseEventHandler value)
at <my source code file>
I'm hoping someone who knows something about ActiveX hosting in .NET can help make sense of this error, and possibly solve this annoying problem.
Edit: Trying @Hans approach,
<ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("00000114-0000-0000-C000-000000000046")>
Interface IOleWindow
<PreserveSig>
Function GetWindow(ByRef hwnd As IntPtr) As Int32
Sub ContextSensitiveHelp(ByVal fEnterMode As Int32)
End Interface
Class ActiveXWindow
Inherits NativeWindow
Protected Overrides Sub WndProc(ByRef m As Message)
System.Diagnostics.Debug.WriteLine(m)
If (m.Msg = &H200) Then Return
MyBase.WndProc(m)
End Sub
End Class
this is inside my form load:
Dim itf = CType(CCDimage1.GetOcx, IOleWindow)
Dim hWnd As IntPtr
Dim hr As Integer = itf.GetWindow(hWnd)
If hr <> 0 Or hWnd = IntPtr.Zero Then Throw New Exception("Could not find handle for DataRay window")
Dim wrapper = New ActiveXWindow()
wrapper.AssignHandle(hWnd)
I get the exception on the first line:
System.InvalidCastException was caught
HResult=-2147467262
Message=Unable to cast COM object of type 'System.__ComObject' to interface type 'Instruments.IOleWindow'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00000114-0000-0000-C000-000000000046}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
Source=Instruments