Jump to content

Web Browser


Generator
 Share

Recommended Posts

Web Browser

A web browser that i started working on it few days ago, it's basically self explaintory.

Main credit goes to IE.au3 author and some goes to AutoIt forum and AutoIt, rest for me putting together and testing

Since my computer is skinned with Vista, icon might look slightly different compare to the image, code is below or download attachment with exe compiled(a nice icon).

#include<GUIConstants.au3>
#include<GUIStatusbar.au3>
#include<GuiCombo.au3>
#include<GuiListView.au3>
#include<IE.au3>
#include<INet.au3>
#include<Misc.au3>

_Singleton("Web Browser")

Opt("TrayMenuMode", 1)
Opt("TrayOnEventMode", 1)
Opt("GUICloseOnEsc", 0)
Opt("GUIOnEventMode", 1)
Opt("GUIResizeMode", 1)
TrayCreateItem("Quit")
TrayItemSetOnEvent(-1, "_Exit")
TraySetState()

Global $Width = 800, $Height = 600, $Homeurl = "about:blank", $ScreenMode = 0, $a_PartsRightEdge[2] = [600, -1], $s_PartText[2] = ["", ""]
Global $Bool = 1, $Bookmark[256], $BookmarkDir[256], $Amount = 0, $configuse = 0, $config_frm, $main_frm, $sourceuse = 0, $source_frm, $source_edit, $History_frm
Global $Home_Input, $urlinput, $Blank = "", $historystate = 0, $Listview, $find_input

