Jump to content

Buttons not working?


Recommended Posts

Ok, I've recently started a project. Now, I've taught myself the basics of the language, and have a pretty decent understand of the power of autoitv3.

However, in my project, I can't seem to get my buttons to work on my GUI. It auto-run's fine, compiles perfect, and doesn't seem to be any errors in format or structure, so I don't know why I can't click my button.

Here's the code that I've gotten so far. Please, if you see coding mistakes or general mistakes, let me know. Again, this is my 2nd project ever using autoitv3, so there may be a few.

(Again, UNFINISHED is the key word. I want to have a thorough understanding of this button problem before I continue.)

;###   Very Start of Program   ###

#include "GUIConstants.au3"                         ;Include GUI constant functions

Global $title = "LazyPole v0.9";Make the title a global variable
Global $wintop = 400, $winleft = 300
Global $winmsg
HotKeySet ( "{End}", "TerminateProg")
Dim $checktrace, $findWoW

;################### Funtions!!! ####################

Func TerminateProg ()
    Local $quitanswer
    $quitanswer = MsgBox ( 1, $title, "Are you sure you want to exit?")
    If $quitanswer = 1 Then
        Exit
    ElseIf $quitanswer = 0 Then
        WinActivate ( $title )
    EndIf
EndFunc

Func TraceWindow ()
    While $checktrace = 1
        MouseMove ( 200, 200, 25)
        Sleep (1000)
        MouseMove ( 500, 200, 25)
        Sleep (1000)
        MouseMove ( 500, 400, 25)
        Sleep (1000)
        MouseMove ( 200, 400, 25)
        Sleep (1000) 
        WEnd
EndFunc

Func GetWoWWindow ()
    Local $active = WinActive ( "World of Warcraft")
    If $active = 1 Then
        WinActivate ( "World of Warcraft")
    ElseIf $active = 0 Then
        Local $tryagain = MsgBox ( 262145, $title, "Please start World of Warcraft and press Attach again")
        If $tryagain = 1 Then
            GetWoWWindow ()
        EndIf
    EndIf
EndFunc

GUICreate ($title, 300, 170, $winleft, $wintop, $WS_EX_TOPMOST)
    GUICtrlCreateLabel ( $title, 0, 0, 300, 170)                    ;Creates a labal, CID 3
        GUICtrlSetBkColor ( 3, 000000)                              ;Sets CID 3 to black                                
    GUICtrlCreateLabel ( "Press End to Quit", 155, 95);Creates Button to quit CID 4
        GUICtrlSetBkColor ( 4, 000000)                              ;Sets BKg to Black
        GUICtrlSetColor ( 4, 16777215)                              ;Sets color of text to White
        GUICtrlSetFont ( 4, 7, "Times New Roman")                   ;Sets Font of CID 5
    GUICtrlCreateLabel ( "Window Size:", 150, 15)                   ;Create CID 5 label
        GUICtrlSetBkColor ( 5, 000000)                              ;Sets BKg to Black
        GUICtrlSetColor ( 5, 16777215)                              ;Sets color of text to White
        GUICtrlSetFont ( 5, 7, "Times New Roman")                   ;Sets Font of CID 5
    GUICtrlCreateLabel ( "X axis:", 150, 35)                        ;Creates CID 6
        GUICtrlSetBkColor ( 6, 000000)                              ;Sets BKG of CID 6 to White
        GUICtrlSetColor ( 6, 16777215)                              ;Sets Font color of CID 6 to Black
        GUICtrlSetFont (6, 8, "Times New Roman")                    ;Sets Font to Garamond
    GUICtrlCreateLabel ( "Y axis:", 150, 55)                        ;Creates CID 7
        GUICtrlSetBkColor ( 7, 000000)                              ;Sets BKG of CID 7 to White
        GUICtrlSetColor ( 7, 16777215)                              ;Sets Font color of CID 7 to Black
        GUICtrlSetFont (7, 8, "Times New Roman")                    ;Sets Font of CID 7 to Garamond
    GUICtrlCreateLabel ( "Acquiring...", 185, 35)                   ;Creates CID 8
        GUICtrlSetBkColor ( 8, 000000)                              ;Sets BKG to Black
        GUICtrlSetColor ( 8, 16777215)                              ;Sets color of font of CID 8 to White
        GUICtrlSetFont ( 8, 8, "Garamond")                          ;Sets Font of CID 8 to Garamond
    GUICtrlCreateLabel ( "Acquiring...", 185, 55)                   ;Creates CID 9
        GUICtrlSetBkColor ( 9, 000000)                              ;Sets BKG to Black
        GUICtrlSetColor ( 9, 16777215)                              ;Sets color of font of CID 9 to White
        GUICtrlSetFont ( 9, 8, "Garamond")                          ;Sets Font of CID 9 to Garamond
    $checktrace = GUICtrlCreateButton ( "Trace", 20, 30, 50, 35)
    $findWoW = GUICtrlCreateButton ( "Attach", 20, 70, 40, 25)
    GUISetState(@SW_SHOW)
    

