Jump to content

My Web Browser ( Have tabs )


Jex
 Share

Recommended Posts

Posted Image

I want share that script because will be useful for learn ie functions.

That script not completed yet and have some bugs.

Thanks danwilli for helps, he helped me too much for fix bugs and added history for back and forward buttons.

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

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, $LastPage

_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)
$Speak = GUICtrlCreateButton("Speak", 750, 5, 48, 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)
CheckPages()
OpenTab(1, "Home")
OpenTab(2, "http://www.yahoo.com")
OpenTab(3, "Last")
OpenTab(4, "http://www.autoitscript.com/forum/index.php")
OpenTab(5)
$init = 0
GUISetState()

While 1
    $Begin = TimerInit()
    $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
            _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")
        Case $Speak
            $oSpeak = ObjCreate("Sapi.SpVoice")
            $oSpeak.Speak($oIE[GetTab()].document.selection.createRange.text)
    EndSwitch
    TestHistory(GetTab())
    CheckStatusBar()
    NavigateCheck()
    CheckTitle()
    Sleep(10)
WEnd

Func CheckTitle()
    $CurrentTitle = _IEPropertyGet($oIE[GetTab()], "title")
    If $CurrentTitle <> $Title2 Then
        If $CurrentTitle = "" Then
            WinSetTitle($Form, "", $Title)
        Else
            WinSetTitle($Form, "", $CurrentTitle & " - " & $Title)
        EndIf
        $Title2 = $CurrentTitle
    EndIf
    $nLink = CheckLink()
    If $nLink <> "about:blank" And $nLink <> _GUICtrlTab_GetItemText($CreateTab, GetTab() - 1) Then GUICtrlSetData($Tab[GetTab()], $nLink)
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")
        RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\My Web Browser", "Last Page", "REG_SZ", _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
        ElseIf $nLink = "Last"  Then
            $nLink = $LastPage
        EndIf
        _IENavigate($oIE[$nNum], $nLink, 0)
        $nLink = CheckLink($nLink)
        GUICtrlSetData($Tab[$nNum], $nLink)
    EndIf
EndFunc   ;==>Navigate

Func CheckLink($cLink = "")
    If $cLink = "" Then $cLink = _IEPropertyGet($oIE[GetTab()], "locationurl")
    $cLink = StringReplace($cLink, "http://", "")
    $cLink = StringReplace($cLink, "www.", "")
    If StringInStr($cLink, "/") Then
        $cLink = StringSplit($cLink, "/")
        $cLink = $cLink[1]
    EndIf
    If StringLen($cLink) > 25 Then $cLink = StringLeft($cLink, 25) & "..."
    Return $cLink
EndFunc   ;==>CheckLink

Func NavigateCheck()
    If _IsPressed("0D") And ControlGetFocus($Form) = "Edit1"  Then
        Navigate(GetTab(), GUICtrlRead($Input))
        GUICtrlSetState($Input, $GUI_FOCUS)
    EndIf
EndFunc   ;==>NavigateCheck

Func CheckPages()
    $HomePage = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\My Web Browser", "Home Page")
    If @error Then $HomePage = "http://www.google.com"
    $LastPage = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\My Web Browser", "Last Page")
    If @error Then $LastPage = "http://www.autoitscript.com"
EndFunc   ;==>CheckPages

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
Edited by Jex
Link to comment
Share on other sites

Looks like we have both Microsoft AND Linux occupying this thread Aren't I just so funny?

Looks nice though! I like the tabs. Also, check out shell32.dll for some nice icons instead of those text buttons.

Edited by Senton-Bomb
Link to comment
Share on other sites

man i luv this..i already deleted IE off meh computer... :):P I LUV IT :blink::wub:

Well, if you delete IE, the script won't work. It uses the Internet Explorer COM object to function.

I only hope you deleted the shortcut and didn't uninstall IE, because half your PC would stop functioning.

Link to comment
Share on other sites

Looks like we have both Microsoft AND Linux occupying this thread Aren't I just so funny?

Looks nice though! I like the tabs. Also, check out shell32.dll for some nice icons instead of those text buttons.

I'm checked shell32.dll but haven't ie back, forward, stop, refresh button icons in there.

Link to comment
Share on other sites

Troubleshooting:)

$CloseTab = Has none function:) Does nothing when clicked meaning filled browser with tabs:)

Will do more tomorrow:)

Never argue with an idiot, he will just bring you down to his own level and beat you with experience! :D

Link to comment
Share on other sites

cannot close tabs

cannot resize

pressing "enter" after typing in a new web address seems to simply refresh the current page

the first page doesn't display correctly until I change tabs

the down arrows don't do anything

can't side scroll (with wheel)

doesn't remember passwords

-just some possibilities to think about

Edited by crzftx
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...