_IEErrorHandlerRegister()
$oIE = _IECreateEmbedded()
$main_frm = GUICreate("Web Browser", $Width, $Height, -1, -1, $WS_SIZEBOX + $WS_MINIMIZEBOX + $WS_CAPTION + $WS_POPUP + $WS_SYSMENU + $WS_MAXIMIZEBOX)
$filemenu = GUICtrlCreateMenu("File")
$fileopen = GUICtrlCreateMenuItem("Open", $filemenu)
$filesave = GUICtrlCreateMenuItem("Save As", $filemenu)
$Seperator1 = GUICtrlCreateMenuItem("", $filemenu)
$fileexit = GUICtrlCreateMenuItem("Exit", $filemenu)
$viewmenu = GUICtrlCreateMenu("View")
$viewsource = GUICtrlCreateMenuItem("View Source", $viewmenu)
$viewhistory = GUICtrlCreateMenuItem("View History", $viewmenu)
$Seperator2 = GUICtrlCreateMenuItem("", $viewmenu)
$viewstatus = GUICtrlCreateMenuItem("View Statusbar", $viewmenu)
$favmenu = GUICtrlCreateMenu("Favorite")
$favadd = GUICtrlCreateMenuItem("Add current page as favorite", $favmenu)
$Seperator3 = GUICtrlCreateMenuItem("", $favmenu)
$optionmenu = GUICtrlCreateMenu("Options")
$optionconfig = GUICtrlCreateMenuItem("Configuration", $optionmenu)
$IEObj = GUICtrlCreateObj($oIE, 10, 2, 780, 490)
$backbtn = GUICtrlCreateButton("", 10, 495, 40, 40, $BS_ICON)
$forwardbtn = GUICtrlCreateButton("", 55, 495, 40, 40, $BS_ICON)
$stopbtn = GUICtrlCreateButton("", 100, 495, 40, 40, $BS_ICON)
$homebtn = GUICtrlCreateButton("", 145, 495, 40, 40, $BS_ICON)
$Printbtn = GUICtrlCreateButton("", 190, 495, 40, 40, $BS_ICON)
$configbtn = GUICtrlCreateButton("", 235, 495, 40, 40, $BS_ICON)
$searchbtn = GUICtrlCreateButton("", 280, 495, 40, 40, $BS_ICON)
$helpbtn = GUICtrlCreateButton("", 750, 495, 40, 40, $BS_ICON)
$searchinput = GUICtrlCreateInput("Search for...Supported by Google(C)", 325, 495, 375, 20)
$urlinput = GUICtrlCreateCombo("", 325, 517, 375, 20, -1)
$loadurl = GUICtrlCreateButton("", 705, 495, 40, 40, $BS_ICON)
$statusbar = _GUICtrlStatusBarCreate($main_frm, $a_PartsRightEdge, $s_PartText)
$progress = _GUICtrlStatusBarCreateProgress($statusbar, 1)
GUICtrlSetOnEvent($backbtn, "_NavigateBack")
GUICtrlSetOnEvent($forwardbtn, "_NavigateFoward")
GUICtrlSetOnEvent($stopbtn, "_NavigateStop")
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUISetOnEvent($GUI_EVENT_RESIZED, "_Resize")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "_Resize")
GUISetOnEvent($GUI_EVENT_RESTORE, "_Resize")
GUICtrlSetOnEvent($fileopen, "_OpenFile")
GUICtrlSetOnEvent($filesave, "_SaveAs")
GUICtrlSetOnEvent($fileexit, "_Exit")
GUICtrlSetOnEvent($viewsource, "_ViewSource")
GUICtrlSetOnEvent($homebtn, "_ViewHome")
GUICtrlSetOnEvent($Printbtn, "_PrintPage")
GUICtrlSetOnEvent($searchbtn, "_Search")
GUICtrlSetOnEvent($loadurl, "_LoadURL")
GUICtrlSetOnEvent($viewstatus, "_StatusBar")
GUICtrlSetOnEvent($helpbtn, "_HelpInfo")
GUICtrlSetOnEvent($favadd, "_AddFavor")
GUICtrlSetOnEvent($configbtn, "_Configuration")
GUICtrlSetOnEvent($optionconfig, "_Configuration")
GUICtrlSetOnEvent($viewhistory, "_ViewHistory")
GUICtrlSetState($viewstatus, $GUI_CHECKED)
GUICtrlSetImage($backbtn, "shell32.dll", 146)
GUICtrlSetImage($forwardbtn, "shell32.dll", 137)
GUICtrlSetImage($stopbtn, "shell32.dll", 109)
GUICtrlSetImage($homebtn, "shell32.dll", 150)
GUICtrlSetImage($Printbtn, "shell32.dll", 16)
GUICtrlSetImage($configbtn, "shell32.dll", 165)
GUICtrlSetImage($searchbtn, "shell32.dll", 22)
GUICtrlSetImage($helpbtn, "shell32.dll", 23)
GUICtrlSetImage($loadurl, "shell32.dll", 137)
GUICtrlSetData($urlinput, $Homeurl, $Homeurl)
GUISetState()

_IENavigate($oIE, $Homeurl, 0)
_GUICtrlComboInitStorage($urlinput, 26, 50)
_CreateHistory()

While 1
    _UpdateCheck()
    _UpdateHistory()
    _ControlCheck()
    Sleep(1)
WEnd
Func _NavigateBack()
    _IEAction($oIE, "back")
EndFunc  ;==>_NavigateBack
Func _NavigateFoward()
    _IEAction($oIE, "forward")
EndFunc  ;==>_NavigateFoward
Func _NavigateStop()
    _IEAction($oIE, "stop")
EndFunc  ;==>_NavigateStop
Func _Exit()
    Exit
EndFunc  ;==>_Exit
Func _Openfile()
    Local $File
    $File = FileOpenDialog("Please select file", @DesktopDir, "html(*.html)|htm(*.htm)", 1 + 2)
    If @error = 1 Then
        Return
    Else
        _IENavigate($oIE, $File, 0)
    EndIf
EndFunc  ;==>_Openfile
Func _SaveAs()
    _IEAction($oIE, "saveas")
