Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
strongm said:Or, assuming that you know the hWnd:
Code:' Requires reference to: ' Microsoft Shell Controls and Automation ' Microsoft Internet Controls Private Function GetWindowsExplorerWindowFolder(hWnd As Long) As String Dim myShell As Shell Dim myExplorerWindow As WebBrowser Set myShell = New Shell For Each myExplorerWindow In myShell.Windows On Error Resume Next If myExplorerWindow.hWnd = hWnd Then If Err = 0 Then GetWindowsExplorerWindowFolder = myExplorerWindow.Document.Folder.Self.Path End If On Error GoTo 0 Next End Function
' Requires reference to:
' Microsoft Shell Controls and Automation
' Microsoft Internet Controls
' Microsoft HTML Object Library
Option Explicit
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetAncestor Lib "user32" (ByVal hwnd As Long, ByVal gaFlags As Long) As Long
Public Function GetBrowserDocument() As IHTMLDocument2
Dim TargetHWND As Long
Dim p As POINTAPI
Dim myShell As Shell
Dim myBrowserWindow As WebBrowser
Dim myBrowserDoc As IHTMLDocument2
GetCursorPos p
TargetHWND = GetAncestor(WindowFromPoint(p.X, p.Y), 2)
Set myShell = New Shell
For Each myBrowserWindow In myShell.Windows
On Error Resume Next
If myBrowserWindow.hwnd = TargetHWND Then
If Err = 0 Then Set myBrowserDoc = myBrowserWindow.Document
End If
On Error GoTo 0
Next
Set GetBrowserDocument = myBrowserDoc
End Function
Dim TargetDoc As IHTMLDocument2
'Selects the Explorer Window's Document
'Requires:
' PictureBox (Picture1) [Drag From this box onto an explorer window to select]
'*Note: Picture Box turns blue when window is selected...
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button Then
Set TargetDoc = GetBrowserDocument()
If TargetDoc Is Nothing Then
Picture1.BackColor = vbButtonFace
Else
Picture1.BackColor = vbBlue
End If
End If
End Sub
'Get HTML Source
'Requires:
' CommandButton (Command1)
' TextBox (Text1) [Multiline w/ scrollbars]
Private Sub Command1_Click()
Dim elem As IHTMLElement
If Not TargetDoc Is Nothing Then
Text1 = TargetDoc.body.innerHTML
End If
End Sub
'Loop through Tags example
'Requires:
' CommandButton (Command2)
' ListBox (List1)
Private Sub Command2_Click()
Dim elem As IHTMLElement
If Not TargetDoc Is Nothing Then
List1.Clear
For Each elem In TargetDoc.All
On Error Resume Next
List1.AddItem elem.tagName & " :: " & elem.Name & " :: " & elem.Value 'txt.Value
On Error GoTo 0
Next
End If
Beep
End Sub
mmilan said:Okay - even if I knew for sure that the client was using IE, I'm not entirely sure how I would go about doing this. There is a tool called Spy that comes with Visual Studio that might be able to get the control handles, but I would reluctant to simply assume that they never change.
strongm said:Ah - this is javascript, isn't it. probably requires a semicolon:
WebBrowser1.document.parentWindow.execScript "makeSelection(5);"
TargetDoc.parentWindow.execScript "document.form-name.field-name.value='my text';"
TargetDoc.form-name.field-name.value="my text"
TargetDoc.Forms("form-name").Item("field-name").Value = "my text"
'Inject search for 'VB Tutorial' into google window and submit
Private Sub Command3_Click()
Dim elem As IHTMLElement
If Not TargetDoc Is Nothing Then
TargetDoc.Forms("f").Item("q").Value = "vb tutorial"
TargetDoc.Forms("f").Item("btnG").Click
End If
End Sub
'Get Form Control Data
'Requires:
' CommandButton (Command1)
' TextBox (Text1) [Multiline w/ scrollbars]
Private Sub Command1_Click()
Dim elem As IHTMLElement
Dim elem2 As IHTMLElement
Dim frm As IHTMLFormElement
If Not TargetDoc Is Nothing Then
Text1 = ""
For Each frm In TargetDoc.Forms
Text1 = Text1 & frm.Name & " <FORM>" & vbCrLf
For Each elem In frm
Text1 = Text1 & " " & elem.getAttribute("Name") & " <" & elem.tagName & "> = " & elem.getAttribute("Value") & vbCrLf
If LCase(elem.tagName) = "select" Then
For Each elem2 In elem.children
Text1 = Text1 & " " & elem2.innerText & " <" & elem2.tagName & ">" & vbCrLf
Next
End If
Next
Next
End If
End Sub
f <FORM>
hl <INPUT> = en
q <INPUT> = search string goes here
btnG <INPUT> = Google Search
btnI <INPUT> = I'm Feeling Lucky
<FORM>
Type <SELECT> = Forum
Find A Forum <OPTION>
Search Posts (Keyword) <OPTION>
Thread Number <OPTION>
Threads by Handle <OPTION>
Search FAQs (Keyword) <OPTION>
Search Links (Keyword) <OPTION>
Find An Expert <OPTION>
SearchString <INPUT> =
getquestion <FORM>
QID <INPUT> = 934916
Userid <INPUT> = 350850
Topic <INPUT> = Can i fill the fields of a web form from VB code?
pid <INPUT> = 222
page <INPUT> = 1
post <TEXTAREA> = When you are working with html Forms, and need to know the names and types of their controls... here is some code that you can replace the Command1_Click() code above with... [b](the rest of the text I was typing here)[/b]
NotifyMe <INPUT> = 1
ProcessEmot <INPUT> = 1
ProcessTGML <INPUT> = 1
showSig <INPUT> = 1
SubReply <INPUT> = Preview Post
SubReply <INPUT> = Submit Post