happytc Posted August 11, 2011 Share Posted August 11, 2011 Following code: when hiting 'start1' Button and 'start2' button, how to make two LABEL display simultaneously? expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiButton.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) Dim $stop = 0 $f = GUICreate('interruption-loop-event', 300, 80) $bt = _GUICtrlButton_Create($f, 'stop', 10, 10, 60, 20) $l = GUICtrlCreateLabel('', 10, 30, 50, 20) $l2 = GUICtrlCreateLabel('', 100, 30, 50, 20) $bt1 = GUICtrlCreateButton('start1', 80, 10, 50, 20) GUICtrlSetOnEvent(-1, '_Click') $bt3 = GUICtrlCreateButton('start2', 150, 10, 50, 20) GUICtrlSetOnEvent(-1, '_Click2') GUISetState() GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUIRegisterMsg($WM_SYSCOMMAND, "On_WM_SYSCOMMAND") Func On_WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam) Local Const $SC_MOVE = 0xF010 Local Const $SC_SIZE = 0xF000 Local Const $SC_CLOSE = 0xF060 If $hWnd = $f Then Switch BitAND($wParam, 0xFFF0) Case 61472 ConsoleWrite("Minimize detected" & @CRLF) Case 61488 ConsoleWrite("Maximize detected" & @CRLF) Case 61728 ConsoleWrite("Restore detected" & @CRLF) Case $SC_MOVE ConsoleWrite("WM_Move detected" & @CRLF) Case $SC_SIZE ConsoleWrite("WM_Size detected" & @CRLF) Case $SC_CLOSE ConsoleWrite("WM_Close detected" & @CRLF) Exit ; Return -1 ; to intercept close EndSwitch EndIf Return $GUI_RUNDEFMSG EndFunc ;==>On_WM_SYSCOMMAND Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam) #forceref $hWnd, $Msg Local $nNotifyCode = BitShift($wParam, 16) Local $nID = BitAND($wParam, 0x0000FFFF) Local $hCtrl = $lParam If $hCtrl = $bt And $nNotifyCode = $BN_CLICKED Then $stop = 1 EndFunc ;==>WM_COMMAND Func _click() $n = 1 $stop = 0 While 1 GUICtrlSetData($l, $n) Sleep(100) $n = $n + 1 If $stop = 1 Then $stop = 0 ExitLoop EndIf WEnd EndFunc ;==>_click Func _click2() $n = 1 $stop = 0 While 1 GUICtrlSetData($l2, $n) Sleep(100) $n = $n + 1 If $stop = 1 Then $stop = 0 ExitLoop EndIf WEnd EndFunc ;==>_click2 While 1 Sleep(100) WEnd Link to comment Share on other sites More sharing options...
UEZ Posted August 11, 2011 Share Posted August 11, 2011 Try this: expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiButton.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) Dim $stop = 0 $f = GUICreate('interruption-loop-event', 300, 80) $bt = GUICtrlCreateButton('stop', 10, 10, 60, 20) GUICtrlSetOnEvent(-1, '_Stop') $l1 = GUICtrlCreateLabel('', 100, 40, 50, 20) $l2 = GUICtrlCreateLabel('', 170, 40, 50, 20) $bt1 = GUICtrlCreateButton('start1', 80, 10, 50, 20) GUICtrlSetOnEvent(-1, '_Click1') $bt3 = GUICtrlCreateButton('start2', 150, 10, 50, 20) GUICtrlSetOnEvent(-1, '_Click2') GUISetState() $ad1 = False $ad2 = False GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") While 1 Sleep(100) WEnd Func _Stop() AdlibUnRegister("Counter1") AdlibUnRegister("Counter2") $ad1 = False $ad2 = False EndFunc Func _click1() If Not $ad1 Then AdlibRegister("Counter1", 100) $ad1 = True EndIf EndFunc ;==>_click1 Func _click2() If Not $ad2 Then AdlibRegister("Counter2", 200) $ad2 = True EndIf EndFunc ;==>_click2 Func Counter1() Local Static $c = 0 GUICtrlSetData($l1, $c) $c += 1 EndFunc Func Counter2() Local Static $c = 0 GUICtrlSetData($l2, $c) $c += 1 EndFunc Func _Exit() _Stop() Exit EndFunc Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
happytc Posted August 11, 2011 Author Share Posted August 11, 2011 The second LABEL was shown in slow motion! I knew Autoit not to support multithreading(It's a big pity). But when needing multithreading, how to use skill instead of it? The adlib function? Try this: expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiButton.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) Dim $stop = 0 $f = GUICreate('interruption-loop-event', 300, 80) $bt = GUICtrlCreateButton('stop', 10, 10, 60, 20) GUICtrlSetOnEvent(-1, '_Stop') $l1 = GUICtrlCreateLabel('', 100, 40, 50, 20) $l2 = GUICtrlCreateLabel('', 170, 40, 50, 20) $bt1 = GUICtrlCreateButton('start1', 80, 10, 50, 20) GUICtrlSetOnEvent(-1, '_Click1') $bt3 = GUICtrlCreateButton('start2', 150, 10, 50, 20) GUICtrlSetOnEvent(-1, '_Click2') GUISetState() $ad1 = False $ad2 = False GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") While 1 Sleep(100) WEnd Func _Stop() AdlibUnRegister("Counter1") AdlibUnRegister("Counter2") $ad1 = False $ad2 = False EndFunc Func _click1() If Not $ad1 Then AdlibRegister("Counter1", 100) $ad1 = True EndIf EndFunc ;==>_click1 Func _click2() If Not $ad2 Then AdlibRegister("Counter2", 200) $ad2 = True EndIf EndFunc ;==>_click2 Func Counter1() Local Static $c = 0 GUICtrlSetData($l1, $c) $c += 1 EndFunc Func Counter2() Local Static $c = 0 GUICtrlSetData($l2, $c) $c += 1 EndFunc Func _Exit() _Stop() Exit EndFunc Br, UEZ Link to comment Share on other sites More sharing options...
UEZ Posted August 11, 2011 Share Posted August 11, 2011 The second LABEL was shown in slow motion!I knew Autoit not to support multithreading(It's a big pity). But when needing multithreading, how to use skill instead of it?The adlib function?Look in helpfile for AdlibRegister to understand why 2nd lable is in "slow motion". Adlib is one possiblity to use it as "multithreading". Other check out the _Timer_x() functions.Br,UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
BrewManNH Posted August 11, 2011 Share Posted August 11, 2011 If you look at the second AdLibRegister function for Start2, you will see that the delay is twice the delay of start1 which is why it is running at half the speed of the first one. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
happytc Posted August 11, 2011 Author Share Posted August 11, 2011 Look in helpfile for AdlibRegister to understand why 2nd lable is in "slow motion". Adlib is one possiblity to use it as "multithreading". Other check out the _Timer_x() functions.Br,UEZIf you look at the second AdLibRegister function for Start2, you will see that the delay is twice the delay of start1 which is why it is running at half the speed of the first one.You are so kind to reply.yeah, I knew the reason why 2nd LABEL was delayed to show.I'm lookig for a method it can make TWO LABEL shown at the same speed, like real multithreading Link to comment Share on other sites More sharing options...
BrewManNH Posted August 11, 2011 Share Posted August 11, 2011 Did you TRY adjusting the delay of the second label's AdLibRegister? Because if you do, they're nearly simultaneous. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
MvGulik Posted August 11, 2011 Share Posted August 11, 2011 (edited) ... mmm ...expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiButton.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> ;; $SS_BLACKFRAME ;; test run options. Global _ $iLockExampleDelay = 66, _ $fLock = True ;; False|True ;; timer managers. Global _ $gaTimers[3], _ $gfTimerActive = False, _ $giTimerInterval = 357 ;; N > 2x or 3x$iLockExampleDelay Global $ghGui, $giCounterLable1 _GuiSetup($ghGui, $giCounterLable1) _Idle() Exit ;; aka: no more root code. Func _ActivateTimerN($iN) ;; behavior: Start, Stop, (Reset &) Restart. If $gaTimers[$iN] Then $gaTimers[$iN] = 0 Else $gaTimers[$iN] = TimerInit() EndIf If Not $gfTimerActive Then $gfTimerActive = True AdlibRegister("_Counter", $giTimerInterval) EndIf EndFunc Func _Counter() If Not $gfTimerActive Then AdlibUnRegister() ;; option A.2 if $fLock Then GUISetState(@SW_LOCK, $ghGui) If $gaTimers[0] Then GUICtrlSetData($giCounterLable1 + 0, Round(TimerDiff($gaTimers[0]) / 1000, 3)) ;; loop candidate. Sleep($iLockExampleDelay) If $gaTimers[1] Then GUICtrlSetData($giCounterLable1 + 1, Round(TimerDiff($gaTimers[1]) / 1000, 3)) Sleep($iLockExampleDelay) If $gaTimers[2] Then GUICtrlSetData($giCounterLable1 + 2, Round(TimerDiff($gaTimers[2]) / 1000, 3)) if $fLock Then GUISetState(@SW_UNLOCK, $ghGui) EndFunc Func _stop() $gfTimerActive = False AdlibUnRegister() ;; option A.1 $gaTimers[0] = 0 ;; loop candidate. $gaTimers[1] = 0 $gaTimers[2] = 0 EndFunc Func _click1() _ActivateTimerN(0) EndFunc Func _click2() _ActivateTimerN(1) EndFunc Func _click3() _ActivateTimerN(2) EndFunc Func _Idle() While 1 Sleep(100) WEnd EndFunc Func _Exit() _Stop() Exit EndFunc Func _GuiSetup(ByRef $hGui, ByRef $icCounterLable1) Local Const $1=80, $2=20, $3=50 Opt("GUIOnEventMode", 1) $hGui = GUICreate('interruption-loop-event', 300, 80) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") ;; global stop button. GUICtrlCreateButton('Stop', 10, 10, 60, 20) GUICtrlSetOnEvent(-1, '_stop') ;; timer buttons. GUICtrlCreateButton('start1', 80, 10, $3, $2) GUICtrlSetOnEvent(-1, '_Click1') GUICtrlCreateButton('start2', 140, 10, $3, $2) GUICtrlSetOnEvent(-1, '_Click2') GUICtrlCreateButton('start3', 200, 10, $3, $2) GUICtrlSetOnEvent(-1, '_Click3') ;; output labels. $icCounterLable1 = GUICtrlCreateLabel('', 10, $3, $1, $2) GUICtrlCreateLabel('', 110, $3, $1, $2) GUICtrlCreateLabel('', 210, $3, $1, $2) ;; output label framing. GUICtrlCreateLabel('', 10, $3, $1, $2, $SS_BLACKFRAME) GUICtrlCreateLabel('', 110, $3, $1, $2, $SS_BLACKFRAME) GUICtrlCreateLabel('', 210, $3, $1, $2, $SS_BLACKFRAME) ;; finalize gui. GUISetState() EndFunc(e: bug1: location A.2 seems to be missing something. O well.)(e: issue1: Lock (Or unlock, or ...) will actually initiate a whole Gui repaint. Which I (kinda) forgot.) Edited August 16, 2011 by iEvKI3gv9Wrkd41u "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
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