EndFunc  ;==>_SaveAs
Func _ViewSource()
    If $sourceuse Then Return
    $sourceuse = Not $sourceuse
    $source_frm = GUICreate("Source Viewer - " & _IEPropertyGet($oIE, "locationname"), 300, 300, -1, -1, -1, -1, $main_frm)
    $source_edit = GUICtrlCreateEdit("", 2, 2, 296, 256, $ES_MULTILINE + $ES_WANTRETURN + $WS_VSCROLL + $WS_HSCROLL + $ES_AUTOVSCROLL + $ES_AUTOHSCROLL)
    $refresh_btn = GUICtrlCreateButton("Update", 105, 265, 90, 30, $BS_CENTER)
    GUICtrlSetOnEvent($refresh_btn, "_RefreshSource")
    GUISetOnEvent($GUI_EVENT_CLOSE, "_SourceDelete")
    GUICtrlSetState($viewsource, $GUI_CHECKED)
    GUISetState()
    _RefreshSource()
EndFunc  ;==>_ViewSource
Func _ViewHome()
    _IENavigate($oIE, $Homeurl, 0)
EndFunc  ;==>_ViewHome
Func _PrintPage()
    _IEAction($oIE, "print")
EndFunc  ;==>_PrintPage
Func _Search()
    Local $Read
    If GUICtrlRead($searchinput) = "" Then
        GUICtrlSetData($searchinput, "Search for...Supported by Google(C)")
        Return
    Else
        $Read = GUICtrlRead($searchinput)
        _IENavigate($oIE, "http://www.google.com", 0)
        $oForm = _IEFormGetCollection($oIE, 0)
        $oQuery = _IEFormElementGetCollection($oForm, 1)
        _IEFormElementSetValue($oQuery, $Read)
        _IEFormSubmit($oForm)
    EndIf
EndFunc  ;==>_Search
Func _LoadURL()
    Local $Read
    $Read = GUICtrlRead($urlinput)
    _IENavigate($oIE, $Read, 0)
EndFunc  ;==>_LoadURL
Func _UpdateCheck()
    If Not _IEPropertyGet($oIE, "busy") Then
        _GUICtrlStatusBarSetIcon($statusbar, 0, "shell32.dll", 176)
        _GUICtrlStatusBarSetText($statusbar, "Done")
        GUICtrlSetData($progress, 100)
    ElseIf _IEPropertyGet($oIE, "busy") Then
        _GUICtrlStatusBarSetIcon($statusbar, 0, "shell32.dll", 159)
        For $i = 0 To 100
            _GUICtrlStatusBarSetText($statusbar, "Loading..." & _IEPropertyGet($oIE, "locationurl"))
            ControlSetText($main_frm, "", "Edit2", _IEPropertyGet($oIE, "locationurl"))
            GUICtrlSetData($progress, $i)
            Sleep(5)
        Next
    EndIf
    _GUICtrlComboAutoComplete($urlinput, $Blank)
    WinSetTitle($main_frm, "", "Web Browser - " & _IEPropertyGet($oIE, "title"))
EndFunc  ;==>_UpdateCheck
Func _HelpInfo()
    MsgBox(64, "Version Info", "Platform & Version :" & _IEPropertyGet($oIE, "appversion"))
EndFunc  ;==>_HelpInfo
Func _StatusBar()
    $Bool = Not $Bool
    If Not $Bool Then
        _GUICtrlStatusBarShowHide($statusbar, @SW_HIDE)
        GUICtrlSetState($viewstatus, $GUI_UNCHECKED)
    Else
        _GUICtrlStatusBarShowHide($statusbar, @SW_SHOW)
        GUICtrlSetState($viewstatus, $GUI_CHECKED)
    EndIf
EndFunc  ;==>_StatusBar
Func _AddFavor()
    If _IEPropertyGet($oIE, "locationurl") = "about:blank" Then Return
    $Bookmark[$Amount] = GUICtrlCreateMenuItem(_IEPropertyGet($oIE, "title"), $favmenu)
    $BookmarkDir[$Amount] = _IEPropertyGet($oIE, "locationurl")
    GUICtrlSetOnEvent(-1, "_LoadFavor")
    $Amount += 1
    If $Amount > 253 Then
        GUICtrlSetState($favadd, $GUI_DISABLE)
    EndIf
