Jump to content

Internet Previewer


Recommended Posts

Hi!, i've created a script to load a page..

So my question is, is there a way to load a Internet page?

Here's my script, it downloads a file from the internet from the entered input.

;;      Includes        ;;
#include <INet.au3>
#include <File.au3>
#include <GUIConstants.au3>

;;      Setup           ;;
$width  =   @DesktopWidth   -   50
$height =   @DesktopHeight  -   50
$title  =   "Internet Previewer"
$status =   "Ready"
Opt("GUIResizeMode",$GUI_DOCKALL)
Opt("GUICloseOnESC",0)

$handle =   GUICreate($title,$width,$height)
$page   =   GUICtrlCreateInput("Default Blank Page",$width*0.01,$height*0.01,$width*0.90,$height*0.025)
$bttn1  =   GUICtrlCreateButton("Go",$width*0.91,$height*0.01,35,20)
HotKeySet("{ENTER}","PageGoto")

;;      Menu Objects        ;;
$nav_1      =   GUICtrlCreateMenu("File")
$nav_2      =   GUICtrlCreateMenu("View")


$view1      =   GUICtrlCreateMenuitem("Statusbar",$nav_2)
GUICtrlSetState($view1,$GUI_CHECKED)


;;      Statusbar           ;;
$statuslabel=   GUICtrlCreateLabel($status,0,$height*0.95,$width,$height,BitOR($SS_SIMPLE,$SS_SUNKEN))

;;      Show GUI and take actions       ;;
GUISetState(@SW_SHOW,$handle)
while 1
    $event  =   GUIGetMsg()
    
    Select
        Case $event =   $GUI_EVENT_CLOSE
            Exit
            
        Case $event =   $page
            PageGoto()
            
        Case $event =   $view1
            If BitAnd(GUICtrlRead($view1),$GUI_CHECKED) = $GUI_CHECKED Then
                GUICtrlSetState($view1,$GUI_UNCHECKED)
                GUICtrlSetState($statuslabel,$GUI_HIDE)
            Else
                GUICtrlSetState($view1,$GUI_CHECKED)
                GUICtrlSetState($statuslabel,$GUI_SHOW)
            EndIf
        EndSelect
WEnd

Exit

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Func PageGoto()
    $file       =   GUICtrlRead($page)
    $file       =   _INetExplorerCapable ($file)
    $chkHttp    =   StringLeft($file,7)
    If $chkHttp <> "http://" Then $file = "http://"&$file
    $filesize   =   InetGetSize ($file)
    $tempfile   =   _TempFile()
    
    InetGet($file,$tempfile)
    While @InetGetActive
        $status     =   "Downloading: "&$file&" - "&$filesize&" Bytes"
        $downloaded =   @InetGetBytesRead
    Wend
    
    ;For $x=1 To $filesize Step +1
    ;   $char   =   FileRead($tempfile,$x)
    ;   GUICtrlCreateLabel($char,$width*0.01+$x*10,$height*0.03+$x*10)
    ;Next

    
EndFunc

Help or Advices are both welcome :)

Thanks,

- ImMense

Link to comment
Share on other sites

Hi!, i've created a script to load a page..

So my question is, is there a way to load a Internet page?

Here's my script, it downloads a file from the internet from the entered input.

Help or Advices are both welcome :)

Thanks,

- ImMense

The beta version of AutoIt has a script included that shows a webpage shown in a Gui. Have a look in @ProgramFilesDir & "\Autoit3\Beta\tests\ActiveX\TestXInternet.au3" for a working demo.
Link to comment
Share on other sites

Link to comment
Share on other sites

Here is the script mentioned. Sure you have Beta? else download it.

#include <GUIConstants.au3>

; Example embedding an Internet Explorer Object inside an AutoIt GUI
;
; Alpha version

; Initialize my error handler
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

; Open InternetExplorer Control
; See also: http://msdn.microsoft.com/workshop/browser/webbrowser/reference/objects/internetexplorer.asp
$oIE = ObjCreate("Shell.Explorer.2")

$SinkObject=ObjEvent($oIE,"IEEvent_","DWebBrowserEvents")
if @error then 
   Msgbox(0,"AutoIt COM Test","ObjEvent: Can't use interface 'DWebBrowserEvents'. error code: " & hex(@error,8))
   exit
endif

