Sign in to follow this  
Followers 0
JustinReno

IE COM and Tabbs

7 posts in this topic

Well, I've been working on this for around half an hour and can't figure this out. This little program is a simple tabbed internet explorer. When I get to tab 2, it starts to morph all the other tabs. I'm not very good at explaining it, so here is the code. Any help would be appreciated:

#include <GuiTab.au3>

Global $TabCount = 0, $Obj[100]

$GUI = GUICreate("Prototype Simple Web Browser", 346, 330)
$NewTab = GUICtrlCreateButton("New Tab", 0, 0, 75, 25, 0)
$URL = GUICtrlCreateButton("URL", 80, 0, 75, 25, 0)
$Tab = GUICtrlCreateTab(0, 32, 345, 297)
$Tab1 = GUICtrlCreateTabItem("0")
$Obj[$TabCount] = ObjCreate("Shell.Explorer.2")
GUICtrlCreateObj($Obj[$TabCount], 8, 56, 330, 268)
GUISetState(@SW_SHOW)

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case -3
            Exit
        Case $NewTab
            _NewTab()
        Case $URL
            _URL()
    EndSwitch
WEnd

Func _NewTab()
    $TabCount += 1
    _GUICtrlTab_InsertItem($Tab, $TabCount, $TabCount)
    _GUICtrlTab_SetCurFocus ($Tab, $TabCount)
    $Obj[$TabCount] = ObjCreate("Shell.Explorer.2")
    GUICtrlCreateObj($Obj[$TabCount], 8, 56, 330, 268)
EndFunc

Func _URL()
    $Obj[_GUICtrlTab_GetCurSel($Tab)].Navigate(InputBox("Prototype Simple Web Browser - New URL", "What URL do you want to go to:"))
EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Jex and I were working on a similar issue. See the function called FlashRefresh() which is the workaround we used for the tabs issue. I think this is an issue with tabs not redrawing correctly, and not necessarily the IE functions themselves. I have briefly discussed this with Dale Hohm, author of the IE functions, and we are thinking that this is a problem with the tabs. If we could create a reproducer, that showed the issue every times, we need to submit it as a bug.

FlashRefresh just displays a gui ctrl over the IE object and then hides it again, redrawing what was behind it.

#include <GUIConstants.au3>
#include <GuiTab.au3>
#include <IE.au3>
#include <GuiStatusBar.au3>
#include <array.au3>
#include <Misc.au3>

HotKeySet("!t", "Test")

Global $Tab[11], $oIE[11], $Obj[11], $flasher[11], $backstack[11][2], $init = 1
Global $Title = "My Web Browser", $TabPos1 = 5, $TabPos2 = 35, $TabPos3 = 850, $TabPos4 = 650, $Status = 0, $Title2, $Status2 = "", $frskip = 0, $Count = 1, $HomePage

