Wexican90 Posted March 29, 2020 Posted March 29, 2020 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
Wexican90 Posted March 29, 2020 Author Posted March 29, 2020 expandcollapse popup#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
Aelc Posted March 30, 2020 Posted March 30, 2020 (edited) Hi it's just about your sleep. So when you really want to start a program you can do it like expandcollapse popup#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 March 30, 2020 by Aelc why do i get garbage when i buy garbage bags?
Nine Posted March 30, 2020 Posted March 30, 2020 @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... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Wexican90 Posted March 30, 2020 Author Posted March 30, 2020 @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.
Nine Posted March 30, 2020 Posted March 30, 2020 38 minutes ago, Wexican90 said: I will take a look at _GDIPlus_ImageGetFrameCount as an alternative. Let me know if you need help to translate it into AdLibRegister “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Aelc Posted March 31, 2020 Posted March 31, 2020 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 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 expandcollapse popup#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?
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now