; Create a simple GUI for our output
GUICreate ( "Embedded Web control Test", 640, 780,(@DesktopWidth-640)/2, (@DesktopHeight-780)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

$GUI_Input_URL      = GuiCtrlCreateInput    ("Enter a URL here..",10,10,500,20)
$GUI_Button_Go      = GuiCtrlCreateButton   ("Go!",     520,10,50,20)
$GUIActiveX         = GUICtrlCreateObj      ( $oIE,      10, 40 , 600 , 360 )
$GUI_Progress       = GUICtrlCreateProgress (            10, 470 , 600 , 20 )
$GUI_Button_Back    = GuiCtrlCreateButton   ("Back",     10, 420, 100,  30)
$GUI_Button_Forward = GuiCtrlCreateButton   ("Forward", 120, 420, 100,  30)
$GUI_Button_Home    = GuiCtrlCreateButton   ("Home",    230, 420, 100,  30)
$GUI_Button_Stop    = GuiCtrlCreateButton   ("Stop",    330, 420, 100,  30)
$GUI_Label_Status   = GUICtrlCreateLabel    ("Status:",  10, 495 , 600 , 30 )
$GUI_Edit_Log       = GUICtrlCreateEdit     ("Test Log:" & @CRLF, 10, 520 , 600 , 200 )
$GUI_Button_Move    = GuiCtrlCreateButton   ("move!",   100, 760, 100,  20)

GUISetState ()    ;Show GUI



$oIE.navigate("http://www.autoitscript.com")
;$oIE.navigate("about:blank")

 ; Waiting for user to close the window
  While 1
    $msg = GUIGetMsg()
    
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $GUI_Button_Home
            $oIE.navigate("http://www.autoitscript.com")
        Case $msg = $GUI_Button_Back
            $oIE.GoBack
        Case $msg = $GUI_Button_Forward
            $oIE.GoForward
        Case $msg = $GUI_Button_Stop
            $oIE.Stop
        Case $msg = $GUI_Input_URL or $msg = $GUI_Button_Go
            $oIE.navigate(GUICtrlRead( $GUI_Input_URL ))
        Case $msg = $GUI_Button_Move
            GUICtrlSetPos ( $GUIActiveX , 20, 40 , 500,200 )
    EndSelect
    
  Wend

  GUIDelete ()

  $SinkObject=""; Stop receiving events
  $oIE=""       ; Stop IE
Exit

; a few Internet Explorer Event Functions
; ---------------------------------------

Func IEEvent_ProgressChange($Progress,$ProgressMax)

    GUICtrlSetData( $GUI_Progress , ($Progress * 100) / $ProgressMax )

EndFunc

Func IEEvent_StatusTextChange($Text)

    GUICtrlSetData( $GUI_Label_Status, $Text)

    If $Text <> "" then GUICtrlSetData( $GUI_Edit_Log, "IE Status text changed to: " & $Text & @CRLF  , "append" )

EndFunc

Func IEEvent_PropertyChange( $szProperty)

    GUICtrlSetData ( $GUI_Edit_Log, "IE Changed the value of the property: " & $szProperty & @CRLF  , "append" )

EndFunc

Func IEEvent_DownloadBegin()

    GUICtrlSetData ( $GUI_Edit_Log, "IE has started a navigation operation" & @CRLF  , "append" )

EndFunc

Func IEEvent_DownloadComplete()

    GUICtrlSetData ( $GUI_Edit_Log, "IE has finished a navigation operation" & @CRLF  , "append" )

EndFunc

Func IEEvent_NavigateComplete2($oWebBrowser,$URL)  

;   IDispatch *pDisp,
;   VARIANT *URL

    GUICtrlSetData ( $GUI_Edit_Log, "IE has finished loading URL: " & $URL & @CRLF  , "append" )

EndFunc

; AutoIt Error Event Function
; ---------------------------
Func MyErrFunc()

  $HexNumber=hex($oMyError.number,8)

  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"     & @CRLF  & @CRLF & _
             "err.description is: " & @TAB & $oMyError.description  & @CRLF & _
             "err.windescription:"   & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "       & @TAB & $HexNumber              & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "   & @TAB & $oMyError.scriptline   & @CRLF & _
             "err.source is: "       & @TAB & $oMyError.source       & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile     & @CRLF & _
             "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
            )

  SetError(1) ; to check for after this function returns
Endfunc
Link to comment
Share on other sites

Here is the script mentioned. Sure you have Beta? else download it.

#include <GUIConstants.au3>

; Example embedding an Internet Explorer Object inside an AutoIt GUI
;
; Alpha version

; Initialize my error handler
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

; Open InternetExplorer Control
; See also: http://msdn.microsoft.com/workshop/browser/webbrowser/reference/objects/internetexplorer.asp
$oIE = ObjCreate("Shell.Explorer.2")

$SinkObject=ObjEvent($oIE,"IEEvent_","DWebBrowserEvents")
if @error then 
   Msgbox(0,"AutoIt COM Test","ObjEvent: Can't use interface 'DWebBrowserEvents'. error code: " & hex(@error,8))
   exit
endif

