Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile Exe
#Dim All
%Unicode = 1
#Include "Win32API.inc"
Enum Equates Singular
IDC_Label = 500
IDC_Resize
IDC_GoTo
IDC_ZoomIn
IDC_ZoomOut
IDC_Zoom100
IDC_URL
IDC_Handle
IDC_Statusbar
End Enum
Global hDlg, hBrowser, hThread, hEdit As Dword, BrowserPosition As Long, HandleChain$
Function PBMain() As Long
Dialog Default Font "Tahoma", 12, 1
Dialog New Pixels, 0, "gbBrowserController",1600,300,350,190, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Resize,"Toggle Size/Position", 50,10,170,25, %BS_Left Or %BS_VCenter Or %WS_TabStop
Control Add Button, hDlg, %IDC_ZoomIn,"ZIn", 50,50,50,25, %BS_Left Or %BS_VCenter Or %WS_TabStop
Control Add Button, hDlg, %IDC_ZoomOut,"ZOut", 110,50,50,25, %BS_Left Or %BS_VCenter Or %WS_TabStop
Control Add Button, hDlg, %IDC_Zoom100,"Z100", 170,50,50,25, %BS_Left Or %BS_VCenter Or %WS_TabStop
Control Add Button, hDlg, %IDC_GoTo,"GoTo URL", 50,90,170,25, %BS_Left Or %BS_VCenter Or %WS_TabStop
Control Add TextBox, hDlg, %IDC_URL,"http://www.garybeene.com", 50,130,280,25
Control Add Statusbar, hDlg, %IDC_StatusBar,"",0,0,0,0
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local temp$$
Select Case Cb.Msg
Case %WM_InitDialog
Thread Create MoveIE(0) To hThread
Thread Close hThread To hThread
Case %WM_Destroy
SendMessage hBrowser, %WM_SysCommand, %SC_Close, 0
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_Resize
'toggle between 2 positions
BrowserPosition Xor= 1
If hBrowser=0 Then WinBeep(300,200) : Exit Function
If BrowserPosition Then
SetWindowPos hBrowser, %hWnd_NoTopMost, 200,0,800,600,%SWP_ShowWindow
Else
SetWindowPos hBrowser, %hWnd_NoTopMost, 200,600,500,400,%SWP_ShowWindow
End If
Statusbar Set Text hDlg, %IDC_StatusBar, 1,0, "Resize " + Time$
Case %IDC_ZoomIn
If hBrowser=0 Then WinBeep(300,200) : Exit Function
Statusbar Set Text hDlg, %IDC_StatusBar, 1,0, "ZoomIn " + Time$
SendZoomIn
Case %IDC_ZoomOut
If hBrowser=0 Then WinBeep(300,200) : Exit Function
Statusbar Set Text hDlg, %IDC_StatusBar, 1,0, "ZoomOut " + Time$
SendZoomOut
Case %IDC_Zoom100
If hBrowser=0 Then WinBeep(300,200) : Exit Function
Statusbar Set Text hDlg, %IDC_StatusBar, 1,0, "ZoomOut " + Time$
SendZoom100
Case %IdOk, %IDC_GoTo
If hBrowser=0 Then WinBeep(300,200) : Exit Function
GetEditHandleBeene
'? HandleChain$
GoToURL
Statusbar Set Text hDlg, %IDC_StatusBar, 1,0, "Edit Handle: " + Str$(hEdit)
' Control Set Focus hDlg, %IDC_URL
' Control Send hDlg, %IDC_URl, %EM_SetSel, 0, -1
End Select
End Select
End Function
Sub SendZoomIn
SetFocus hBrowser
SetForeGroundWindow hBrowser
keybd_event(%VK_CONTROL, 0, 0, 0)
keybd_event(%VK_Add, 0, 0, 0)
keybd_event(%VK_Add, 0, %KEYEVENTF_KEYUP, 0)
keybd_event(%VK_CONTROL, 0, %KEYEVENTF_KEYUP, 0)
End Sub
Sub SendZoomOut
SetFocus hBrowser
SetForeGroundWindow hBrowser
keybd_event(%VK_CONTROL, 0, 0, 0)
keybd_event(%VK_Subtract, 0, 0, 0)
keybd_event(%VK_Subtract, 0, %KEYEVENTF_KEYUP, 0)
keybd_event(%VK_CONTROL, 0, %KEYEVENTF_KEYUP, 0)
End Sub
Sub SendZoom100
SetFocus hBrowser
SetForeGroundWindow hBrowser
keybd_event(%VK_CONTROL, 0, 0, 0)
keybd_event(%VK_0, 0, 0, 0)
keybd_event(%VK_0, 0, %KEYEVENTF_KEYUP, 0)
keybd_event(%VK_CONTROL, 0, %KEYEVENTF_KEYUP, 0)
End Sub
Sub SendEnterBeene(hEdit As Dword)
SetFocus hEdit
SetForeGroundWindow hEdit
keybd_event(%VK_Return, 0, 0, 0)
keybd_event(%VK_Return, 0, %KEYEVENTF_KEYUP, 0)
End Sub
Sub SendEnterPierre(hEdit As Dword)
SendMessage(hEdit, %WM_KeyDown, %VK_RETURN, 0)
SendMessage(hEdit, %WM_Char, %VK_RETURN, 0)
SendMessage(hEdit, %WM_KeyUp, %VK_RETURN, 0)
End Sub
Thread Function MoveIE(ByVal x As Long) As Long
ShellExecute 0, "Open", "IExplore.exe", $Nul, $Nul, %SWP_HideWindow
Sleep 1000 'why is this necessary
Do
hBrowser = FindWindow("IEFrame", ByVal %Null)
Control Set Text hDlg, %IDC_Handle, Hex$(hBrowser)
Loop Until hBrowser
SetWindowPos hBrowser, %hWnd_NoTopMost, 200,200,900,600,%SWP_ShowWindow
Statusbar Set Text hDlg, %IDC_StatusBar, 1,0, "IE Handle: " + Hex$(hBrowser)
End Function
Sub GoToURL
Local temp$$
Control Get Text hDlg, %IDC_URL To temp$$
SendMessage hEdit, %WM_SetText, 0, StrPtr(temp$$)
SendMessage hEdit, %WM_SetReDraw, 1, 0
InvalidateRect hEdit, ByVal %NULL, 0 : UpdateWindow hEdit
SetFocus hEdit
SendEnterBeene hEdit
End Sub
Function GetEditHandlePierre() As Long
Local hWorker, hRebar, hBand As Dword, HandleChain$
hWorker = FindWindowEX(hBrowser, 0, "WorkerW", "")
hRebar = FindWindowEX(hWorker, 0, "RebarWindow32", "")
hBand = FindWindowEX(hRebar, 0, "Address Band Root", "")
hEdit = FindWindowEX(hBand, 0, "Edit", "")
Function = hEdit
Function GetEditHandleBeene() As Long
Local hWorker,hRebar,hBand,hAddress As Dword 'hBrowser and hEdit are Global. hbrowser already acquired
hWorker = EnumerateChildren(hBrowser, "WorkerW") 'Get handle to address control
hRebar = EnumerateChildren(hWorker, "ReBarWindow32") 'Get handle to address control
hBand = EnumerateChildren(hRebar, "Address Band Root") 'Get handle to address control
hAddress = EnumerateChildren(hBand, "AddressDisplay Control") 'Get handle to address control
hEdit = EnumerateChildren(hBand, "Edit")
Function = hEdit
End Function
Function EnumerateChildren(hParent As Dword, ClassName$) As Long
Local szClass As WStringZ * %Max_Path, iReturn, hChild As Long
hChild = GetWindow(hParent, %GW_CHILD Or %GW_HWNDFIRST)
Do While hChild
iReturn = GetClassName(hChild, szClass, SizeOf(szClass))
If ClassName$ = szClass Then Function = hChild : Exit Function
hChild = GetWindow(hChild, %GW_HWNDNEXT)
Loop
End Function
http://www.garybeene.com/sw/gbsnippets.htm