EndFunc  ;==>_AddFavor
Func _LoadFavor()
    Local $Id = @GUI_CtrlHandle
    For $i = 0 To UBound($Bookmark, 1) - 1
        If GUICtrlGetHandle($Bookmark[$i]) = $Id Then
            _IENavigate($oIE, $BookmarkDir[$i])
            ExitLoop
        EndIf
    Next
EndFunc  ;==>_LoadFavor
Func _Configuration()
    If $configuse Then Return
    $configuse = Not $configuse
    $config_frm = GUICreate("Configuration", 500, 45, -1, -1, -1, -1, $main_frm)
    $Home_SetBlank = GUICtrlCreateButton("", 2, 2, 40, 40, $BS_ICON)
    $Home_Show = GUICtrlCreateButton("", 47, 2, 40, 40, $BS_ICON)
    $Apply_Button = GUICtrlCreateButton("", 455, 2, 40, 40, $BS_ICON)
    $Home_Input = GUICtrlCreateInput($Homeurl, 90, 12, 360, 20)
    GUICtrlSetImage($Apply_Button, "shell32.dll", 137)
    GUICtrlSetImage($Home_Show, "shell32.dll", 150)
    GUICtrlSetImage($Home_SetBlank, "shell32.dll", 0)
    GUICtrlSetOnEvent($Home_SetBlank, "_SetBlank")
    GUICtrlSetOnEvent($Home_Show, "_ShowHome")
    GUICtrlSetOnEvent($Apply_Button, "_ApplyConfig")
    GUISetOnEvent($GUI_EVENT_CLOSE, "_ConfigDelete")
    GUISetState()
EndFunc  ;==>_Configuration
Func _ConfigDelete()
    $configuse = Not $configuse
    GUIDelete($config_frm)
EndFunc  ;==>_ConfigDelete
Func _SourceDelete()
    $sourceuse = Not $sourceuse
    GUICtrlSetState($viewsource, $GUI_UNCHECKED)
    GUIDelete($source_frm)
EndFunc  ;==>_SourceDelete
Func _ShowHome()
    GUICtrlSetData($Home_Input, $Homeurl)
EndFunc  ;==>_ShowHome
Func _SetBlank()
    GUICtrlSetData($Home_Input, "about:blank")
EndFunc  ;==>_SetBlank
Func _ApplyConfig()
    $Homeurl = GUICtrlRead($Home_Input)
    _ConfigDelete()
EndFunc  ;==>_ApplyConfig
Func _Resize()
    _GUICtrlStatusBarResize($statusbar)
EndFunc  ;==>_Resize
Func _RefreshSource()
    WinSetTitle($source_frm, "", "Source Viewer - " & _IEPropertyGet($oIE, "locationname"))
    GUICtrlSetData($source_edit, StringReplace(_INetGetSource(_IEPropertyGet($oIE, "locationurl")), ">", ">" & @CRLF))
EndFunc  ;==>_RefreshSource
Func _ControlCheck()
    If ControlGetFocus($main_frm, "") = "Edit2" And _IsPressed("0D") Then
        If GUICtrlRead($urlinput) = "" Then Return
        Do
            Sleep(1)
        Until Not _IsPressed("0D")
        _LoadURL()
        _ComboStringManage()
    EndIf
EndFunc  ;==>_ControlCheck
Func _ComboStringManage()
    Local $Read
    $Read = GUICtrlRead($urlinput)
    If _GUICtrlComboGetCount($urlinput) > 25 Then
        _GUICtrlComboDeleteString($urlinput, 24)
        _ComboStringSearch($Read)
    Else
        _ComboStringSearch($Read)
    EndIf
EndFunc  ;==>_ComboStringManage
Func _ComboStringSearch($Read)
    If _GUICtrlComboFindString($urlinput, $Read) = $CB_ERR Then
        _GUICtrlComboAddString($urlinput, $Read)
        _GUICtrlComboSelectString($urlinput, 0, $Read)
    Else
        _GUICtrlComboSelectString($urlinput, 0, $Read)
    EndIf