; Create a simple GUI for our output
GUICreate ( "Embedded Web control Test", 640, 780,(@DesktopWidth-640)/2, (@DesktopHeight-780)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

$GUI_Input_URL      = GuiCtrlCreateInput    ("Enter a URL here..",10,10,500,20)
$GUI_Button_Go      = GuiCtrlCreateButton   ("Go!",     520,10,50,20)
$GUIActiveX         = GUICtrlCreateObj      ( $oIE,      10, 40 , 600 , 360 )
$GUI_Progress       = GUICtrlCreateProgress (            10, 470 , 600 , 20 )
$GUI_Button_Back    = GuiCtrlCreateButton   ("Back",     10, 420, 100,  30)
$GUI_Button_Forward = GuiCtrlCreateButton   ("Forward", 120, 420, 100,  30)
$GUI_Button_Home    = GuiCtrlCreateButton   ("Home",    230, 420, 100,  30)
$GUI_Button_Stop    = GuiCtrlCreateButton   ("Stop",    330, 420, 100,  30)
$GUI_Label_Status   = GUICtrlCreateLabel    ("Status:",  10, 495 , 600 , 30 )
$GUI_Edit_Log       = GUICtrlCreateEdit     ("Test Log:" & @CRLF, 10, 520 , 600 , 200 )
$GUI_Button_Move    = GuiCtrlCreateButton   ("move!",   100, 760, 100,  20)

GUISetState ()    ;Show GUI
$oIE.navigate("http://www.autoitscript.com")
;$oIE.navigate("about:blank")

 ; Waiting for user to close the window
  While 1
    $msg = GUIGetMsg()
    
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $GUI_Button_Home
            $oIE.navigate("http://www.autoitscript.com")
        Case $msg = $GUI_Button_Back
            $oIE.GoBack
        Case $msg = $GUI_Button_Forward
            $oIE.GoForward
        Case $msg = $GUI_Button_Stop
            $oIE.Stop
        Case $msg = $GUI_Input_URL or $msg = $GUI_Button_Go
            $oIE.navigate(GUICtrlRead( $GUI_Input_URL ))
        Case $msg = $GUI_Button_Move
            GUICtrlSetPos ( $GUIActiveX , 20, 40 , 500,200 )
    EndSelect
    
  Wend

  GUIDelete ()

  $SinkObject=""; Stop receiving events
  $oIE=""       ; Stop IE
Exit

; a few Internet Explorer Event Functions
; ---------------------------------------

Func IEEvent_ProgressChange($Progress,$ProgressMax)

    GUICtrlSetData( $GUI_Progress , ($Progress * 100) / $ProgressMax )

EndFunc

Func IEEvent_StatusTextChange($Text)

    GUICtrlSetData( $GUI_Label_Status, $Text)

    If $Text <> "" then GUICtrlSetData( $GUI_Edit_Log, "IE Status text changed to: " & $Text & @CRLF  , "append" )

EndFunc

Func IEEvent_PropertyChange( $szProperty)

    GUICtrlSetData ( $GUI_Edit_Log, "IE Changed the value of the property: " & $szProperty & @CRLF  , "append" )

EndFunc

Func IEEvent_DownloadBegin()

    GUICtrlSetData ( $GUI_Edit_Log, "IE has started a navigation operation" & @CRLF  , "append" )

EndFunc

Func IEEvent_DownloadComplete()

    GUICtrlSetData ( $GUI_Edit_Log, "IE has finished a navigation operation" & @CRLF  , "append" )

EndFunc

Func IEEvent_NavigateComplete2($oWebBrowser,$URL)  

;   IDispatch *pDisp,
;   VARIANT *URL

    GUICtrlSetData ( $GUI_Edit_Log, "IE has finished loading URL: " & $URL & @CRLF  , "append" )

EndFunc

; AutoIt Error Event Function
; ---------------------------
Func MyErrFunc()

  $HexNumber=hex($oMyError.number,8)

  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"     & @CRLF  & @CRLF & _
             "err.description is: " & @TAB & $oMyError.description  & @CRLF & _
             "err.windescription:"   & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "       & @TAB & $HexNumber              & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "   & @TAB & $oMyError.scriptline   & @CRLF & _
             "err.source is: "       & @TAB & $oMyError.source       & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile     & @CRLF & _
             "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
            )

  SetError(1) ; to check for after this function returns
Endfunc

Im very sure :)... im noob at autoit but i aint dumb :(

I've downloaded it the last beta : autoit-v3.1.1.125-beta-Setup.exe 25-May-2006 23:27 2.3M

Now testing it...

-ImMense

EDIT: oh my GOD!!!!!!!!!!!! AWESOME! :D thanks very much man

Edited by Immense
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...