Jump to content

Recommended Posts

Posted

Hi,

Very new to AutoIt so hoping someone can help me out.

I have a script where on one tab when I click a button control it runs a process in the background. As this runs a GIF is displayed. However if the tab is changed whilst this process is running I want the GIF to be hidden. And then to show again if the tab is changed back to the original tab.

I have come up with a somewhat simplified example to demonstrate what I am trying to do. When I click the Run button, the AutoIt icon is displayed (I just used CreateGIF here as this is a UDF similar to my original script) but when I switch to Tab1 during the Run, the icon is still displayed. Once the function has completed the code I have in the while loop does hide the icon as I wish. But i want this to also happen while the function is running.

I have been trying to get this going using GUIRegisterMSG & WM_COMMAND having researched online but I am really struggling to come up with a way to identify the change of tab using this.

Could someone point me in the right direction?

I included the GIFanimation.udf for reference if needed as I don't think this comes as standard.

Thanks

 

TabChangeDetect_Example.au3 GIFAnimation.au3

Posted
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include "GIFAnimation.au3"

Global $RunningGIF1


Opt("GUIOnEventMode", 1)

$Gui = GUICreate("Main GUI", 400, 400, -1, -1)
$hTab = GUICtrlCreateTab(5, 5, 390, 390)
$Control = GUICtrlCreateTabItem('Tab0')
$Runbutton = GUICtrlCreateButton("Run", 20, 50, 50, 50)

GUICtrlSetOnEvent($Runbutton, "action")
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")

GUICtrlCreateTabItem("Tab1")
GUICtrlCreateTabItem("")



GUISetState()
$iLastTab = 0

While 1
    ; Check which Tab is active
    $iCurrTab = GUICtrlRead($hTab)
    ; If the Tab has changed
    If $iCurrTab <> $iLastTab Then
        ; Show/Hide controls as required
        Switch $iCurrTab
            Case 0
                ConsoleWrite('On tab 0' & @CRLF)
                GUICtrlSetState($RunningGIF1, $GUI_SHOW)
            Case 1
                ConsoleWrite('On tab 1' & @CRLF)
                GUICtrlSetState($RunningGIF1, $GUI_HIDE)
        EndSwitch
        ; Store the value for future comparisons
        $iLastTab = $iCurrTab
    EndIf
    Sleep(100)
WEnd


Func action()
    ConsoleWrite('Running.....' & @CRLF)
    $RunningGIF1 = _GUICtrlCreateGIF('C:\Program Files (x86)\AutoIt3\Icons\au3.ico', "", 150, 150, 100, 100)
    Sleep(5000)
    ConsoleWrite('Finished Running.....' & @CRLF)
EndFunc   ;==>action

Func Close()
    Exit
EndFunc   ;==>Close
3 minutes ago, Wexican90 said:

Hi,

Very new to AutoIt so hoping someone can help me out.

I have a script where on one tab when I click a button control it runs a process in the background. As this runs a GIF is displayed. However if the tab is changed whilst this process is running I want the GIF to be hidden. And then to show again if the tab is changed back to the original tab.

I have come up with a somewhat simplified example to demonstrate what I am trying to do. When I click the Run button, the AutoIt icon is displayed (I just used CreateGIF here as this is a UDF similar to my original script) but when I switch to Tab1 during the Run, the icon is still displayed. Once the function has completed the code I have in the while loop does hide the icon as I wish. But i want this to also happen while the function is running.

I have been trying to get this going using GUIRegisterMSG & WM_COMMAND having researched online but I am really struggling to come up with a way to identify the change of tab using this.

Could someone point me in the right direction?

I included the GIFanimation.udf for reference if needed as I don't think this comes as standard.

Thanks

 

TabChangeDetect_Example.au3 1.36 kB · 1 download GIFAnimation.au3 68.62 kB · 0 downloads

 

Posted (edited)

Hi

it's just about your sleep. So when you really want to start a program you can do it like

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include "GIFAnimation.au3"

Global $RunningGIF1


Opt("GUIOnEventMode", 1)

$Gui = GUICreate("Main GUI", 400, 400, -1, -1)
$hTab = GUICtrlCreateTab(5, 5, 390, 390)
$Control = GUICtrlCreateTabItem('Tab0')
$Runbutton = GUICtrlCreateButton("Run", 20, 50, 50, 50)

GUICtrlSetOnEvent($Runbutton, "action")
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")

GUICtrlCreateTabItem("Tab1")
GUICtrlCreateTabItem("")



GUISetState()
$iLastTab = 0

While 1
    ; Check which Tab is active
    $iCurrTab = GUICtrlRead($hTab)
    ; If the Tab has changed
    If $iCurrTab <> $iLastTab Then
        ; Show/Hide controls as required
        Switch $iCurrTab
            Case 0
                ConsoleWrite('On tab 0' & @CRLF)
                GUICtrlSetState($RunningGIF1, $GUI_SHOW)
            Case 1
                ConsoleWrite('On tab 1' & @CRLF)
                GUICtrlSetState($RunningGIF1, $GUI_HIDE)
        EndSwitch
        ; Store the value for future comparisons
        $iLastTab = $iCurrTab
    EndIf
    Sleep(100)
WEnd


