Go Back   Random Stuff Forums > Technical > Programming

Programming Discuss any type of programming here.

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 17-09-2007, 09:00 PM
Matt's Avatar
(Offline)
Administrator
 
Join Date: Jan 2007
Location: United States - Ohio
Posts: 3,820
Matt is an unknown quantity at this point
Default [AutoIt] Simple Web Browser

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
__________________
"Facts do not cease to exist because they are ignored."
Reply With Quote
  #2  
Old 17-09-2007, 09:03 PM
Speedster239's Avatar
Speedster239 (Offline)
Active Member
 
Join Date: Jul 2007
Location: The Internet
Posts: 271
Speedster239 is an unknown quantity at this point
Default

Nice tutorial man. Detailed and informing!
__________________

To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.

My goal ^
Reached on Sunday, November 11th, 2007. Next skill to max out: Magic - 13.04 or 200mil fletch xp

I program PHP, Java and Vb.

MSN:
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
Reply With Quote
  #3  
Old 17-09-2007, 11:10 PM
World Domination's Avatar
(Offline)
Super Sexy Admin
 
Join Date: Jan 2007
Location: Illinois, USA
Posts: 7,384
World Domination is an unknown quantity at this point
Default

Stealing my VB Tuts. Bastard. ;)
Just Kidding, Great Tut and very well explained. Keep up the good work.
__________________
RSForums.org - We Don't give a fuck.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.

"It's not yelling, it's projecting; and by the way, my voice is soothing."
-Billy Mays

Reply With Quote
  #4  
Old 17-09-2007, 11:51 PM
Matt's Avatar
(Offline)
Administrator
 
Join Date: Jan 2007
Location: United States - Ohio
Posts: 3,820
Matt is an unknown quantity at this point
Default

Lol. I'm in your coding, stealing your ideas :P

Thanks Rob
__________________
"Facts do not cease to exist because they are ignored."
Reply With Quote
  #5  
Old 18-09-2007, 12:15 AM
Woody's Avatar
Woody (Offline)
Hmmmm
 
Join Date: Feb 2007
Location: Virginia
Posts: 1,609
Woody is an unknown quantity at this point
Default

Figured I might as well add some more code to it to add more functions.
Added:
Back Button
Forward Button
Refresh Button
Progress Bar

Noted all my additions for reference.
#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", 166, 410, 400, 25, 0)

$back_button = GUICtrlCreateButton("Back", 16, 410, 50, 25, 0) ; Creats Back GUI
$forward_button = GUICtrlCreateButton("Forward", 66, 410, 50, 25, 0) ; Creates Forward GUI
$refresh_button = GUICtrlCreateButton("Refresh", 116, 410, 50, 25, 0) ; Creates Refresh GUI
$progressbar1 = GUICtrlCreateProgress ( 570, 415, 200, 20, 0) ; Creates Progress bar
_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)
        Set_progress() ; Function
    Case $msg = $back_button ; Send browser to previous page
        $Object.GoBack
        Set_progress() ; Function
    Case $msg = $forward_button ; Send browser forward
        $Object.GoForward
        Set_progress() ; Function
    Case $msg = $refresh_button ; Refreshes browser page
        $Object.Refresh
        Set_progress() ; Function
    Case $msg = $GUI_EVENT_CLOSE
        Exit
    EndSelect
WEnd

Func Set_progress() ; Creates Progress bar
    For $pg = 0 To 100 Step 5
        GUICtrlSetData($progressbar1, $pg)
        Sleep(2)
    Next
EndFunc
Enjoy.

Edit: Screenshot
__________________

To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.

I heart my weighted companion cube.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.



To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
And then jesus said "Let there be Asterisks!"

Last edited by Woody; 18-09-2007 at 12:19 AM..
Reply With Quote
  #6  
Old 18-09-2007, 12:21 AM
World Domination's Avatar
(Offline)
Super Sexy Admin
 
Join Date: Jan 2007
Location: Illinois, USA
Posts: 7,384
World Domination is an unknown quantity at this point
Default

Thanks for the addition Woody, although I don't think I will ever get into AutoIt.:P
__________________
RSForums.org - We Don't give a fuck.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.

"It's not yelling, it's projecting; and by the way, my voice is soothing."
-Billy Mays

Reply With Quote
  #7  
Old 18-09-2007, 12:24 AM
Matt's Avatar
(Offline)
Administrator
 
Join Date: Jan 2007
Location: United States - Ohio
Posts: 3,820
Matt is an unknown quantity at this point
Default

Awesome Woody. Glad to see you are learning!!
__________________
"Facts do not cease to exist because they are ignored."
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -5. The time now is 03:39 AM.

Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0
Copyright © 2006 - 2010, Rsforums.org