Jump to content

Loop issue


Recommended Posts

Hello,

I am trying to create browser using the IE functions, but I am having a problem with the address bar that I am trying to create. Whenever I go to a new page, I want the URL in the inputbox to change to match what the URL of the visible is.

I have a While Loop that contains my Switch statements to detect what buttons are pressed and what action to take when they are pressed. This part is working fine. I then set up a function to refresh the Inputbox with the current URL. To stop the Inputbox from constantly refreshing/flickering, I exported the current value of the inputbox and compared that site to the current "actual" URL. If they didn't match then I would see the Input box to change to the new URL. The problem I have is that as soon as I start typing a URL, the inputbox changes back to what I was trying to change it from.

I have tried taking this check out of the loop, but then the problem is that if I go to google and select a website link from within the search engine, the URL doesn't change. It only changes when I click on the "GO" button.

I tried creating 2 separate loops, but then I found out that this isn't available in AutoIT.

I need the Input box to check for URL changes, but maintain the functionality of the buttons. Can someone see what's wrong with the code that I have please?

Thanks,

Jeff

; *******************************************************
; Example 1 - Trap COM errors so that 'Back' and 'Forward'
;               outside of history bounds does not abort script
;               (expect COM errors to be sent to the console)
; *******************************************************
;
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <IE.au3>

If Not FileExists("C:\temp\url.ini") Then
    IniWrite("C:\temp\url.ini","URL","URL","http://www.autoitscript.com")
EndIf
$urlHome = IniRead("C:\temp\url.ini","URL","URL","")
_IEErrorHandlerRegister ()

$oIE = _IECreateEmbedded ()
GUICreate("Embedded Web control Test", 640, 580, _
        (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _
        $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
$GUIActiveX = GUICtrlCreateObj($oIE, 10, 40, 600, 360)
$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", 340, 420, 100, 30)
$GUI_Button_Go = GUICtrlCreateButton("Go", 450, 420, 100, 30)
$url = GUICtrlCreateInput($urlHome,10,10,600,25)
GUICtrlSetData($url,$urlHome)

GUISetState()       ;Show GUI

_IENavigate ($oIE, $urlHome)

; Waiting for user to close the window
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $GUI_Button_Home
            _IENavigate ($oIE, "http://www.autoitscript.com")
        Case $GUI_Button_Back
            _IEAction ($oIE, "back")
        Case $GUI_Button_Forward
            _IEAction ($oIE, "forward")
        Case $GUI_Button_Stop
            _IEAction ($oIE, "stop")
        Case $GUI_Button_Go
            $urlValue = GUICtrlRead($url)
            _IENavigate($oIE,$urlValue)
            $urlGet = _IEPropertyGet($oIE,"locationurl")
            GUICtrlSetData($url,$urlGet)
    EndSwitch
WEnd

GUIDelete()

Exit

Func _inputChk()
    $urlGet = _IEPropertyGet($oIE,"locationurl")
    FileWriteLine("C:\temp\Cache.txt",$urlGet)
    $URLGUI = GUICtrlRead($url)
    $URLCache = FileReadLine("C:\temp\Cache.txt",1)
    If $URLCache <> $URLGUI Then
        GUICtrlSetData($url,$urlGet)
    EndIf
    FileDelete("C:\temp\Cache.txt")
    Sleep(1000)
EndFunc
Link to comment
Share on other sites

I would go more like this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
#include <ButtonConstants.au3>

_IEErrorHandlerRegister()
$urlHome = "http://www.autoitscript.com"
$oIE = _IECreateEmbedded()
GUICreate("Embedded Web control Test", 640, 580, _
        (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _
        $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
$GUIActiveX = GUICtrlCreateObj($oIE, 10, 40, 600, 360)
$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", 340, 420, 100, 30)
$GUI_Button_Go = GUICtrlCreateButton("Go", 450, 420, 100, 30, BitOR($GUI_SS_DEFAULT_BUTTON, $BS_DEFPUSHBUTTON))
$url = GUICtrlCreateInput($urlHome, 10, 10, 600, 25)
GUICtrlSetData($url, $urlHome)

GUISetState() ;Show GUI

_IENavigate($oIE, $urlHome)

; Waiting for user to close the window
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $GUI_Button_Home
            _IENavigate($oIE, $urlHome, 0)
            AdlibRegister("_LoadWaiting")
        Case $GUI_Button_Back
            _IEAction($oIE, "back")
            AdlibRegister("_LoadWaiting")
        Case $GUI_Button_Forward
            _IEAction($oIE, "forward")
            AdlibRegister("_LoadWaiting")
        Case $GUI_Button_Stop
            _IEAction($oIE, "stop")
            AdlibRegister("_LoadWaiting")
        Case $GUI_Button_Go
            $urlValue = GUICtrlRead($url)
            _IENavigate($oIE, $urlValue, 0)
            AdlibRegister("_LoadWaiting")
    EndSwitch
WEnd

Func _LoadWaiting()
    If _IELoadWait($oIE, 0, 0) Then
        $urlGet = _IEPropertyGet($oIE, "locationurl")
        GUICtrlSetData($url, $urlGet)
        AdlibUnRegister("_LoadWaiting")
    EndIf
EndFunc   ;==>_LoadWaiting

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...