Jump to content

Help Switching from GUI Poll method to OnEvent Mode


Recommended Posts

I have a GUI with unknown # of buttons and associated menu items (loaded from a configuration file).

Currently using the GUI Poll method, I have this:

; Note: $Groups is an Array that is loaded with items
; $Btn_Groups and $MenuViewGroups are Redimed and defined using $Groups contents
Local $I, $GUIMsg
While 1
    $GUIMsg = GUIGetMsg()
    Switch $GUIMsg
    Case $Btn_Groups[0] To $Btn_Groups[UBound($Groups)-1]
             For $I = 0 To UBound($Groups)-1
                   If $GUIMsg = $Btn_Groups[$I] Then
                      $Active_Group = $I
                      Load_Group_Items()
                   EndIf
             Next;$I
    Case $MenuViewGroups[0] To $MenuViewGroups[UBound($Groups)-1]
             For $I = 0 To UBound($Groups)-1
                   If $GUIMsg = $MenuViewGroups[$I] Then
                      $Active_Group = $I
                      Load_Group_Items()
                   EndIf
             Next;$I
    EndSwitch
WEnd

the Buttons/Menu Items are defined as below:

$J = UBound($Groups)
    ReDim $Btn_Groups[$J]
    ReDim $MenuViewGroups[$J]
    $J = $J - 1
    For $I = 0 To $J; View->Group->Menu Items [HAVE TO BE ADDED IN SEQUENCE, otherwise will NOT Trigger !!!]
        $MenuViewGroups[$I] = GUICtrlCreateMenuItem($Groups[$I], $MenuViewGroup)
    Next;$I
    For $I = 0 To $J; Group Buttons
        $Top = $Top + 70
        $Btn_Groups[$I]  = GUICtrlCreateButton($Groups[$I], 5, $Top, 65, 65, BitOR($BS_CENTER, $BS_MULTILINE, $BS_BITMAP))
    Next;$I

I need to switch to the GUI OnEvent Mode (because of ListView tracking, sort, etc.).

Any Ideas/suggestions to effectively implement a call to the "Load_Group_Items()" Func. while tracking which Button/Menu was clicked ($Active_Group variable is the one used in Load_Group_Items func.) ?

Wish I could just do....

GUICtrlSetOnEvent($Btn_Groups[0] To $Btn_Groups[uBound($Groups)-1], "Load_Group_Items") and

GUICtrlSetOnEvent($MenuViewGroups[0] To $MenuViewGroups[uBound($Groups)-1], "Load_Group_Items") :)

But then I don't know which is the button/menu clicked :-(

Edit: Oops, wrong forum, How do I move this to the GUI Help/Support Forum?

Edited by DaRam
Link to comment
Share on other sites

An example says more than a million words :)

#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode",1)
GUICreate("Sample",400,50)
Dim $controls[10]
For $i=0 To UBound($controls)-1
    $controls[$i]=GUICtrlCreateButton($i,$i*30+10,10,30)
    GUICtrlSetOnEvent(-1,"_Buttonclicked")
Next
GUISetOnEvent($GUI_EVENT_CLOSE,"close")
GUISetState()


Do
    Sleep(100)
Until False

Func close()
    Exit
EndFunc


Func _Buttonclicked()
    For $i=0 To UBound($controls)-1
        If @GUI_CtrlId=$controls[$i] Then ; @GUI_CtrlID is the control that fired the event.
            MsgBox(0,"Button clicked","Button number "&$i&" was clicked.")
            ExitLoop
        EndIf
    Next
EndFunc

:)

Broken link? PM me and I'll send you the file!

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