_IEErrorHandlerRegister()
$Form = GUICreate($Title, $TabPos3 + 10, $TabPos4 + 30)
$FileMenu = GUICtrlCreateMenu("File")
$FileOpenTab = GUICtrlCreateMenu("New Tab", $FileMenu)
$OpenTab1 = GUICtrlCreateMenuItem("Open Blank Page", $FileOpenTab)
$OpenTab2 = GUICtrlCreateMenuItem("Open Home Page", $FileOpenTab)
$ShowSource = GUICtrlCreateMenuItem("Show Page Source", $FileMenu)
$EditMenu = GUICtrlCreateMenu("Edit")
$Cut = GUICtrlCreateMenuItem("Cut", $EditMenu)
$Copy = GUICtrlCreateMenuItem("Copy", $EditMenu)
$Paste = GUICtrlCreateMenuItem("Paste", $EditMenu)
$Sep = GUICtrlCreateMenuItem("", $EditMenu)
$Selectall = GUICtrlCreateMenuItem("Select All", $EditMenu)
$SettingsMenu = GUICtrlCreateMenu("Settings")
$ChangeHomePage = GUICtrlCreateMenuItem("Change Home Page", $SettingsMenu)
$StatusBar = _GUICtrlStatusBar_Create($Form)
Local $aParts[1] = [500]
_GUICtrlStatusBar_SetParts($StatusBar, $aParts)
$Input = GUICtrlCreateInput("", 7, 7, 305, 22)
$Go = GUICtrlCreateButton("Go", 336, 5, 35, 25)
$Back = GUICtrlCreateButton("Back", 376, 5, 43, 25)
$Forward = GUICtrlCreateButton("Forward", 440, 5, 59, 25)
$Stop = GUICtrlCreateButton("Stop", 520, 5, 43, 25)
$Refresh = GUICtrlCreateButton("Refresh", 568, 5, 59, 25)
$Home = GUICtrlCreateButton("Home", 632, 5, 43, 25)
$Back2 = GUICtrlCreateButton("v", 418, 5, 17, 25)
$Forward2 = GUICtrlCreateButton("v", 498, 5, 17, 25)
$Go2 = GUICtrlCreateButton("v", 320, 5, 17, 25)
$NewTab = GUICtrlCreateButton("New Tab", 680, 5, 65, 25)
$CloseTab = GUICtrlCreateButton("X", 832, 36, 19, 17)
$CreateTab = GUICtrlCreateTab($TabPos1, $TabPos2, $TabPos3, $TabPos4 - 50)
GUICtrlSetState($Back, $GUI_DISABLE)
GUICtrlSetState($Forward, $GUI_DISABLE)
GUICtrlSetState($Back2, $GUI_DISABLE)
GUICtrlSetState($Forward2, $GUI_DISABLE)
$HomePage = CheckHomePage()
OpenTab(1, "Home")
OpenTab(2, "http://www.yahoo.com/")
OpenTab(3, "http://www.autoitscript.com/forum/index.php")
$init = 0
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Go
            Navigate(GetTab(), GUICtrlRead($Input))
        Case $Back
            HistoryBack(GetTab())
        Case $Forward
            HistoryForward(GetTab())
        Case $Stop
            _IEAction($oIE[GetTab()], "stop")
        Case $Refresh
            _IEAction($oIE[GetTab()], "refresh")
        Case $Home
            Navigate(GetTab(), "Home")
        Case $OpenTab1
            OpenTab($Count)
        Case $OpenTab2
            OpenTab($Count, "Home")
        Case $Cut
            _IEAction($oIE[GetTab()], "cut")
        Case $Copy
            _IEAction($oIE[GetTab()], "copy")
        Case $Paste
            _IEAction($oIE[GetTab()], "paste")
        Case $Selectall
            _GUICtrlTab_SetCurFocus($CreateTab, GetTab() - 1)
            _IEAction($oIE[GetTab()], "selectall")
        Case $ChangeHomePage
            $hPage = InputBox("Home Page", "Set default home page :", $HomePage, "", 200, 130)
            If Not @error Then
                $HomePage = $hPage
                RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\My Web Browser", "Home Page", "REG_SZ", $HomePage)
            EndIf
        Case $NewTab
            OpenTab($Count, "Home")
        Case $ShowSource
            If FileExists(@TempDir & "\Source.txt") Then FileDelete(@TempDir & "\Source.txt")
            $Source = _IEDocReadHTML($oIE[GetTab()])
            FileWrite(@TempDir & "\Source.txt", $Source)
            ShellExecute(@TempDir & "\Source.txt")
    EndSwitch
    TestHistory(GetTab())
    CheckTitle()
    CheckStatusBar()
    NavigateCheck()
    Sleep(10)
WEnd

Func CheckTitle()
    $CurrentTitle = _IEPropertyGet($oIE[GetTab()], "title")
    If $CurrentTitle <> $Title2 Then
        WinSetTitle($Form, "", $CurrentTitle & " - " & $Title)
        $Title2 = $CurrentTitle
    EndIf
EndFunc   ;==>CheckTitle

