Jump to content
Sign in to follow this  
Makaule

[Solved] How to detect which buttom was pressed?

Recommended Posts

I want to create GUI table which may be resized, add additional buttoms, while keeping the rest not moved. I have made almost everything what i want, i just stuck on detecting which buttom was pressed. At the moment i am just lacking some imagination to solve it, so i am open for suggestions.

Here is my code:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)

Global $PriesagaInput[1]
Global $Buttom[1]
Global $n = 0

$MAIN = GUICreate("Test Form", 300, 300, 190, 115)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$Label1 = GUICtrlCreateLabel("Label1", 16, 18, 49, 17)
GUICtrlSetResizing(-1, BitOr($GUI_DOCKTOP, $GUI_DOCKSIZE))
$Label2 = GUICtrlCreateLabel("Label2", 16, 52, 40, 17)
GUICtrlSetResizing(-1, BitOr($GUI_DOCKTOP, $GUI_DOCKSIZE))
$Buttom[0] = GUICtrlCreateButton("Buttom", 205, 15, 70, 25)
GUICtrlSetResizing(-1, BitOr($GUI_DOCKTOP, $GUI_DOCKSIZE))
GUICtrlSetOnEvent($Buttom[0], "_Check")
$AddMore = GUICtrlCreateButton("More>>>", 205, 268, 70, 25)
GUICtrlSetResizing(-1, BitOr($GUI_DOCKBOTTOM, $GUI_DOCKSIZE))
GUICtrlSetOnEvent($AddMore, "_AddMoreButtom")

While 1
    GUISetState(@SW_SHOW)
WEnd

Func _Exit()
    Exit
EndFunc
Func _Check()
    ConsoleWrite(@CRLF & UBound($Buttom) & "...." & $n)
EndFunc
Func _AddMoreButtom()
    $WinPos = WinGetPos($MAIN)
    If UBound($Buttom) = 2 Then GuiCtrlSetState($AddMore, $GUI_DISABLE)
    ReDim $Buttom[UBound($Buttom) + 1]
    $Buttom[UBound($Buttom) - 1] = GUICtrlCreateButton("Buttom" & _
                                   (UBound($Buttom) - 1), 205, 15 + _
                                   (UBound($Buttom) - 1) * 30, 70, 25)
    GUICtrlSetResizing(-1, BitOr($GUI_DOCKTOP, $GUI_DOCKSIZE))
    GUICtrlSetOnEvent($Buttom[UBound($Buttom) - 1], "_Check")
    WinMove($MAIN, "", Default, Default, Default, $WinPos[3] + 30)
EndFunc
Edited by Makaule

Share this post


Link to post
Share on other sites

Makaule,

Use the @GUI_CTRLID macro. As it says in teh Help file, it returns the control ID of the control sending the message OR the system event ID: :(

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)

Global $PriesagaInput[1]
Global $Button[1]
Global $n = 0

$MAIN = GUICreate("Test Form", 300, 300, 190, 115)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$Label1 = GUICtrlCreateLabel("Label1", 16, 18, 49, 17)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKSIZE))
$Label2 = GUICtrlCreateLabel("Label2", 16, 52, 40, 17)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKSIZE))
$Button[0] = GUICtrlCreateButton("Button0", 205, 15, 70, 25)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKSIZE))
GUICtrlSetOnEvent($Button[0], "_Check")
$AddMore = GUICtrlCreateButton("More>>>", 205, 268, 70, 25)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKBOTTOM, $GUI_DOCKSIZE))
GUICtrlSetOnEvent($AddMore, "_AddMoreButton")

While 1
    GUISetState(@SW_SHOW)
WEnd

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Func _Check()

    For $i = 0 To UBound($Button) - 1
        If $Button[$i] = @GUI_CtrlId Then ConsoleWrite("You pressed Button " & $i & @CRLF)
    Next

EndFunc   ;==>_Check

Func _AddMoreButton()
    $WinPos = WinGetPos($MAIN)
    If UBound($Button) = 2 Then GUICtrlSetState($AddMore, $GUI_DISABLE)
    ReDim $Button[UBound($Button) + 1]
    $Button[UBound($Button) - 1] = GUICtrlCreateButton("Button" & _
            (UBound($Button) - 1), 205, 15 + _
            (UBound($Button) - 1) * 30, 70, 25)
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKSIZE))
    GUICtrlSetOnEvent($Button[UBound($Button) - 1], "_Check")
    WinMove($MAIN, "", Default, Default, Default, $WinPos[3] + 30)
EndFunc   ;==>_AddMoreButton

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...