Sign in to follow this  
Followers 0
xzibit

Autoit GUI Buttons not responding in Loop

10 posts in this topic

Hello all,

i just got Script where im already using:

Opt("GUIOnEventMode", 1)oÝ÷ ÚÊ-«mê'z÷§¶jzÈhºWp¢¹w¢l¬r¸©´ljYh'â²Ö«¶Ø^¦º ­©ºØÞ²ËazËZ®Öî¶Ú'«z+`¡ë%G­+ºÚ"µÍ[ÈÝ

B[H ÌÍÐÛÝ[[H   ÌÍÓX^[H  ÌÍÜ×Ý  ÌÍÜ×Ù[S[YK ÌÍÚÙ[K  ÌÍÜ×Ù[PÛÛ[Ü ÌÍØYÙHHÕRPÝXY
    ÌÍØ
HÈÕRPÝXY
    ÌÍØJBÌÍÜÈHBÌÍØÛÝ[HÜ    ÌÍÜÈHHÈ
ÌÍÜ×ÝH ][ÝÚËÛØØ[ÜÝÜÙXÚÜÏX[    [ØOI][ÝÉ[ÉÌÍØYÙBÌÍÜ×Ù[S[YHHØÜ[É][ÝÉÌLØÛÛ[[    ][ÝÂ[]Ù]
    ÌÍÜ×Ý  ÌÍÜ×Ù[S[YJBÌÍÚÙ[HH[SÜ[    ÌÍÜ×Ù[S[YK
BÌÍÜ×Ù[PÛÛ[H[TXY
    ÌÍÚÙ[H
BÌÍØWÛX]ÚÈHÝ[ÔYÑ^
    ÌÍÜ×Ù[PÛÛ[   ÌÎNÊÚJJÜÊIÙ]ÛÜÏI][ÝÝÙ][ÝÉÝËÖÊ    ÜÜ[ÛÜÏI][ÝÛÉ][ÝÉÝß
WJÊIËÜÜ[ÝÉÌÎNËÊBÜ    ÌÍÚHHÈMBÌÍØWÛX]ÚÖÉÌÍÚWHHÝ[Õ[SY
    ÌÍØWÛX]ÚÖÉÌÍÚWKJBÌÍÓX^HMÌÍØÛÝ[H   ÌÍØÛÝ[
ÈBTÙÜÜÓÛ  ][ÝÐÚXÚÚ[É][ÝË  ][ÝÉ][ÝË    ][ÝÉ][ÝËÚÝÜZYÚHML
BTÙÜÜÔÙ]

    ÌÍÐÛÝ[ÉÌÍÓX^
JL  ][ÝÉ][ÝË    ][ÝÕÙ    ][ÝÈ  [È ÌÍÐÛÝ[ [È ][ÝÈÙ    ][ÝÈ  [È ÌÍÓX^    [È ][ÝÈÝ[][ÝÊB×Ð^QÜ^J  ÌÍØWÛX]ÚË ][ÝÕY][ÝÊBÓÙÐÞ
    ][ÝÐÛÝ[ÝÛ][ÝË   ][ÝÖZ ][ÝÈ  [È ÌÍØWÛX]ÚÖÉÌÍÚWJBÒQS]YØ]H
    ÌÍÛÒQK  ][ÝÚËÛØØ[ÜÝÝÙÉ][ÝÈ [È ÌÍØWÛX]ÚÖÉÌÍÚWKJBÒQSØYØZ]
    ÌÍÛÒQK
B^×Ð^QÜ^J    ÌÍØWÛX]ÚË ][ÝÕY][ÝÊB[PÛÜÙJ ÌÍÚÙ[JB^^ÙÜÜÓÙ
B[[

It works well and it works too if i use Hotkeys instead of buttons hotkeys will stop the script and exit the programm but my normal buttons arent working anymore, also my minimize funktion or exit button at the top corner of the program arent working.

I'll hope some1 can help me out there.

thanks in advance - best regards

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hello all,

i just got Script where im already using:

Opt("GUIOnEventMode", 1)ƒoÝŠ÷ ÚÊ-…«m…ê'z÷§¶jzÈhºWp¢¹Šw¢žl¬r¸©´‹ljYh’'â²Ö«¶Ø^¦º ­©›ºØŸŠšÞ²ËazËZ®Öî¶Ú'«z+`¡ë%ŠG­†+ºÚ"µÍ‘[˜ÈÝ

B‘[H  ˆÌÍŽÐÛÝ[‚‘[H ˆÌÍŽÓX^‘[H   ˆÌÍŽÜ×Ý›   ˆÌÍŽÜ×Ùš[S˜[YK ˆÌÍŽÚÙš[K    ˆÌÍŽÜ×Ùš[PÛÛ[‘›Üˆ   ˆÌÍŽØYÙHHÕRPÝ›™XY
    ˆÌÍŽØŽ
HÈÕRPÝ›™XY
    ˆÌÍŽØŽJB‰ˆÌÍŽÜÈHB‰ˆÌÍŽØÛÝ[ˆH‘›Üˆ  ˆÌÍŽÜÈHHÈ
Œ‰ˆÌÍŽÜ×Ý›H œ][ÝÚ‹ËÛØØ[ÜÝÜÙX˜ÚÜÏX[ ˜[ØOIœ][Ýɘ[ɈÌÍŽØYÙB‰ˆÌÍŽÜ×Ùš[S˜[YHHØÜš‰˜[Éœ][ÝɈÌLŽØÛÛ[š[    œ][Ý‚’[™]Ù]
    ˆÌÍŽÜ×Ý›   ˆÌÍŽÜ×Ùš[S˜[YJB‰ˆÌÍŽÚÙš[HHš[SÜ[Š   ˆÌÍŽÜ×Ùš[S˜[YK
B‰ˆÌÍŽÜ×Ùš[PÛÛ[Hš[T™XY
    ˆÌÍŽÚÙš[H
B‰ˆÌÍŽØWÛX]ÚÈHÝš[™Ô™YÑ^
    ˆÌÍŽÜ×Ùš[PÛÛ[ ˆÌÎNÊÚJJÜÊI›Ù]ˆÛÜÏIœ][ÝÝÙ‰œ][ÝÉ™ÝËŠÖÊ ›ÜÜ[ˆÛÜÏIœ][ÝÛ‹ŠÉœ][ÝÉ™Ýß
WJŠÊI›ËÜÜ[‰™ÝɈÌÎNËÊB‘›Üˆ   ˆÌÍŽÚHHÈMB‰ˆÌÍŽØWÛX]ÚÖɈÌÍŽÚWHHÝš[™Õš[SY
    ˆÌÍŽØWÛX]ÚÖɈÌÍŽÚWKŒJB‚‰ˆÌÍŽÓX^HMŠŒ‰ˆÌÍŽØÛÝ[ˆH  ˆÌÍŽØÛÝ[ˆ
ÈB‚T›ÙÜ™ÜÓÛŠ   œ][ÝÐÚXÚÚ[™Éœ][ÝË   œ][ÝÉœ][ÝË    œ][ÝÉœ][ÝËÚÝÜZYÚHML
B‚T›ÙÜ™ÜÔÙ]

    ˆÌÍŽÐÛÝ[‹ÉˆÌÍŽÓX^
JŒL    œ][ÝÉœ][ÝË    œ][ÝÕÙˆ    œ][ÝÈ    ˜[È   ˆÌÍŽÐÛÝ[ˆ   ˜[È   œ][ÝÈÙˆ    œ][ÝÈ    ˜[È   ˆÌÍŽÓX^    ˜[È   œ][ÝÈ›Ý[™‰œ][ÝÊB‚Ž×Ðœ˜^QÜ^J    ˆÌÍŽØWÛX]ÚË œ][ÝÕ™Y™™‰œ][ÝÊBŽÓÙЛÞ
    œ][ÝÐÛÝ[ÝÛ‰œ][ÝË    œ][ÝÖ˜Zˆ   œ][ÝÈ    ˜[È   ˆÌÍŽØWÛX]ÚÖɈÌÍŽÚWJB—ÒQS˜]šYØ]H
    ˆÌÍŽÛÒQK  œ][ÝÚ‹ËÛØØ[ÜÝÝÙ‹Éœ][ÝÈ   ˜[È   ˆÌÍŽØWÛX]ÚÖɈÌÍŽÚWKJB—ÒQSØYØZ]
    ˆÌÍŽÛÒQKŒ
B‚“™^‚Ž×Ðœ˜^QÜ^J  ˆÌÍŽØWÛX]ÚË œ][ÝÕ™Y™™‰œ][ÝÊB‚‘š[PÛÜÙJ ˆÌÍŽÚÙš[JB“™^“™^”›ÙÜ™ÜÓÙ™Š
B‘[™[˜

It works well and it works too if i use Hotkeys instead of buttons hotkeys will stop the script and exit the programm but my normal buttons arent working anymore, also my minimize funktion or exit button at the top corner of the program arent working.

I'll hope some1 can help me out there.

thanks in advance - best regards

Can I see the code for your GUI loop? The one that contains something like $msg = GuiGetMsg().

Edit: Sorry for the f*cked up code in the quote. I replied on my iPhone which probably has something to do with it.

Edited by Minikori

For those who are asking questions, look in the help file first. I'm tired of people asking stupid questions about how to do things when 10 seconds in the help file could solve their problem.[quote name='JRowe' date='24 January 2010 - 05:58 PM' timestamp='1264381100' post='766337'][quote name='beerman' date='24 January 2010 - 03:28 PM' timestamp='1264372082' post='766300']They already have a punishment system for abuse.[/quote]... and his his name is Valik.[/quote]www.minikori.com

Share this post


Link to post
Share on other sites

#NoTrayIcon
#RequireAdmin
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <EditConstants.au3>
#include <ButtonConstants.au3>
#include <IE.au3>

Opt("MustDeclareVars", 0)
Opt("GUIOnEventMode", 1)

_IEErrorHandlerRegister ()
_IELoadWaitTimeout (6000)

HotKeySet("{ESC}", "Quit")
HotKeySet("{F5}", "stop")
HotKeySet("{F6}", "click")
HotKeySet("{F7}", "Minimize")

; packing Files to the exe
FileInstall("minimize.bmp", @TempDir & "\minimize.bmp")
FileInstall("close.bmp", @TempDir & "\close.bmp")
FileInstall("icon.ico", @TempDir & "\icon.ico")

$Title = "test" 
$Width = 1000 
$Height = 800 

; Konstanten
Global $break = False, $check = False
Global Const $Font = "Trebuchet MS" 
Global Const $FontSize = 8.5
Global Const $FontColor = 0xFFFFFF
Global Const $FontColor2 = 0xC4B550 ; progress, tab, active
Global Const $FontColorInput = 0xFFFFFF
Global Const $TitleHeight = 21
Global Const $DefaultCtrlHeight = 24
Global Const $BgColorTitle = 0x6699CC
Global Const $BgColor = 0x336699
Global Const $BgColorInput = 0x555555
Global Const $BgColorButton = 0x555852
Global Const $LineColor = 0x6699CC

$Gui = GUICreate($Title, $Width, $Height, -1, -1, $WS_POPUP)
GUISetIcon(@TempDir & "\icon.ico")
GUISetBkColor($BgColor)
GUISetFont($FontSize, 400, 0, $Font)

; Fenster-Rahmen
;   Close-Button
$Close = GUICtrlCreatePic("close.bmp", $Width - 16, 7, 9, 9)
GUICtrlSetOnEvent($Close, "Quit")
;   Minimieren-Button
$Minimize = GUICtrlCreatePic("minimize.bmp", $Width - 31, 7, 9, 9)
GUICtrlSetOnEvent($Minimize, "Minimize")
;   Titel-Label
$TitleBar = GUICtrlCreateLabel($Title, 6, 4, $Width - 42, 17, -1, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetColor(-1, $FontColor)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
;   Hintergrund der Titelleiste
GUICtrlCreateGraphic(0, 0, $Width, $TitleHeight)
GUICtrlSetBkColor(-1, $BgColorTitle)

; Eigentlicher Inhalt
$btn1 = GUICtrlCreateInput("Benutzername", 850, 96, 105, 20, 0)
$btn2 = GUICtrlCreateInput("Passwort", 850, 128, 105, 20, $ES_PASSWORD)
$btn3 = GUICtrlCreateButton("login", 850, 160, 105, 20, 0)
GUICtrlSetOnEvent($btn3, "login")

$btn7 = GUICtrlCreateLabel("Hi", 850, 96, 15, 20, 0)
GUICtrlSetColor(-1, $FontColor)

$btn5 = GUICtrlCreateButton("Start [F6]", 850, 192, 105, 20, 0)
GUICtrlSetOnEvent($btn5, "click")
$btn6 = GUICtrlCreateButton("Stop [F5]", 850, 224, 105, 20, 0)
GUICtrlSetOnEvent($btn6, "stop")

            GUICtrlSetState($btn5, $GUI_HIDE)
            GUICtrlSetState($btn6, $GUI_HIDE)
            GUICtrlSetState($btn7, $GUI_HIDE)
            GUICtrlSetState($btn8, $GUI_HIDE)
            GUICtrlSetState($btn9, $GUI_HIDE)
            GUICtrlSetState($btn10, $GUI_HIDE)
            GUICtrlSetState($btn11, $GUI_HIDE)
            GUICtrlSetState($btn12, $GUI_HIDE)

$btnExit = GUICtrlCreateButton("Exit [ESC]", 850, 320, 105, 20, 0)
GUICtrlSetOnEvent($btnExit, "Quit")

; Fenster-Rahmen
;   Gui-Rand
GUICtrlCreateGraphic(0, $TitleHeight, $Width, $Height - $TitleHeight)
GUICtrlSetBkColor(-1, $LineColor)
GUICtrlCreateGraphic(1, $TitleHeight, $Width - 3, $Height - $TitleHeight - 2)
GUICtrlSetBkColor(-1, $BgColor)

; Rechter Bereich
;   Gui-Rand
GUICtrlCreateGraphic(800, $TitleHeight, 198, $Height - $TitleHeight - 2)
GUICtrlSetBkColor(-1, 0x336699)

; Gui einblenden
GuiRoundCorners($Gui, 0, 0, 2, 2)
WinSetTrans($Gui, "", 0)
FadeIn($Gui)

Func GuiRoundCorners($h_win, $i_x1, $i_y1, $i_x3, $i_y3)
    $pos = WinGetPos($h_win)
    $ret = DllCall("gdi32.dll", "long", "CreateRoundRectRgn", "long", $i_x1, "long", $i_y1, "long", $pos[2], "long", $pos[3], "long", $i_x3, "long", $i_y3)
    If $ret[0] Then
        $ret2 = DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $ret[0], "int", 1)
        If $ret2[0] Then
            Return 1
        Else
            Return 0
        EndIf
    Else
        Return 0
    EndIf
EndFunc   ;==>GuiRoundCorners

Func FadeIn($h)
    For $i = 0 To 255 Step 15
        Sleep(10)
        WinSetTrans($h, "", $i)
    Next
EndFunc   ;==>FadeIn

Func FadeOut($h)
    For $i = 255 To 0 Step -15
        Sleep(10)
        WinSetTrans($h, "", $i)
    Next
EndFunc   ;==>FadeOut

Func SetTitle($s)
    GUICtrlSetData($TitleBar, $s)
    WinSetTitle($Gui, "", $s)
EndFunc


$oIE = _IECreateEmbedded ()
$GUIActiveX = GUICtrlCreateObj($oIE, 1, $TitleHeight, 798, $Height - $TitleHeight - 2)
GUISetState()
_IENavigate ($oIE, "about:blank", 0)

While 1
    Sleep(10)
WEnd

thats it

Share this post


Link to post
Share on other sites

The reason for this is the behavior of the functions.

GUICtrlSetOnEvent() waits until the last called function is finished.

HotKeySet(): "A hotkey-press *typically* interrupts the active AutoIt function/statement and runs its user function until it completes or is interrupted. Exceptions are as follows:..."

A work around for this is to register WM_COMMAND (define cID as globals) and e.g. set a global bool to check state.

Say you start your function with a loop like:

func running()
    $bRunning = true
    while $bRunning = true
    ;do some stuff....
    wend
endfuncoÝ÷ Ù8^*.q©î±ëayc8Ã4;h³­raÆè¢Wë¢kk¹ëh}©ly#ºÇ¬¶¬¶§µêëºlyªÜ»§±«­¢+Ø¥¹±Õ±ÐíU%
½¹ÍѹÑÍà¹ÔÌÐì(¥¹±Õ±Ðí]¥¹½ÝÍ
½¹ÍѹÑ̹ÔÌÐì()=ÁÐ Ìäí5ÕÍѱÉYÉÌÌäì°Ä¤()±½°ÀÌØí¹°Ä()áµÁ± ¤()Õ¹áµÁ± ¤(%1½°ÀÌØíÁɹÐÄ°ÀÌØí½¬Ä((%=ÁÐ ÅÕ½ÐíU%
½½É5½ÅÕ½Ðì°È¤(%=ÁÐ ÅÕ½ÐíU%IÍ¥é5½ÅÕ½Ðì°Ä¤(%=ÁÐ ÅÕ½ÐíU%=¹Ù¹Ñ5½ÅÕ½Ðì°Ä¤(($ÀÌØíÁɹÐÄôU%
ÉÑ ÅÕ½ÐíAɹÐÄÅÕ½Ðì¤(%U%MÑ=¹Ù¹Ð ÀÌØíU%}Y9Q}
1=M°ÅÕ½ÐíMÁ¥±Ù¹ÑÌÅÕ½Ðì¤(%U%MÑ=¹Ù¹Ð ÀÌØíU%}Y9Q}5%9%5%i°ÅÕ½ÐíMÁ¥±Ù¹ÑÌÅÕ½Ðì¤(%U%MÑ=¹Ù¹Ð ÀÌØíU%}Y9Q}IMQ=I°ÅÕ½ÐíMÁ¥±Ù¹ÑÌÅÕ½Ðì¤(($ÀÌØí½¬ÄôU%
Ñɱ
ÉÑ    ÕÑѽ¸ ÅÕ½Ðí=,ÅÕ½Ðì°ÄÀ°ÌÀ°ÔÀ¤(%U%
ÑɱMÑ=¹Ù¹Ð ´Ä°ÅÕ½Ðí=-AÉÍÍÅÕ½Ðì¤(($ÀÌØí¹°ÄôU%
Ñɱ
ÉÑ    ÕÑѽ¸ ÅÕ½Ðí
¹°ÅÕ½Ðì°À°´Ä¤(%U%
ÑɱMÑ=¹Ù¹Ð ´Ä°ÅÕ½Ðí
¹±AÉÍÍÅÕ½Ðì¤((%U%I¥ÍÑÉ5Í ÀÌØí]5}
=559°ÅÕ½Ðí]5}
=559ÅÕ½Ðì¤((%U%MÑMÑÑ¡M]}M!=¤(($ì)ÕÍÐ¥±É½Õ¹(%]¡¥±Ä($%M±À ÄÀ¤(%]¹()¹Õ¹ìôôÐíáµÁ±(()Õ¹=-AÉÍÍ ¤(%5Í    ½à À°ÅÕ½Ðí=,AÉÍÍÅÕ½Ðì°ÅÕ½Ðí%ôÅÕ½ÐìµÀìU%}
Ñɱ%µÀìÅÕ½Ðì]¥¹!¹±ôÅÕ½ÐìµÀìU%}]¥¹!¹±µÀìÅÕ½Ðì
Ñɱ!¹±ôÅÕ½ÐìµÀìU%}
Ñɱ!¹±¤(%M±À ÌÀÀÀ¤)¹Õ¹ìôôÐí=-AÉÍÍ(()Õ¹
¹±AÉÍÍ ¤($%5Í    ½à À°ÅÕ½Ðí
¹°AÉÍÍÅÕ½Ðì°ÅÕ½Ðí%ôÅÕ½ÐìµÀìU%}
Ñɱ%µÀìÅÕ½Ðì]¥¹!¹±ôÅÕ½ÐìµÀìU%}]¥¹!¹±µÀìÅÕ½Ðì
Ñɱ!¹±ôÅÕ½ÐìµÀìU%}
Ñɱ!¹±¤($%ͱÀ ÌÀÀÀ¤)¹Õ¹ìôôÐí
¹±AÉÍÍ(()Õ¹MÁ¥±Ù¹ÑÌ ¤(%M±Ð($%
ÍU%}
Ñɱ%ôÀÌØíU%}Y9Q}
1=M($$%5Í  ½à À°ÅÕ½Ðí
±½ÍAÉÍÍÅÕ½Ðì°ÅÕ½Ðí%ôÅÕ½ÐìµÀìU%}
Ñɱ%µÀìÅÕ½Ðì]¥¹!¹±ôÅÕ½ÐìµÀìU%}]¥¹!¹±¤($$%á¥Ð(($%
ÍU%}
Ñɱ%ôÀÌØíU%}Y9Q}5%9%5%i($$%5Í  ½à À°ÅÕ½Ðí]¥¹½Ü5¥¹¥µ¥éÅÕ½Ðì°ÅÕ½Ðí%ôÅÕ½ÐìµÀìU%}
Ñɱ%µÀìÅÕ½Ðì]¥¹!¹±ôÅÕ½ÐìµÀìU%}]¥¹!¹±¤(($%
ÍU%}
Ñɱ%ôÀÌØíU%}Y9Q}IMQ=I($$%5Í    ½à À°ÅÕ½Ðí]¥¹½ÜIÍѽÉÅÕ½Ðì°ÅÕ½Ðí%ôÅÕ½ÐìµÀìU%}
Ñɱ%µÀìÅÕ½Ðì]¥¹!¹±ôÅÕ½ÐìµÀìU%}]¥¹!¹±¤((%¹M±Ð)¹Õ¹ìôôÐíMÁ¥±Ù¹ÑÌ()Õ¹]5}
=559 ÀÌØí¡]¹°ÀÌØí5Í°ÀÌØíÝAÉ´°ÀÌØí±AÉ´¤(%1½°ÀÌØí¥%ɽ´ô   ¥Ñ9 ÀÌØíÝAÉ´°Áá¤í1½]½É(%1½°ÀÌØí¥
½ô    ¥ÑM¡¥Ð ÀÌØíÝAÉ´°Äؤí!¥]½É((%MÝ¥Ñ ÀÌØí¥%ɽ´($%
ÍÀÌØí¹°Ä($$%5Í ½à À°ÌäìÌäì°Ìäí
¹°Ìäì¤(%¹MÝ¥Ñ (%IÑÕɸÀÌØíU%}IU95M)¹Õ¹ìôôÐí]5}
=559

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

If you've a defined stop() function (your script sample above is none functional), AND this func responds quickly, you could call it directly from WM_COMMAND, but keep in mind the help-file, which says for GUIRegisterMsg():

"Warning: blocking of running user functions which executes window messages with commands such as "Msgbox()" can lead to unexpected behavior, the return to the system should be as fast as possible !!!"

Edited by KaFu

Share this post


Link to post
Share on other sites

ok i tried that out, the button works like you wrote but only with a msgbox f.e.

if i replace the msgbox with:

$bRunning = False

cauz i added like you said the while statement to my main loop, its simply doin nothing.

maybe im doin a simple mistake.

Share this post


Link to post
Share on other sites

What's you stop() func doing? The one triggered with F5. Can't see it in the code provided. Apply the same mechanism to the WM_COMMAND.

Share this post


Link to post
Share on other sites

hmm i found out that he cant do anything cauz i cant exit the loop from the stop function because its not in the loop.

so the button works now inside the loop but wont let me exit it from another function.

any workaround on this ?

Share this post


Link to post
Share on other sites

If there is a loop (like mentioned supplied code isnt't complete; doesn't run), then the trick with the bool should work. Just add an extraline like

if $bRunning = false then exitloop

Share this post


Link to post
Share on other sites

thats it, thank you very much :)

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  
Followers 0