【发布时间】:2013-11-21 00:44:58
【问题描述】:
我在表单上使用了许多第 3 方 ActiveX 控件。我的应用程序有多个表单,并且说这些 ActiveX 控件位于 myAxHostingForm 上。将鼠标移到某些控件上会获得 myAxHostingForm 焦点。我想阻止它。
我尝试了一个空的事件处理程序
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
我得到以下异常:
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>
我希望对 .NET 中的 ActiveX 托管有所了解的人可以帮助理解这个错误,并可能解决这个烦人的问题。
编辑: 尝试@Hans 方法,
<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
这是在我的表单加载中:
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)
我在第一行得到了异常:
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
【问题讨论】:
标签: .net vb.net winforms activex