Jump to content

Need assistance with loop for browser refresh


 Share

Go to solution Solved by SmOke_N,

Recommended Posts

Hello guys & gals, So I was wondering if you could help me out with this script. I have two embedded browsers an am looking to have 2 functions. _Func_1 () will control $start which  would be a loop that will continously refesh browser 1. _Func_2() will stop _Func_1(). Below is my attempt of what I am trying to accomplish, so any help would be greatly appreciated :)

 

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




Opt("GUIOnEventMode", 1)
Example()




Func Example()
    Local $idButton_Back, $idButton_Forward
    Local $idButton_Home, $idButton_Stop, $iMsg


    $oIE1 = _IECreateEmbedded()
    $oIE2 = _IECreateEmbedded()


    GUICreate("Browser Refresher",@DesktopWidth , @DesktopHeight,0,0)
    GUICtrlCreateObj($oIE1, 1, 1, 900, 360)
GUICtrlCreateObj($oIE2, 950, 1, 900, 1000)


$start = GuiCtrlCreateButton ("Start Refresher",10,450,100,30)
GUICtrlSetOnEvent($start, "_Func_1")
    $stop = GuiCtrlCreateButton ("Stop Refresher",10,480,100,30)
GUICtrlSetOnEvent($start, "_Func_2")


GUISetState(@SW_SHOW) ;Show GUI


    $oIE1.navigate("https://login.salesforce.com/")
$oIE2.navigate("https://login.salesforce.com/")
EndFunc




    While 1
        $iMsg = GUIGetMsg()
Wend


Func _Func_1()
If $start = True Then
       $oIE1.refresh
 Sleep(10000)
 EndIf
EndFunc


Func _Func_2()
If $stop = True Then
    Msg Box (0,"The Refresher has stopped", "The Refresher has stopped!")
EndIf
EndFunc

 

Link to comment
Share on other sites

So I think I am getting closer, here is what I added:

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




Opt("GUIOnEventMode", 1)

    Local $idButton_Back, $idButton_Forward
    Local $idButton_Home, $idButton_Stop, $iMsg


    $oIE1 = _IECreateEmbedded()
    $oIE2 = _IECreateEmbedded()
    $refresh = $oIE1.refresh
    $iMsg = GUIGetMsg


    GUICreate("Browser Refresher",@DesktopWidth , @DesktopHeight,0,0)
    GUICtrlCreateObj($oIE1, 1, 1, 900, 360)
GUICtrlCreateObj($oIE2, 950, 1, 900, 1000)


$start = GuiCtrlCreateButton ("Start Refresher",10,450,100,30)
$oIE1.navigate("https://login.salesforce.com/")
$stop = GuiCtrlCreateButton ("Stop Refresher",10,480,100,30)
$oIE2.navigate("https://login.salesforce.com/")

While 1
GUISetState(@SW_SHOW) ;Show GUI
Switch $iMsg
Case $iMsg = $start
   MsgBox (0,"Refresher has started", "Refresher has started")
   If $oDiv = _IEGetObjById($oIE1, "login") Then $refresh
endswitch
Wend
Link to comment
Share on other sites

I can tell you that you should not/can not use Opt("GUIOnEventMode", 1) and a GUIGetMsg loop.

Also you have put that GUIGetMsg in a variable and are calling it without parenthesis 

And I'm not sure you can call an object method, from a variable like you do

$refresh = $oIE1.refresh

If $oDiv = _IEGetObjById($oIE1, "login") Then $refresh

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

John,

Thanks for the input. I changed up the way to go about this. I have the refresh working now. but would it be possible to stop the do loop. I am looking but everything I try does not seem to work. Below is what I have now: 

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

    Local $idButton_Back, $idButton_Forward
    Local $idButton_Home, $idButton_Stop, $iMsg


    $oIE1 = _IECreateEmbedded()
    $oIE2 = _IECreateEmbedded()



    GUICreate("Browser Refresher",@DesktopWidth , @DesktopHeight,0,0)
    GUICtrlCreateObj($oIE1, 1, 1, 900, 360)
GUICtrlCreateObj($oIE2, 950, 1, 900, 1000)


$start = GuiCtrlCreateButton ("Start Refresher",10,450,100,30)
$oIE1.navigate("https://login.salesforce.com/")
$stop = GuiCtrlCreateButton ("Stop Refresher",10,480,100,30)
$oIE2.navigate("https://login.salesforce.com/")

While 1

GUISetState(@SW_SHOW) ;Show GUI
Local $iMsg = GUIGetMsg()
SELECT
Case $iMsg = $GUI_EVENT_CLOSE
            ExitLoop
         Case $iMsg = $stop
        MsgBox (0,"Refresher has stopped", "Refresher has stopped")

Case $iMsg = $start
   MsgBox (0,"Refresher has started", "Refresher has started")
      Do
       Sleep (10000)
       $oIE1.refresh
       Until $iMsg = $stop

EndSelect
Wend
Link to comment
Share on other sites

  • Moderators
  • Solution

Not a fan of how you have this setup.. but to solve your issue using your own code:

Do
                $oIE1.refresh
            Until GUIGetMsg() = $stop

Your issue.

1.  You're in a loop, which has no access to GUIGetMsg()

2.  GUIGetMsg() refreshes every 250 ms so your Sleep is killing it even if it did register

3.  If you wanted wait for the msg, catch GUIGetMsg() from the second loop as demonstrated above and remove the sleep() (again, won't work with that sleep).

Way I'd probably do it.

1.  Create a function that uses global $oIE1.refresh

2.  Use call function from 1. when it is pressed

3.  Right after the function call use AdlibRegister for the function from 1. and set the timer for 10 seconds like you had with sleep

4.  In stop area, use AdlibUnregister

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Thanks Smoke,

I figured out a way using the HotKey now at this point. I really appreciate your input. Here is my final script!

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

    Local $idButton_Back, $idButton_Forward
    Local $idButton_Home, $idButton_Stop, $iMsg
HotKeySet("{F1}", "_Continue")
Dim $binFlag = False

    $oIE1 = _IECreateEmbedded()
    $oIE2 = _IECreateEmbedded()
    $counter = False

GUICreate("Browser Refresher",@DesktopWidth , @DesktopHeight,0,1,$WS_MAXIMIZEBOX)
GUISetState()
GUICtrlCreateObj($oIE1, 1, 1, 900, 360)
GUICtrlCreateObj($oIE2, 950, 1, 900, 1000)


$start = GuiCtrlCreateButton ("Start Refresher",10,450,100,30)
$oIE1.navigate("https://login.salesforce.com/")
$oIE2.navigate("https://login.salesforce.com/")


While $counter = False
GUISetState(@SW_SHOW) ;Show GUI
Local $iMsg = GUIGetMsg()
SELECT
Case $iMsg = $GUI_EVENT_CLOSE
            ExitLoop


Case $iMsg = $start
   MsgBox (0,"Refresher has started", "Refresher has started")
      Do
       Sleep (10000)
       $oIE1.refresh
       GUICtrlSetState ($start, $GUI_DISABLE)
       GUICtrlSetdata ($start, "Press F1 to Disable")
    Until $binFlag = True
    GUICtrlSetState($start, $GUI_ENABLE)
    GUICtrlSetdata ($start, "Start Refresher")


EndSelect
Wend

Func _Continue()
    $binFlag = Not $binFlag
EndFunc
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...