2011-09-09 5 views
1

デスクトップVBアプリケーションがのコントロールをすでに持っている方法はありますか?ブラウザウィンドウ?たとえば、ウィンドウ内の特定の座標をマウスでクリックするか、ウィンドウに特定の要素が含まれているかどうかを確認します。vb形式の既に開いているブラウザを制御/アクセスする

Microsoft Internet Controls(shdocvw)とMSHTML(IHTMLDocument2)を使用してみましたが、ブラウザウィンドウの要素にアクセスする方法(body.innnerHTMLなど)に苦労しています。

答えて

0

には、Microsoft HTMLオブジェクトライブラリへの参照を追加し、Microsoftインターネットが

Option Explicit On 

Public Class Form1 

    'Functions used to set cursor location and mouse clicks 
    Public Declare Auto Function SetCursorPos Lib "User32.dll" (ByVal X As Integer, ByVal Y As Integer) As Long 
    Public Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long) 
    Public Declare Auto Function ShowWindow Lib "user32" (ByVal _ 
    hwnd As Long, ByVal nCmdShow As Long) As Long 

    'Constants used for cursor and mouse functions, and to maximize window 
    Public Const SW_MAXIMIZE = 3 
    Public Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down 
    Public Const MOUSEEVENTF_LEFTUP = &H4 ' left button up 
    Public Const MOUSEEVENTF_RIGHTDOWN = &H8 ' right button down 
    Public Const MOUSEEVENTF_RIGHTUP = &H10 ' right button up  

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
     'retrieve all the open instances of IE 
     Dim shellWindows = New SHDocVw.ShellWindowsClass() 
     Dim htmlInput As mshtml.HTMLInputElement 
     'for each instance of IE 
     For Each ie As SHDocVw.InternetExplorer In shellWindows 
     'If the title of the IE window matches the designated title 
     If ie.Document.title = "Page Title" Then 
      'retrieve the control with the designated field id 
      htmlInput = ie.Document.getElementById("fieldID") 
      'if the control's inner html matches the designated text 
      If htmlInput.innerHTML = "innerHTML" Then 
       'show the IE window maximized and with focus 
       ShowWindow(ie.HWND, SW_MAXIMIZE) 
       'move the cursor to the designated x,y coordinates 
       SetCursorPos(xCoord, yCoord) 
       'left mouse click down and up 
       mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0) 
       mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0) 
       'send the designated keyboard command 
       My.Computer.Keyboard.SendKeys("keyboardCommand") 
      End If 
     End If 
     Next 
    End Sub 
End Class 
1

あなたはTABにあり、そしてあなたがキーストロークをエミュレートするためのSendKeysを使用することができます〜あなたはVB.NET

 set WshShell = WScript.CreateObject("WScript.Shell") 
    WshShell.Run "iexplore" 
    WScript.Sleep 100 
    WshShell.AppActivate "Windows Internet Explorer" 
    WshShell.SendKeys "~" 
    WScript.Sleep 500 
    WshShell.SendKeys "www.google.com" 

を使用することができる可能性があるVBScriptで:AppActivateのを使用することができます。

+0

を制御し、特定のHTML要素が存在している場合、私は、例えば、ブラウザウィンドウの状態を判断する必要があります。 – mp42871

+0

多分送信キーコマンドを使ってソースを表示し、さらに多くのsendキーコマンドを使ってそのHTMLをクリップボードにコピーします。その後、クリップボードからHTMLを取得して、アプリケーションからHTMLにアクセスできます。 – N0Alias

+0

私はむしろあまり古風な方法でコードにアクセスしたい – mp42871

関連する問題