EndFunc  ;==>_ComboStringSearch
Func _CreateHistory()
    $History_frm = GUICreate("View History", 400, 400, -1, -1, -1, -1, $main_frm)
    $Listview = GUICtrlCreateListView("Title|URL", 2, 2, 396, 350, -1)
    $find_btn = GUICtrlCreateButton("", 2, 355, 40, 40, $BS_ICON)
    $find_input = GUICtrlCreateInput("Enter Keyword to search....", 45, 365, 260, 20)
    $delete_history = GUICtrlCreateButton("", 310, 355, 40, 40, $BS_ICON)
    $load_history = GUICtrlCreateButton("", 355, 355, 40, 40, $BS_ICON)
    GUICtrlSetImage($delete_history, "shell32.dll", 131)
    GUICtrlSetImage($find_btn, "shell32.dll", 22)
    GUICtrlSetImage($load_history, "shell32.dll", 137)
    GUICtrlSetOnEvent($find_btn, "_FindHistory")
    GUICtrlSetOnEvent($load_history, "_LoadHistory")
    GUICtrlSetOnEvent($delete_history, "_DeleteHistory")
    GUISetOnEvent($GUI_EVENT_CLOSE, "_ViewHistory")
    GUISetState(@SW_HIDE)
    _GUICtrlListViewSetColumnWidth($Listview, 0, 100)
    _GUICtrlListViewSetColumnWidth($Listview, 1, 250)
EndFunc  ;==>_CreateHistory
Func _UpdateHistory()
    If _IEPropertyGet($oIE, "locationurl") = _GUICtrlListViewGetItemText($Listview, _GUICtrlListViewGetItemCount($Listview) - 1, 1) Then
        Return
    Else
        _GUICtrlListViewInsertItem($Listview, -1, _IEPropertyGet($oIE, "locationname") & "|" & _IEPropertyGet($oIE, "locationurl"))
    EndIf
EndFunc  ;==>_UpdateHistory
Func _ViewHistory()
    $historystate = Not $historystate
    If $historystate Then
        GUICtrlSetState($viewhistory, $GUI_CHECKED)
        GUISetState(@SW_SHOW, $History_frm)
    Else
        GUICtrlSetState($viewhistory, $GUI_UNCHECKED)
        GUISetState(@SW_HIDE, $History_frm)
    EndIf
EndFunc  ;==>_ViewHistory
Func _FindHistory()
    For $i = 0 To _GUICtrlListViewGetItemCount($Listview)
        If StringInStr(_GUICtrlListViewGetItemText($Listview, $i, -1), GUICtrlRead($find_input)) > 0 Then
            _GUICtrlListViewSetItemSelState($Listview, $i)
            Return
        EndIf
    Next
    GUICtrlSetData($find_input, "No Result..ReEnter Keyword..")
EndFunc  ;==>_FindHistory
Func _LoadHistory()
    _IENavigate($oIE, _GUICtrlListViewGetItemText($Listview, -1, 1), 0)
EndFunc  ;==>_LoadHistory
Func _DeleteHistory()
    _GUICtrlListViewDeleteItemsSelected($Listview)
EndFunc  ;==>_DeleteHistory

Screenshot of the GUI:

Code: Web_Browser.au3

Comments and suggestions are welcome, if anyone is willing to do me a favor as in taking a screenshot of the GUI(XP User none skinned) and post it, it would be really helpful, if any bug please report.

Edit: Forgot about security issue, no, don't use this as your default browser, it does not block popup or disable activex or javascript and many other things. But if you are going to safety site this would be the choice because low usage of the memory.

Edit2: Updated, self explaintory, see screenshot for update quickview.

Edited by Generator
Link to comment
Share on other sites

cool, works good, web browsers seem to have replaced media players as the new 'hot' topic

Nah, because you made one and inspired me, i found media player is unnesscery unless it's a really good one. I am using IE7 as the model of the browser, many other functions will be add in.

P.S: For what reason you removed all your source in your post?

Link to comment
Share on other sites

And you call this a Web Browser? What web browser is this? This is just a wrapper for the IE browser control.