Func CheckStatusBar()
    If _IEPropertyGet($oIE[GetTab()], "busy") And $Status2 <> _IEPropertyGet($oIE[GetTab()], "locationurl") Then
        _GUICtrlStatusBar_SetText($StatusBar, "Opening page " & _IEPropertyGet($oIE[GetTab()], "locationurl") & "...")
        GUICtrlSetState($Stop, $GUI_ENABLE)
        $Status2 = _IEPropertyGet($oIE[GetTab()], "locationurl")
    ElseIf Not _IEPropertyGet($oIE[GetTab()], "busy") And $Status2 <> "" Then
        _GUICtrlStatusBar_SetText($StatusBar, " ")
        GUICtrlSetState($Stop, $GUI_DISABLE)
        $Status2 = ""
    EndIf
EndFunc   ;==>CheckStatusBar

Func OpenTab($oNum, $oLink = "")
    If $Count > 10 Then
        MsgBox(0, "Error", "You may only have 10 tabs open at one time")
        Return @error
    EndIf
    $Count += 1
    $backstack[$oNum][0] = 0
    $Tab[$oNum] = GUICtrlCreateTabItem($oNum)
    $oIE[$oNum] = _IECreateEmbedded()
    $Obj[$oNum] = GUICtrlCreateObj($oIE[$oNum], $TabPos1 + 5, $TabPos2 + 25, $TabPos3 - 10, $TabPos4 - 80)
    $flasher[$oNum] = GUICtrlCreateEdit("", $TabPos1 + 5, $TabPos2 + 25, $TabPos3 - 10, $TabPos4 - 80)
    GUICtrlSetState($flasher[$oNum], $GUI_HIDE)
    Navigate($oNum, $oLink)
    TestHistory($oNum)
    If $init = 0 Then
        _GUICtrlTab_SetCurSel($CreateTab, $Count - 2)
    EndIf
EndFunc   ;==>OpenTab

Func Navigate($nNum, $nLink)
    If $nLink = "" Then
        $nLink = "about:blank"
        _IENavigate($oIE[$nNum], $nLink, 0)
        GUICtrlSetData($Tab[$nNum], "Blank Page")
    Else
        If $nLink = "Home" Then $nLink = $HomePage
        _IENavigate($oIE[$nNum], $nLink, 0)
        $nLink = StringReplace($nLink, "http://", "")
        $nLink = StringReplace($nLink, "www.", "")
        If StringInStr($nLink, "/") Then
            $nLink = StringSplit($nLink, "/")
            $nLink = $nLink[1]
        EndIf
        If StringLen($nLink) > 25 Then $nLink = StringLeft($nLink, 25) & "..."
        GUICtrlSetData($Tab[$nNum], $nLink)
    EndIf
EndFunc   ;==>Navigate

Func NavigateCheck()
    If _IsPressed("0D") And ControlGetFocus($Form) = "Edit1" Then
        Navigate(GetTab(), GUICtrlRead($Input))
        GUICtrlSetState($Input, $GUI_FOCUS)
    EndIf
EndFunc   ;==>NavigateCheck
   
Func CheckHomePage()
    $hPage = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\My Web Browser", "Home Page")
    If @error Then $hPage = "http://www.google.com"
    Return $hPage
EndFunc

Func GetTab()
    Return _GUICtrlTab_GetCurSel($CreateTab) + 1
EndFunc   ;==>GetTab

