2016-09-29 15 views
-1

私は別のソフトウェアでInternet Explorerのコントロールで選択したテキストを読み込むアプリケーションを開発しています。私はインターネットで多くの検索をしましたが、役に立たなかった。より詳細に問題を取得するには、以下の絵を見てください。他のウィンドウでinternet explorer_serverで選択したテキストを取得する方法は?

をこれは、ソフトウェアの小さなウィンドウです。このウィンドウから選択したテキスト(スクリーンショットで強調表示されているようなもの)を読みたいと思います。 spy ++を使用すると、テキストがインターネットexprlorer_serverにあることがわかりました。

私はSendMessageTimeout

 lMsg = RegisterWindowMessage("WM_HTML_GETOBJECT") 
     Dim result As Long = SendMessageTimeout(htmlWindow, lMsg, 0, 0, SendMessageTimeoutFlags.SMTO_ABORTIFHUNG, 1000, lRes) 

を使用して、選択したテキストを取得しようとしました。しかしSenMessageTimeoutは常にLRESにゼロを返します。

私が選択したテキストを取得するには、次のコードをしようとしています:任意の助けが理解されるであろう

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 

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 

に続いてのgetHtmlContent機能です。

答えて

-1

私は私の問題を解決しました。 私はSendMessageTimeoutの代わりにSendMessageを使用しました。以下に示すよう は宣言のSendMessage:

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) as IHTMLDocument2;戻り、所望の結果。

関連する問題