While 1
    Opt("TrayIconDebug", 1)                                         ;0=no info, 1=debug line info
    $winmsg = GUIGetMsg ()  
    Select
    Case $winmsg = $checktrace
        TraceWindow ()
        ContinueLoop
    Case $winmsg = $findWoW
        GetWoWWindow ()
        ContinueLoop
    EndSelect
    Sleep (500)
WEnd
Link to comment
Share on other sites

  • Moderators

GUICtrlSetStat(-1, $GUI_DISABLE), you have to disable the labels

;###   Very Start of Program   ###

#include "GUIConstants.au3"                        ;Include GUI constant functions

Global $title = "LazyPole v0.9";Make the title a global variable
Global $wintop = 400, $winleft = 300
Global $winmsg
HotKeySet ( "{End}", "TerminateProg")
Dim $checktrace, $findWoW

;################### Funtions!!! ####################

Func TerminateProg ()
    Local $quitanswer
    $quitanswer = MsgBox ( 1, $title, "Are you sure you want to exit?")
    If $quitanswer = 1 Then
        Exit
    ElseIf $quitanswer = 0 Then
        WinActivate ( $title )
    EndIf
EndFunc

Func TraceWindow ()
    While $checktrace = 1
        MouseMove ( 200, 200, 25)
        Sleep (1000)
        MouseMove ( 500, 200, 25)
        Sleep (1000)
        MouseMove ( 500, 400, 25)
        Sleep (1000)
        MouseMove ( 200, 400, 25)
        Sleep (1000)
        WEnd
EndFunc

Func GetWoWWindow ()
    Local $active = WinActive ( "World of Warcraft")
    If $active = 1 Then
        WinActivate ( "World of Warcraft")
    ElseIf $active = 0 Then
        Local $tryagain = MsgBox ( 262145, $title, "Please start World of Warcraft and press Attach again")
        If $tryagain = 1 Then
            GetWoWWindow ()
        EndIf
    EndIf
EndFunc

