Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在internet explorer_服务器的其他窗口中获取所选文本?_C#_Vb.net - Fatal编程技术网

C# 如何在internet explorer_服务器的其他窗口中获取所选文本?

C# 如何在internet explorer_服务器的其他窗口中获取所选文本?,c#,vb.net,C#,Vb.net,我正在开发一个应用程序,在另一个软件中读取internet explorer_服务器控件中的选定文本。我在网上做了很多搜索,但都没有结果。要更详细地了解问题,请查看下图: 这是一个软件的小窗口。我想从此窗口读取所选文本(如我在屏幕截图中突出显示的文本)。使用spy++我发现文本位于internet exprlorer_服务器中 我尝试使用SendMessageTimeout获取所选文本 lMsg = RegisterWindowMessage("WM_HTML_GETOBJEC

我正在开发一个应用程序,在另一个软件中读取internet explorer_服务器控件中的选定文本。我在网上做了很多搜索,但都没有结果。要更详细地了解问题,请查看下图:

这是一个软件的小窗口。我想从此窗口读取所选文本(如我在屏幕截图中突出显示的文本)。使用spy++我发现文本位于internet exprlorer_服务器中

我尝试使用SendMessageTimeout获取所选文本

        lMsg = RegisterWindowMessage("WM_HTML_GETOBJECT")
        Dim result As Long = SendMessageTimeout(htmlWindow, lMsg, 0, 0, SendMessageTimeoutFlags.SMTO_ABORTIFHUNG, 1000, lRes)
但在LRE中,SenMessageTimeout始终返回零

我正在尝试以下代码以获取所选文本:

  Dim hWndParent As IntPtr = GetForegroundWindow()
        If hWndParent <> IntPtr.Zero AndAlso hWndParent <> Me.Handle Then
            Dim hWndFocusChild = GethWndWithFocus(hWndParent)
            Dim strClassName As String = GetClassName(hWndFocusChild)
            If strClassName.ToLower.Contains("internet explorer_server") Then
                GetHTMLContent(hWndFocusChild)
            End If                  
        End If
Dim hWndParent As IntPtr=GetForeGroundIndow()
如果hWndParent IntPtr.Zero和hWndParent Me.Handle也是
Dim hWndFocusChild=GethWndWithFocus(hWndParent)
Dim strClassName As String=GetClassName(hWndFocusChild)
如果strClassName.ToLower.Contains(“internet explorer\U服务器”)则
GetHTMLContent(hWndFocusChild)
如果结束
如果结束
下面是GetHTMLContent函数:

  Public Shared Function GetHTMLContent(htmlWindow As IntPtr) As mshtml.HTMLDocument
    Dim htmlDocument As New mshtml.HTMLDocument()
    Dim thedoc As New mshtml.HTMLDocument()
    Dim htmlDoc As IHTMLDocument = Nothing
    Dim foundWindow As Integer = htmlWindow.ToInt32()
    Dim htmlContent As String = ""
    Dim IID_IHTMLDocument As New UUID()
    Dim lRes As Long
    Dim lMsg As Long = 0
    Dim hr As Integer = 0
    If foundWindow <> 0 Then
        lMsg = RegisterWindowMessage("WM_HTML_GETOBJECT")
        Dim result As Long = SendMessageTimeout(htmlWindow, lMsg, 0, 0, SendMessageTimeoutFlags.SMTO_ABORTIFHUNG, 1000, lRes)
        If result <> 0 Then
            If lRes <> 0 Then
                ' Initialize the interface ID 
                IID_IHTMLDocument.Data1 = &H626FC520
                IID_IHTMLDocument.Data2 = &HA41E
                IID_IHTMLDocument.Data3 = &H11CF

                IID_IHTMLDocument.Data4 = New Byte(7) {}
                IID_IHTMLDocument.Data4(0) = &HA7
                IID_IHTMLDocument.Data4(1) = &H31
                IID_IHTMLDocument.Data4(2) = &H0
                IID_IHTMLDocument.Data4(3) = &HA0
                IID_IHTMLDocument.Data4(4) = &HC9
                IID_IHTMLDocument.Data4(5) = &H8
                IID_IHTMLDocument.Data4(6) = &H26
                IID_IHTMLDocument.Data4(7) = &H37
                Try
                    'htmlDoc = (mshtml.IHTMLDocument)ObjectFromLresult(, IID_IHTMLDocument, 0, htmlDoc);
                    hr = ObjectFromLresult(lRes, IID_IHTMLDocument, 0, thedoc)
                Catch e As Exception
                    MessageBox.Show("Did not get IHTMLDocument: " + e.Message)
                End Try
            End If
        End If
    End If
    Return thedoc
End Function
公共共享函数GetHTMLContent(htmlWindow作为IntPtr)作为mshtml.HTMLDocument
将htmlDocument设置为新的mshtml.htmlDocument()
将doc设置为新的mshtml.HTMLDocument()
作为IHTMLDocument的Dim htmlDoc=无
将foundWindow设置为整数=htmlWindow.ToInt32()
Dim htmlContent As String=“”
Dim IID_IHTMLDocument作为新UUID()
暗淡的lRes和长的一样
长=0时的尺寸lMsg
作为整数的Dim hr=0
如果找到窗口0,则
lMsg=RegisterWindowMessage(“WM\u HTML\u GETOBJECT”)
Dim结果为Long=SendMessageTimeout(htmlWindow,lMsg,0,0,SendMessageTimeoutFlags.SMTO_abortfhung,1000,lRes)
如果结果为0,则
如果lRes为0,则
'初始化接口ID
IID_IHTMLDocument.Data1=&H626FC520
IID_IHTMLDocument.Data2=&HA41E
IID_IHTMLDocument.Data3=&H11CF
IID_IHTMLDocument.Data4=新字节(7){}
IID_IHTMLDocument.Data4(0)=&HA7
IID_IHTMLDocument.Data4(1)=&H31
IID_IHTMLDocument.Data4(2)=&H0
IID_IHTMLDocument.Data4(3)=&HA0
IID_IHTMLDocument.Data4(4)=&HC9
IID_IHTMLDocument.Data4(5)=&H8
IID_IHTMLDocument.Data4(6)=&H26
IID_IHTMLDocument.Data4(7)=&H37
尝试
'htmlDoc=(mshtml.IHTMLDocument)ObjectFromLresult(,IID_IHTMLDocument,0,htmldocument);
hr=来自lResult的对象(lRes,IID_IHTMLDocument,0,DOC)
捕获e作为例外
MessageBox.Show(“未获取IHTMLDocument:+e.Message”)
结束尝试
如果结束
如果结束
如果结束
返回DOC
端函数
任何帮助都将不胜感激。

我解决了我的问题。 我使用SendMessage而不是SendMessageTimeout。 声明的SendMessage如下所示:

 private static extern IntPtr SendMessage(int hWnd, UInt32 Msg, int wParam, IntPtr lParam);
lResult = SendMessage(hWnd.ToInt32(), lMsg, 0, p);
并将其命名为如下所示:

 private static extern IntPtr SendMessage(int hWnd, UInt32 Msg, int wParam, IntPtr lParam);
lResult = SendMessage(hWnd.ToInt32(), lMsg, 0, p);
现在
htmlDocument=ObjectFromLresult(lResult,typeof(IHTMLDocument).GUID,IntPtr.Zero)作为IHTMLDocument2返回所需的结果