Jump to content
Sign in to follow this  
johnmcloud

AdlibRegister for 2 Func

Recommended Posts

johnmcloud

Hi guys,

I'dl like to use the same AdlibRegister for to different function. That's an example:

#include <GUIConstantsEx.au3>

Global $hButton3 = 9999, $Increase = 0, $hGUI1

gui1()

Func gui1()
$hGUI1 = GUICreate("Gui 1", 200, 200, 100, 100)
$hButton1 = GUICtrlCreateButton("Adlib1", 10, 10, 80, 30)
$hButton2 = GUICtrlCreateButton("Show Gui 2", 10, 60, 80, 30)
GUISetState()

While 1
  Switch GUIGetMsg()
   Case $GUI_EVENT_CLOSE
    ExitLoop
   Case $hButton1
    AdlibRegister("Test", 400)
    Sleep(2000)
    AdlibUnRegister("Test")
    WinSetTitle($hGUI1, "", "Gui 1")
   Case $hButton2
    GUICtrlSetState($hButton2, $GUI_DISABLE)
    gui2()
   Case $hButton3
    AdlibRegister("Test", 400)
    Sleep(2000)
    AdlibUnRegister("Test")
    WinSetTitle($hGUI1, "", "Gui 1")
  EndSwitch
WEnd
EndFunc   ;==>gui1

Func gui2()
$hGUI2 = GUICreate("Gui 2", 200, 200, 350, 350)
$hButton3 = GUICtrlCreateButton("Adlib2", 10, 10, 80, 30)
GUISetState()
EndFunc   ;==>gui2

Func Test()
Switch Mod($Increase, 4)
  Case 0
   WinSetTitle($hGUI1, "", "... A")
  Case 1
   WinSetTitle($hGUI1, "", "... B")
  Case 2
   WinSetTitle($hGUI1, "", "... C")
  Case 3
   WinSetTitle($hGUI1, "", "... D")
EndSwitch
$Increase += 1
EndFunc   ;==>Test

I have try to make an handle like:

Func Test($handle)
Switch Mod($Increase, 4)
  Case 0
   WinSetTitle($handle, "", "... A")
  Case 1
   WinSetTitle($handle, "", "... B")
  Case 2
   WinSetTitle($handle, "", "... C")
  Case 3
   WinSetTitle($handle, "", "... D")
EndSwitch
$Increase += 1
EndFunc   ;==>Test
[autoit]

and make:
[autoit] 
AdlibRegister("Test(" & $hGUI1 & ")",400)

But not work, some advice?

Thanks ;)

Share this post


Link to post
Share on other sites
water

You can't pass parameters to Adlibregister. Hence

AdlibRegister("Test(" & $hGUI1 & ")",400)
won't work.

The way you use AdLibRegister (register, wait a few seconds and unregister in a loop) I would simply call test as a function.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
johnmcloud

So, if i have understad well, i can't call the same Test() for two different function?

I need to create two different like:

Func Test_GUI1()
Switch Mod($Increase, 4)
Case 0
WinSetTitle($hGUI1, "", "... A")
Case 1
WinSetTitle($hGUI1 "", "... B")
Case 2
WinSetTitle($hGUI1, "", "... C")
Case 3
WinSetTitle($hGUI1, "", "... D")
EndSwitch
$Increase += 1
EndFunc
 
Func Test_GUI2()
Switch Mod($Increase, 4)
Case 0
WinSetTitle($hGUI2, "", "... A")
Case 1
WinSetTitle($hGUI2, "", "... B")
Case 2
WinSetTitle($hGUI2, "", "... C")
Case 3
WinSetTitle($hGUI2, "", "... D")
EndSwitch
$Increase += 1
EndFunc

There isn't a workaround?

Edited by johnmcloud

Share this post


Link to post
Share on other sites
water

You can use AdLibRegister for two different functions. But the way you use AdLibRegister doesn't make sense. Simply call Test() and pass parameters if needed.

AdLibRegister is used to call a function every x milliseconds while the main script keeps on processing.

You register the function, Sleep and then unregister the function. That's not what AdLibRegister should be used for.

Is this a real life problem you try to solve or do you just play around?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
johnmcloud

No, that's a real life problem.

I have posted an example script, but the goal is the same...so i need to create 2 separate but same function because i can't make handle to adblibregister.

Share this post


Link to post
Share on other sites
water

You don't need two functions, just drop AdLiBRegister.

#include <GUIConstantsEx.au3>

Global $hButton3 = 9999, $Increase = 0, $hGUI1

gui1()

Func gui1()
    $hGUI1 = GUICreate("Gui 1", 200, 200, 100, 100)
    $hButton1 = GUICtrlCreateButton("Adlib1", 10, 10, 80, 30)
    $hButton2 = GUICtrlCreateButton("Show Gui 2", 10, 60, 80, 30)
    GUISetState()
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $hButton1
                Test($hGUI1)
                Sleep(2000)
                WinSetTitle($hGUI1, "", "Gui 1")
            Case $hButton2
                GUICtrlSetState($hButton2, $GUI_DISABLE)
                gui2()
            Case $hButton3
                Test($hGUI1)
                Sleep(2000)
                WinSetTitle($hGUI1, "", "Gui 1")
        EndSwitch
    WEnd