GUICreate ($title, 300, 170, $winleft, $wintop, $WS_EX_TOPMOST)
    GUICtrlCreateLabel ( $title, 0, 0, 300, 170)                   ;Creates a labal, CID 3                    
        GUICtrlSetState(-1, $GUI_DISABLE)
        GUICtrlSetBkColor ( 3, 000000)                             ;Sets CID 3 to black       
    GUICtrlCreateLabel ( "Press End to Quit", 155, 95);Creates Button to quit CID 4                   
        GUICtrlSetState(-1, $GUI_DISABLE)
        GUICtrlSetBkColor ( 4, 000000)                             ;Sets BKg to Black
        GUICtrlSetColor ( 4, 16777215)                             ;Sets color of text to White
        GUICtrlSetFont ( 4, 7, "Times New Roman")                  ;Sets Font of CID 5
    GUICtrlCreateLabel ( "Window Size:", 150, 15)                  ;Create CID 5 label                    
        GUICtrlSetState(-1, $GUI_DISABLE)
        GUICtrlSetBkColor ( 5, 000000)                             ;Sets BKg to Black
        GUICtrlSetColor ( 5, 16777215)                             ;Sets color of text to White
        GUICtrlSetFont ( 5, 7, "Times New Roman")                  ;Sets Font of CID 5
    GUICtrlCreateLabel ( "X axis:", 150, 35)                       ;Creates CID 6                     
        GUICtrlSetState(-1, $GUI_DISABLE)
        GUICtrlSetBkColor ( 6, 000000)                             ;Sets BKG of CID 6 to White
        GUICtrlSetColor ( 6, 16777215)                             ;Sets Font color of CID 6 to Black
        GUICtrlSetFont (6, 8, "Times New Roman")                   ;Sets Font to Garamond
    GUICtrlCreateLabel ( "Y axis:", 150, 55)                       ;Creates CID 7                     
        GUICtrlSetState(-1, $GUI_DISABLE)
        GUICtrlSetBkColor ( 7, 000000)                             ;Sets BKG of CID 7 to White
        GUICtrlSetColor ( 7, 16777215)                             ;Sets Font color of CID 7 to Black
        GUICtrlSetFont (7, 8, "Times New Roman")                   ;Sets Font of CID 7 to Garamond
    GUICtrlCreateLabel ( "Acquiring...", 185, 35)                  ;Creates CID 8                     
        GUICtrlSetState(-1, $GUI_DISABLE)
        GUICtrlSetBkColor ( 8, 000000)                             ;Sets BKG to Black
        GUICtrlSetColor ( 8, 16777215)                             ;Sets color of font of CID 8 to White
        GUICtrlSetFont ( 8, 8, "Garamond")                         ;Sets Font of CID 8 to Garamond
    GUICtrlCreateLabel ( "Acquiring...", 185, 55)                  ;Creates CID 9                     
        GUICtrlSetState(-1, $GUI_DISABLE)
        GUICtrlSetBkColor ( 9, 000000)                             ;Sets BKG to Black
        GUICtrlSetColor ( 9, 16777215)                             ;Sets color of font of CID 9 to White
        GUICtrlSetFont ( 9, 8, "Garamond")                         ;Sets Font of CID 9 to Garamond
    $checktrace = GUICtrlCreateButton ( "Trace", 20, 30, 50, 35)
    $findWoW = GUICtrlCreateButton ( "Attach", 20, 70, 40, 25)
    GUISetState(@SW_SHOW)
    

While 1
    Opt("TrayIconDebug", 1)                                        ;0=no info, 1=debug line info
    $winmsg = GUIGetMsg ()  
    Select
    Case $winmsg = $checktrace
        TraceWindow ()
        ContinueLoop
    Case $winmsg = $findWoW
        GetWoWWindow ()
        ContinueLoop
    EndSelect
    Sleep (10)
WEnd

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

This actually looks alot better:

;###   Very Start of Program   ###

#include "GUIConstants.au3"                       ;Include GUI constant functions

Global $title = "LazyPole v0.9";Make the title a global variable
Global $wintop = 400, $winleft = 300
Global $winmsg
HotKeySet ( "{End}", "TerminateProg")
Dim $checktrace, $findWoW

;################### Funtions!!! ####################

Func TerminateProg ()
    Local $quitanswer
    $quitanswer = MsgBox ( 1, $title, "Are you sure you want to exit?")
    If $quitanswer = 1 Then
        Exit
    ElseIf $quitanswer = 0 Then
        WinActivate ( $title )
    EndIf
EndFunc

Func TraceWindow ()
    While $checktrace = 1
        MouseMove ( 200, 200, 25)
        Sleep (1000)
        MouseMove ( 500, 200, 25)
        Sleep (1000)
        MouseMove ( 500, 400, 25)
        Sleep (1000)
        MouseMove ( 200, 400, 25)
        Sleep (1000)
        WEnd
EndFunc