Func TestHistory($nNum)
    If IsArray($backstack) = 0 Then Return
    If $backstack[$nNum][0] = 0 Then
        If _IEPropertyGet($oIE[$nNum], "locationurl") <> "" Then
            $backstack[$nNum][0] += 1
            $backstack[$nNum][$backstack[$nNum][0]] = _IEPropertyGet($oIE[$nNum], "locationurl")
        EndIf
    EndIf
    If $backstack[$nNum][$backstack[$nNum][0]] <> _IEPropertyGet($oIE[$nNum], "locationurl") And "" <> _IEPropertyGet($oIE[$nNum], "locationurl") And _IEPropertyGet($oIE[$nNum], "locationurl") <> $backstack[$nNum][$backstack[$nNum][0]] Then
        $backstack[$nNum][0] += 1
        $newurl = _IEPropertyGet($oIE[$nNum], "locationurl")
        If $backstack[$nNum][0] + 1 > UBound($backstack, 2) Then ReDim $backstack[11][$backstack[$nNum][0] + 1]
        If $backstack[$nNum][$backstack[$nNum][0]] <> "" Then
            For $avar = $backstack[$nNum][0] To UBound($backstack, 2) - 1
                $backstack[$nNum][$avar] = ""
            Next
        EndIf
        $backstack[$nNum][$backstack[$nNum][0]] = $newurl
        While _IEPropertyGet($oIE[$nNum], "locationurl") <> $backstack[$nNum][$backstack[$nNum][0]]
            Sleep(10)
        WEnd
        If $frskip = 0 Then
            FlashRefresh($nNum)
        Else
            $frskip = 0
        EndIf
    EndIf
    NavButtons($nNum)
EndFunc   ;==>TestHistory

Func NavButtons($nNum)
    If $backstack[$nNum][0] > 1 And GUICtrlGetState($Back) <> 80 Then
        GUICtrlSetState($Back, $GUI_ENABLE)
        GUICtrlSetState($Back2, $GUI_ENABLE)
    EndIf
    If $backstack[$nNum][0] = 1 And GUICtrlGetState($Back) <> 144 Then
        GUICtrlSetState($Back, $GUI_DISABLE)
        GUICtrlSetState($Back2, $GUI_DISABLE)
    EndIf
    If UBound($backstack, 2) - 1 > $backstack[$nNum][0] Then
        If $backstack[$nNum][$backstack[$nNum][0] + 1] = "" Then
            If GUICtrlGetState($Forward) <> 144 Then
                GUICtrlSetState($Forward, $GUI_DISABLE)
                GUICtrlSetState($Forward2, $GUI_DISABLE)
            EndIf
        Else
            If GUICtrlGetState($Forward) <> 80 Then
                GUICtrlSetState($Forward, $GUI_ENABLE)
                GUICtrlSetState($Forward2, $GUI_ENABLE)
            EndIf
        EndIf
    Else
        If GUICtrlGetState($Forward) <> 144 Then
            GUICtrlSetState($Forward, $GUI_DISABLE)
            GUICtrlSetState($Forward2, $GUI_DISABLE)
        EndIf
    EndIf
EndFunc   ;==>NavButtons

Func HistoryBack($nNum)
    GUICtrlSetState($Back, $GUI_DISABLE)
    GUICtrlSetState($Back2, $GUI_DISABLE)
    $backstack[$nNum][0] -= 1
    Navigate($nNum, $backstack[$nNum][$backstack[$nNum][0]])
    While _IEPropertyGet($oIE[$nNum], "locationurl") <> $backstack[$nNum][$backstack[$nNum][0]]
        Sleep(10)
    WEnd
    $frskip = 1
    TestHistory($nNum)
    FlashRefresh($nNum)
EndFunc   ;==>HistoryBack

Func HistoryForward($nNum)
    GUICtrlSetState($Forward, $GUI_DISABLE)
    GUICtrlSetState($Forward2, $GUI_DISABLE)
    $backstack[$nNum][0] += 1
    Navigate($nNum, $backstack[$nNum][$backstack[$nNum][0]])
    While _IEPropertyGet($oIE[$nNum], "locationurl") <> $backstack[$nNum][$backstack[$nNum][0]]
        Sleep(10)
    WEnd
    $frskip = 1
    TestHistory($nNum)
    FlashRefresh($nNum)
EndFunc   ;==>HistoryForward

Func Test()
    _ArrayDisplay($backstack)
EndFunc   ;==>Test

Func FlashRefresh($nNum)
    GUICtrlSetState($flasher[$nNum], $GUI_SHOW)
    GUICtrlSetState($flasher[$nNum], $GUI_HIDE)
    _GUICtrlTab_DeselectAll($CreateTab, False)