EndFunc   ;==>gui1

Func gui2()
    $hGUI2 = GUICreate("Gui 2", 200, 200, 350, 350)
    $hButton3 = GUICtrlCreateButton("Adlib2", 10, 10, 80, 30)
    GUISetState()
EndFunc   ;==>gui2

Func Test($hGUI)
    Switch Mod($Increase, 4)
        Case 0
            WinSetTitle($hGUI, "", "... A")
        Case 1
            WinSetTitle($hGUI, "", "... B")
        Case 2
            WinSetTitle($hGUI, "", "... C")
        Case 3
            WinSetTitle($hGUI, "", "... D")
    EndSwitch
    $Increase += 1
EndFunc   ;==>Test

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • Bilgus
      By Bilgus
      Apparently you can't use a function with variables for AdlibRegister
      Like you declare it with a variable even an optional one and it throws an error if you try and call it
      Thats ok though I figured out a hack using eval to get a better result
      Registered_Funct(250);Register Sleep(10000) Registered_Funct(-1);UnRegister Func Registered_Funct($iTime = -1) Local $i_Time = Eval("iTime") If $i_Time > 0 Then AdlibRegister("Registered_Funct", $i_Time) ElseIf $i_Time < 0 Then AdlibUnRegister("Registered_Funct") Else ConsoleWrite("Do Stuff") EndIf EndFunc
      Surely it has an impact on efficiency though...
    • Miliardsto
      By Miliardsto
      Is there any difference in timers and AdlibRegister ?
      in :
      performance usage reliability or any kind of difference I want use few timers at once so it will make difference.
      I have problem with timers and I saw AdlibRegister behaves similar like:
      wont stop crashing slowing program so much maybe is there any trick to make it better?
    • badcoder123
      By badcoder123
      Hey everyone,
      I've been messing around with some new things and adlibs look extremely useful/interesting, however, I can't seem to get it to work.. Here's what I have
      HotKeySet("{F1}", "_Exit") $qCount = 1 Global $_Timer AdlibRegister($_Timer, 1000) AdlibUnRegister($_Timer) While 1 SoundPlay(@WindowsDir & "\media\tada.wav", 1) $qCount += 1 ToolTip('"Tada" has been played ' & $qCount & " times",200,200) WEnd Func _Timer() Local Static $iCount += 1 ConsoleWrite($iCount) If $iCount = 20 Then ConsoleWrite("iCount is at " & $iCount) EndFunc Func _Exit() Exit EndFunc Basically I want it to call the _Timer function but it doesn't seem to work :/ any ideas?
    • timmy2
      By timmy2
      I'm writing a small prog that will run in the background and sound an alarm if a certain Gmail message arrives in an otherwise unused account.
      My inclination is to use a simple While/WEnd loop with a 5 minute Sleep between checking for messages, but I've seen examples here of somewhat similar background tasks that employ AdlibRegister so I'm curious which method is the most reliable and least impactful on the CPU.  Below are two simple scripts that begin to do what I want and represent how I think this could be handled.
      While/WEnd with Sleep
      #include <CheckMail.au3> Global $aReturn Global $iEmails While 1 $aReturn = CheckMail("username", "password") $iEmails = @extended If $iEmails > 0 ExitLoop Sleep(300000) ; check for new messages every 5 minutes WEnd ;work with contents of $aReturn array that contains the new message(s) found  
      While/WEnd with Sleep and AdlibRegister
      #include <CheckMail.au3> Global $aReturn Global $iEmails = 0 AdlibRegister('_CallCheckMail',300000) ; check for new messages every 5 minutes While 1 Sleep(500000) ; I had to put something here. Does higher the value = less CPU demand? If $iEmails > 0 ExitLoop WEnd ;work with contents of $aReturn array that contains the new message(s) found Func _CallCheckMail $aReturn = CheckMail("username", "password") $iEmails = @extended Return EndFunc  
    • JScript
      By JScript
      Function Reference
      _AdlibEnhance.au3
      Adlib function with support for parameters, pause and resume using Call Back!

      Sintax:


      _Adlib_Register( "Function" [, "Params" [, Time [, RepeatCount ]]] ) _Adlib_Pause( "Function" ) _Adlib_Resume( "Function" ) _Adlib_SetTimer( "Function" [, Time ] ) _Adlib_UnRegister( "Function" )
      Supports:


      ; You can call functions with parameters and native functions also!
      Downloads:

      Version: 0.10
      _AdlibEnhance_(RedirectLink).html

      Note: Usage example is included!

      Sample:



      Fixes:


      Regards,

      João Carlos.
×