Func GetWoWWindow ()
    Local $active = WinActive ( "World of Warcraft")
    If $active = 1 Then
        WinActivate ( "World of Warcraft")
    ElseIf $active = 0 Then
        Local $tryagain = MsgBox ( 262145, $title, "Please start World of Warcraft and press Attach again")
        If $tryagain = 1 Then
            GetWoWWindow ()
        EndIf
    EndIf
EndFunc

    Local $Label[8]
    $Main_GUI = GUICreate ($title, 300, 170, $winleft, $wintop, $WS_EX_TOPMOST)
    GUISetBkColor(0x000000, $Main_GUI)
    $Label[1] = GUICtrlCreateLabel ( $title, 0, 0, 300, 30)               ;Creates a labal, CID 3         
        GUICtrlSetBkColor ($Label[1], 000000)                             ;Sets CID 3 to black   
        GUICtrlSetColor ($Label[1], 16777215)
        GUICtrlSetFont ($Label[1], 7, "Times New Roman")
    $Label[2] = GUICtrlCreateLabel ( "Press End to Quit", 155, 95);Creates Button to quit CID 4          
        GUICtrlSetBkColor ($Label[2], 000000)                             ;Sets BKg to Black
        GUICtrlSetColor ($Label[2], 16777215)                             ;Sets color of text to White
        GUICtrlSetFont ($Label[2], 7, "Times New Roman")                  ;Sets Font of CID 5
    $Label[3] = GUICtrlCreateLabel ( "Window Size:", 150, 15)                 ;Create CID 5 label       
        GUICtrlSetBkColor ($Label[3], 000000)                             ;Sets BKg to Black
        GUICtrlSetColor ($Label[3], 16777215)                             ;Sets color of text to White
        GUICtrlSetFont ($Label[3], 7, "Times New Roman")                  ;Sets Font of CID 5
    $Label[4] = GUICtrlCreateLabel ( "X axis:", 150, 35)                      ;Creates CID 6              
        GUICtrlSetBkColor ($Label[4], 000000)                             ;Sets BKG of CID 6 to White
        GUICtrlSetColor ($Label[4], 16777215)                             ;Sets Font color of CID 6 to Black
        GUICtrlSetFont ($Label[4], 8, "Times New Roman")                  ;Sets Font to Garamond
    $Label[5] = GUICtrlCreateLabel ( "Y axis:", 150, 55)                      ;Creates CID 7             
        GUICtrlSetBkColor ($Label[5], 000000)                             ;Sets BKG of CID 7 to White
        GUICtrlSetColor ($Label[5], 16777215)                             ;Sets Font color of CID 7 to Black
        GUICtrlSetFont ($Label[5], 8, "Times New Roman")                  ;Sets Font of CID 7 to Garamond
    $Label[6] = GUICtrlCreateLabel ( "Acquiring...", 185, 35)                 ;Creates CID 8           
        GUICtrlSetBkColor ($Label[6], 000000)                             ;Sets BKG to Black
        GUICtrlSetColor ($Label[6], 16777215)                             ;Sets color of font of CID 8 to White
        GUICtrlSetFont ($Label[6], 8, "Garamond")                         ;Sets Font of CID 8 to Garamond
    $Label[7] = GUICtrlCreateLabel ( "Acquiring...", 185, 55)                 ;Creates CID 9            
        GUICtrlSetBkColor ($Label[7], 000000)                             ;Sets BKG to Black
        GUICtrlSetColor ($Label[7], 16777215)                             ;Sets color of font of CID 9 to White
        GUICtrlSetFont ($Label[7], 8, "Garamond")                         ;Sets Font of CID 9 to Garamond
    $checktrace = GUICtrlCreateButton ( "Trace", 20, 30, 50, 35)
    $findWoW = GUICtrlCreateButton ( "Attach", 20, 70, 40, 25)
    GUISetState(@SW_SHOW)
    

While 1
    Opt("TrayIconDebug", 1)                                       ;0=no info, 1=debug line info
    $winmsg = GUIGetMsg ()  
    Select
    Case $winmsg = $checktrace
        TraceWindow ()
        ContinueLoop
    Case $winmsg = $findWoW
        GetWoWWindow ()
        ContinueLoop
    EndSelect
    Sleep (10)