EndFunc   ;==>FlashRefresh

EDIT: Spelled Dale's last name wrong

Edited by danwilli

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

It still doesn't work. This is my code which also can be a reproducer:

#include <GuiTab.au3>

Global $TabCount = 0, $Obj[10], $Flasher[10]

HotKeySet("{ESC}", "_Refresh")

$GUI = GUICreate("Prototype Simple Web Browser", 346, 330)
$NewTab = GUICtrlCreateButton("New Tab", 0, 0, 75, 25, 0)
$URL = GUICtrlCreateButton("URL", 80, 0, 75, 25, 0)
$Tab = GUICtrlCreateTab(0, 32, 345, 297)
$Tab1 = GUICtrlCreateTabItem("0")
$Obj[$TabCount] = ObjCreate("Shell.Explorer.2")
GUICtrlCreateObj($Obj[$TabCount], 8, 56, 330, 268)
GUISetState(@SW_SHOW)

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case -3
            Exit
        Case $NewTab
            _NewTab()
        Case $URL
            $Obj[_GUICtrlTab_GetCurSel($Tab)].Navigate(InputBox("Prototype Simple Web Browser - New URL", "What URL do you want to go to:"))
            _Refresh()
    EndSwitch
WEnd

Func _NewTab()
    $TabCount += 1
    _GUICtrlTab_InsertItem($Tab, $TabCount, $TabCount)
    _GUICtrlTab_SetCurFocus ($Tab, $TabCount)
    $Obj[$TabCount] = ObjCreate("Shell.Explorer.2")
    GUICtrlCreateObj($Obj[$TabCount], 8, 56, 330, 268)
    $Flasher[$TabCount] = GUICtrlCreateEdit("", 0, 0, 400, 400)
    GUICtrlSetState($Flasher[$TabCount], $GUI_HIDE)
EndFunc

Func FlashRefresh($nNum)
    GUICtrlSetState($Flasher[$nNum], $GUI_SHOW)
    GUICtrlSetState($Flasher[$nNum], $GUI_HIDE)
    _GUICtrlTab_DeselectAll($Tab, False)
EndFunc   ;==>FlashRefresh

Func _Refresh()
    FlashRefresh(_GUICtrlTab_GetCurSel($Tab))
EndFunc

Edit: Spelling.

Edited by JustinReno

Share this post


Link to post
Share on other sites

I ran your code and see no problems.

To be a reproducer it needs to be simpler and include instructions.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Open 4 tabs

Make all 4 tabs go to a different webpage.

Look at all of the tabs, some of them will "morph" together.

Share this post


Link to post
Share on other sites

Ok, some strange behaviou with 4 tabs I didn't see with 3.

Can you simplify the entire scenario? Can you do it with 2 tabs and without the new tab and url button logic?

When you think about ccreating a reproducer, think about helping the developer focus on exactly what the trouble is without needing to verify other logic in your code.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

$GUI = GUICreate("Tabbed Repoducer", 354, 450)
$Tab = GUICtrlCreateTab(0, 0, 353, 449)
GUICtrlCreateTabItem("Google")
$IE1 = ObjCreate("Shell.Explorer.2")
GUICtrlCreateObj($IE1, 8, 24, 338, 420)
GUICtrlCreateTabItem("Answers")
$IE2 = ObjCreate("Shell.Explorer.2")
GUICtrlCreateObj($IE2, 8, 24, 338, 420)
GUICtrlCreateTabItem("AutoIt")
$IE3 = ObjCreate("Shell.Explorer.2")
GUICtrlCreateObj($IE3, 8, 24, 338, 420)
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)

$IE1.Navigate("www.google.com")
$IE2.Navigate("www.answers.com")
$IE3.Navigate("www.autoitscript.com")

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case -3
            Exit
    EndSwitch
WEnd

This works, but the other code I posted doesn't. I need the posted one to work.

The other code I posted only gets to tab 2. (0, 1, 2) Before it starts to morph.

Edited by JustinReno

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0