The finished project:
#include <GUIConstants.au3>
#include <IE.au3>
$GUI = GUICreate("Simple Web Browser", 800, 450)
$object = ObjCreate("Shell.Explorer.2")
$object_ctrl = GUICtrlCreateObj($object, 16, 10, 780, 400)
$url_button = GUICtrlCreateButton("URL", 16, 410, 750, 25, 0)
_IENavigate($object, "www.google.com")
GUISetState()
While 1
$msg = GUIGetMsg()
Select
Case $msg = $url_button
$URL = Inputbox("Web Browser", "Enter the URL you want to visit.")
_IENavigate($Object, $URL)
Case $msg = $GUI_EVENT_CLOSE
Exit
EndSelect
WEnd
This may look a little threatening, but it really isn't. Let's break it down, shall we.
#include <GUIConstants.au3>
#include <IE.au3>
These are two files that come with the autoit program. We have to include them, so that we can make a GUI, and so that we can use IE features. Not much else with that that we need to worry about now. Just be aware that it is there.
$GUI = GUICreate("Simple Web Browser", 800, 450)
$object = ObjCreate("Shell.Explorer.2")
$object_ctrl = GUICtrlCreateObj($object, 16, 10, 780, 400)
$url_button = GUICtrlCreateButton("URL", 16, 410, 750, 25, 0)
_IENavigate($object, "www.google.com")
GUISetState()
This code is where the GUI (
Graphical User Interface) is made. The first like of code makes a 800x450 GUI, the second creates the "browser" object. The third like takes that object, and puts it into the GUI, and the fourth simply creates a button that will say "URL". The fifth line sets the default page to google.com. And the "GUISetState()" simply makes the GUI appear, this goes at the end of the GUI coding.
While 1
$msg = GUIGetMsg()
Select
Case $msg = $url_button
$URL = Inputbox("Web Browser", "Enter the URL you want to visit.")
_IENavigate($Object, $URL)
Case $msg = $GUI_EVENT_CLOSE
Exit
EndSelect
WEnd
Here, the "While" statement begins a type of
iteration. This is basically saying the following is true forever (since the value after it is "1", if this was ever equal to zero, it would stop).
The $msg = GUIGetMsg() line of code is setting a variable on the "$msg", any time someone interacts with the GUI (i.e. clicks a button) a new message will be send into the $msg variable.
After this, is a type of
conditional statement, "select". This is basically a large version of "If" statements, and is used for a larger scale, since a lot of if..then..elseif... can get really messy.
For each condition of "select" you use "case" meaning that if x=y then (this coding will be executed). Being used here are "$msg = $url_button", meaning if someone clicks the "$url_button" this will be true, and thusly executed. "$msg = $GUI_EVENT_CLOSE" is also here, this is simply what the program does when someone clicks on the "x" buttons. It is good practice to include this in all of your programs.
$URL = Inputbox("Web Browser", "Enter the URL you want to visit.")
_IENavigate($Object, $URL)
The concept here is rather simple. When the case statement above this is true (i.e. someone clicking on the URL button) the program will send an InputBox (from the "InputBox()" function), and then take whatever input the user gave there, and navigate the browser there.
Simple enough, eh? Hope everyone finds this useful