Func action()
    ConsoleWrite('Running.....' & @CRLF)
    $RunningGIF1 = _GUICtrlCreateGIF('C:\Program Files\AutoIt3\Icons\au3.ico', "", 150, 150, 100, 100)
    $cache  = GUICtrlRead($hTab)
    Do
    Sleep ( 100 )
    Until $cache <> GUICtrlRead ($hTab)

    ConsoleWrite('Finished Running.....' & @CRLF)
EndFunc   ;==>action

Func Close()
    Exit
EndFunc   ;==>Close

Because your program will be run and the script continue. 

You should delete the GIF after the Do Until loop because it will appear twice if you click run again...

but if you run program you should compare it to it like processexist or something

hope that helps 😃

Edited by Aelc

why do i get garbage when i buy garbage bags? <_<

Posted

@Wexican90  I would not touch this UDF even if my life was depending on it.  In my case, it makes my computer crash literally after awhile. So I prefer using an AdlibRegister approach where you display frame by frame at a certain rate that you can extract from the GIF file or you can set a constant rate.  Look at _GDIPlus_ImageGetFrameCount example to have an idea how you could manage it with a timer.  Once your GIF is properly working, you are freeing your main GUI loop.  And it will make your programming life easier...

Posted

@Aelc Thanks for your response. I just realised I may not have explained the problem correctly.

So in my actual script the sleep function is replaced by a Run function which runs a process in the background (typically takes 20 seconds or so). As this process is running  I would like to be able to detect a tab change and hide the GIF if the tab is moved from the current tab. I have just simplified the script to illustrate the problem but had not explained it correctly, apologies.

So in your revised script, if I increase the Sleep to 20 seconds, and hit Run, I would like the GIF to be hidden when tab 1 is being viewed within this 20 second interval.

Do you know how this could be done?

 

@Nine thanks for this info. Being new enough to this, i'm not aware which UDFs are to be avoided, good to know. I will take a look at _GDIPlus_ImageGetFrameCount as an alternative.

 

Posted
4 hours ago, Wexican90 said:

@Aelc Thanks for your response. I just realised I may not have explained the problem correctly.

So in my actual script the sleep function is replaced by a Run function which runs a process in the background (typically takes 20 seconds or so). As this process is running  I would like to be able to detect a tab change and hide the GIF if the tab is moved from the current tab. I have just simplified the script to illustrate the problem but had not explained it correctly, apologies.

So in your revised script, if I increase the Sleep to 20 seconds, and hit Run, I would like the GIF to be hidden when tab 1 is being viewed within this 20 second interval.

Do you know how this could be done?

 

Wait .. TAB 1 is already viewied then. do you mean TAB 2?

anyway this should help... You can adjust the tabs if necessary.

still the solution of @Nine would be more clean i guess :) damn dude :P 

SO step by step:

 - Your While Loop is not retouched. I just used a func to call it later because it's the same what we use

- _action Running the GIF and your Process you want ( Adjust the Path in Top ! )

- The Do loop sleep and checks if the Tab is changed. When it is it hides the GIF

- this will be done until Your process isn't running anymore.

- delete the GIF

Hope that helps :)

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include "GIFAnimation.au3"

Global $RunningGIF1


Opt("GUIOnEventMode", 1)

$Gui = GUICreate("Main GUI", 400, 400, -1, -1)
$hTab = GUICtrlCreateTab(5, 5, 390, 390)
$Control = GUICtrlCreateTabItem('Tab0')
$Runbutton = GUICtrlCreateButton("Run", 20, 50, 50, 50)

$RunningProcessPath = "YOUR_Process_Path.exe"

GUICtrlSetOnEvent($Runbutton, "action")
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")

GUICtrlCreateTabItem("Tab1")
GUICtrlCreateTabItem("")



GUISetState()
$iLastTab = 0

While 1
    ; Check which Tab is active
    $iCurrTab = GUICtrlRead($hTab)
    ; If the Tab has changed
    If $iCurrTab <> $iLastTab Then
        ; Show/Hide controls as required
        _Adjust_Ctrl($iCurrTab)
        ; Store the value for future comparisons
        $iLastTab = $iCurrTab
    EndIf
    Sleep(100)
WEnd


Func action()
    ConsoleWrite('Running.....' & @CRLF)
    $RunningGIF1 = _GUICtrlCreateGIF('C:\Program Files\AutoIt3\Icons\au3.ico', "", 150, 150, 100, 100)
    $PID = Shellexecute($RunningProcessPath)
    Do
    Sleep ( 100 )
    $cache  = GUICtrlRead($hTab)
    _Adjust_Ctrl ($cache)
    Until Processexists ( $PID ) <> True
    _GIF_DeleteGIF($RunningGIF1)
    ConsoleWrite('Finished Running.....' & @CRLF)
EndFunc   ;==>action

Func Close()
    Exit
EndFunc   ;==>Close

Func _Adjust_Ctrl($switch)
        Switch $switch
            Case 0
                ConsoleWrite('On tab 0' & @CRLF)
                GUICtrlSetState($RunningGIF1, $GUI_SHOW)
            Case 1
                ConsoleWrite('On tab 1' & @CRLF)
                GUICtrlSetState($RunningGIF1, $GUI_HIDE)
        EndSwitch
EndFunc

 

why do i get garbage when i buy garbage bags? <_<

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
×
×
  • Create New...