Jump to content

Control dynamic buttons...


Recommended Posts

Hi all, i maded this example script and don't know how to control these buttons, i want to get $x and $y of button ($button[$x][$y]) ...

#include <GuiConstants.au3>

Global $button[100][100]
Local $x, $y
GuiCreate("MyGUI", 320, 350,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

For $x = 1 To 10
    For $y = 1 To 10
        $button[$x][$y] = GuiCtrlCreateButton(Random(1,50,1), $x*30-20, $y*30-20, 30, 30)
    Next
Next
$Label11 = GUICtrlCreateLabel("Pressed button ( x , y ) : ?", 10, 320, 300, 20, $SS_CENTER, BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE))

GuiSetState()

While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $button;???
        GUICtrlSetData($Label11,$x)
    EndSelect
WEnd
Exit
Edited by n3nE

[quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :)

Link to comment
Share on other sites

#n3ne

you could also use oneventmode

with @GUI_CtrlId in a function

#include <GuiConstants.au3>

Global $button[100][100]
Local $x, $y
GUICreate("MyGUI", 320, 350, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

For $x = 1 To 10
    For $y = 1 To 10
        $button[$x][$y] = GUICtrlCreateButton(Random(1, 50, 1), $x * 30 - 20, $y * 30 - 20, 30, 30)
    Next
Next
$Label11 = GUICtrlCreateLabel("Pressed button ( x , y ) : ?", 10, 320, 300, 20, $SS_CENTER, BitOR($WS_EX_CLIENTEDGE, $WS_EX_STATICEDGE))

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $button[1][1] To $button[10][10]
            Beep(1000,5)
            GUICtrlSetData($Label11, GUICtrlRead($msg))
    EndSwitch
WEnd
Exit

I see fascists...

Link to comment
Share on other sites

perhaps I misunderstood what you want

do you want the x and y numbers from the array, not the random button number?

here's a version in oneventmode

#include <GuiConstants.au3>
Opt("GUIOnEventMode",1)

Global $button[100][100]
Local $x, $y

GUICreate("MyGUI", 320, 350, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
GUISetOnEvent($GUI_EVENT_CLOSE, "_Events")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "_Events")
GUISetOnEvent($GUI_EVENT_RESTORE, "_Events")

For $x = 1 To 10
    For $y = 1 To 10
        $button[$x][$y] = GUICtrlCreateButton(Random(1, 50, 1), $x * 30 - 20, $y * 30 - 20, 30, 30)
        GUICtrlSetOnEvent(-1, "_ButtonMatrix")
    Next
Next
$Label11 = GUICtrlCreateLabel("Pressed button ( x , y ) : ?", 10, 320, 300, 20, $SS_CENTER, BitOR($WS_EX_CLIENTEDGE, $WS_EX_STATICEDGE))

GUISetState()

While 1
    Sleep(10000)
WEnd

Func _ButtonMatrix()
    For $x = 1 To 10
        For $y = 1 To 10
            If $button[$x][$y] = @GUI_CtrlId Then
                
                GUICtrlSetData($Label11, "Pressed button: " & GUICtrlRead(@GUI_CtrlId) & "  (" & $x &","& $y & ")")
                ExitLoop 2
            EndIf
        Next
    Next
    Beep(1000,5)
EndFunc

Func _Events()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_MINIMIZE
        Case $GUI_EVENT_RESTORE
        Case Else 
    EndSwitch
Endfunc

I see fascists...

Link to comment
Share on other sites

I need x and y, and with your first script i may get that, but 2nd script is exactly what i want, thank you :)

[quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :)

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...