This IS not a real web browser, it's Internet Explorer masked as something else(and seriously crippled...).

Why use crippled version of IE? The real IE is crippled enough :)

To say that you have created a true web browser, your script has to do the actual parsing & rendering of the web page.

Obviously, your script does not do this.

Link to comment
Share on other sites

And you call this a Web Browser? What web browser is this? This is just a wrapper for the IE browser control.

This IS not a real web browser, it's Internet Explorer masked as something else(and seriously crippled...).

Why use crippled version of IE? The real IE is crippled enough :)

To say that you have created a true web browser, your script has to do the actual parsing & rendering of the web page.

Obviously, your script does not do this.

I was thinking almost the exact same thing. It does look much better then IE though. Would love to see a GUI like that on a "real" browser.

Link to comment
Share on other sites

And you call this a Web Browser? What web browser is this? This is just a wrapper for the IE browser control.

This IS not a real web browser, it's Internet Explorer masked as something else(and seriously crippled...).

Why use crippled version of IE? The real IE is crippled enough :)

To say that you have created a true web browser, your script has to do the actual parsing & rendering of the web page.

Obviously, your script does not do this.

Technically this is a browser, but we won't be using this anyways since IE and Firefox or Opera is much better, and security issue also comes in, but as you can see it's just like a model of IE in AutoIt.
Link to comment
Share on other sites

Yes, it is nice for demonstrating the use of the IE COM+ embedding into the AutoIt GUI.

But, it is not a true browser written in AutoIt language.

How about the implementation of page rendering engine and the HTTP request engine with AutoIt ?

(I don't know these can be done with AutoIt or not)

[u]My Projects[/u]:General:WinShell (Version 1.6)YouTube Video Downloader Core (Version 2.0)Periodic Table Of Chemical Elements (Version 1.0)Web-Based:Directory Listing Script Written In AutoIt3 (Version 1.9 RC1)UDFs:UnicodeURL UDFHTML Entity UDF[u]My Website:[/u]http://dhilip89.hopto.org/[u]Closed Sources:[/u]YouTube Video Downloader (Version 1.3)[quote]If 1 + 1 = 10, then 1 + 1 ≠ 2[/quote]

Link to comment
Share on other sites

I think it'd be awesome if someone made an HTML interpreter/renderer, instead of using the embedded IE Object.

Nice browser btw! Looks professional.

Edited by AutoItKing
http://www.autoitking.co.nr Site is DOWN | My deviantART | No Topic Topic - Don't do it!-------------------- UDF's/Scripts:AutoIt: [BenEditor 3.6] [_ShutDown()]PHP: [CommentScript]Web Based AutoIt: [MemStats] [HTML to AU3] [User LogIn and SignUp script]
Link to comment
Share on other sites

Guys when someone makes a web browser here and uses ie, dont be so suprised.

Just too bad there isn't *free* independent browser objects/parsers that would be available to autoit, the offbyone authors have an dll but its not free.

Speaking of html parsing.. that would be very difficult but possible. theres an xml.au3 library around here, that may help out.

Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()
Link to comment
Share on other sites

Well of course it's possible! I mean, Firefox, IE, Opera, OffByOne, etc. have all done it!

http://www.autoitking.co.nr Site is DOWN | My deviantART | No Topic Topic - Don't do it!-------------------- UDF's/Scripts:AutoIt: [BenEditor 3.6] [_ShutDown()]PHP: [CommentScript]Web Based AutoIt: [MemStats] [HTML to AU3] [User LogIn and SignUp script]
Link to comment
Share on other sites

I think it's possible to render a web page using only AutoIt scripting, but considering the AutoIt's lack of speed I think this is not a good idea, because the browser will be very slow.

But maybe if the browser is a text browser, the idea is not so bad.

These days there are not much people using text browsers, except the blind people, who are actually using text browsers&screen readers.

And at last - again, the script you call a "web browser" is not a real browser, but anyway, it's a good example.

Link to comment
Share on other sites

  • 2 weeks later...

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...