WEnd

You created a HUGE label for the first one... I just set the bkgroundcolor to the color you had it at.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Misc tips:

You can use -1 to refer to the mostly recently created control, and you can use the hex number 0xFFFFFF for the coor white. So you could replace most of your calls to GUICtrlSetColor with GUICtrlSetColor(-1, 0xFFFFFF) for consistency.

You might also look at the GuiSetBkColor and GuiSetFont functions.

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

I think this is cleaner:

Local $Label[8]
    $Main_GUI = GUICreate ($title, 300, 170, $winleft, $wintop, $WS_EX_TOPMOST)
    
    GuiSetFont(8, 400, 0, "Times New Roman", $Main_GUI)
    GUISetBkColor(0x000000, $Main_GUI)

    $Label[1] = GUICtrlCreateLabel ( $title, 0, 0, 300, 30)
    $Label[2] = GUICtrlCreateLabel ( "Press End to Quit", 155, 95)
    $Label[3] = GUICtrlCreateLabel ( "Window Size:", 150, 15)
    $Label[4] = GUICtrlCreateLabel ( "X axis:", 150, 35)
    $Label[5] = GUICtrlCreateLabel ( "Y axis:", 150, 55)
    $Label[6] = GUICtrlCreateLabel ( "Acquiring...", 185, 35)
    $Label[7] = GUICtrlCreateLabel ( "Acquiring...", 185, 55)
    $checktrace = GUICtrlCreateButton ( "Trace", 20, 30, 50, 35)
        GuiCtrlSetFont(-1, 9, 400, 0, "Garamond")
    $findWoW = GUICtrlCreateButton ( "Attach", 20, 70, 40, 25)
        GuiCtrlSetFont(-1, 9, 400, 0, "Garamond")

    For $i = 1 to 7
        GUICtrlSetColor($Label[$i], 0xFFFFFF)
        GUICtrlSetBkColor($Label[$i], 0x0)
    Next

    GUISetState(@SW_SHOW)
Edited by CyberSlug
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

I think this is cleaner:

Local $Label[8]
    $Main_GUI = GUICreate ($title, 300, 170, $winleft, $wintop, $WS_EX_TOPMOST)
    
    GuiSetFont(8, 400, 0, "Times New Roman", $Main_GUI)
    GUISetBkColor(0x000000, $Main_GUI)

    $Label[1] = GUICtrlCreateLabel ( $title, 0, 0, 300, 30)
    $Label[2] = GUICtrlCreateLabel ( "Press End to Quit", 155, 95)
    $Label[3] = GUICtrlCreateLabel ( "Window Size:", 150, 15)
    $Label[4] = GUICtrlCreateLabel ( "X axis:", 150, 35)
    $Label[5] = GUICtrlCreateLabel ( "Y axis:", 150, 55)
    $Label[6] = GUICtrlCreateLabel ( "Acquiring...", 185, 35)
    $Label[7] = GUICtrlCreateLabel ( "Acquiring...", 185, 55)
    $checktrace = GUICtrlCreateButton ( "Trace", 20, 30, 50, 35)
        GuiCtrlSetFont(-1, 9, 400, 0, "Garamond")
    $findWoW = GUICtrlCreateButton ( "Attach", 20, 70, 40, 25)
        GuiCtrlSetFont(-1, 9, 400, 0, "Garamond")

    For $i = 1 to 7
        GUICtrlSetColor($Label[$i], 0xFFFFFF)
        GUICtrlSetBkColor($Label[$i], 0x0)
    Next

    GUISetState(@SW_SHOW)

Wow, you guys are insanely fast and helpful with support!

Cheers to all. Thanks again. Like I said about the coding, I am definitely just a starter. Most of the functions/labels/ideas come to me in the middle of coding, so I just kind of wing it. This last code though...beautifully coded. I think I may have to take it.

Thanks again to all,

Until Next Time.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...