Jump to content

_ChooseBox Function


Ashalshaikh
 Share

Recommended Posts

Hi ;)

I just wrote small function which can helps you to make small box easly.

_ChooseBox

Show box with choices and button

Pictures :-

Posted Image

Posted Image

Posted Image

Function with two examples : -

#include <GuiTreeView.au3>
#include <GuiImageList.au3>



;--- Examples -------------------------
Global $ChooseList[4][3]
$ChooseList[0][0] = 'Choose 1'
$ChooseList[0][1] = 'shell32.dll'
$ChooseList[0][2] = '5'
$ChooseList[1][0] = 'Choose 2'
$ChooseList[1][1] = 'shell32.dll'
$ChooseList[1][2] = '8'
$ChooseList[2][0] = 'Choose 3'
$ChooseList[2][1] = 'shell32.dll'
$ChooseList[2][2] = '200'
$ChooseList[3][0] = 'Choose  4'
$ChooseList[3][1] = 'shell32.dll'
$ChooseList[3][2] = '150'
$result = _ChooseBox($ChooseList)
If @error Then
    MsgBox(16, '', 'You Click X Button')
Else
    MsgBox(64, '', 'Selected : ' & $result & @CRLF & _
            '    Array Index = ' & @extended)
EndIf
$result = _ChooseBox($ChooseList, 'Example', 300, 100, 50, 150)
If @error Then
    MsgBox(16, '', 'You Click X Button')
Else
    MsgBox(64, '', 'Selected : ' & $result & @CRLF & _
            '    Array Index = ' & @extended)
EndIf
;--- End - Examples ---------------------

;-------------- _ChoosBox ----------------------
; Name...........: _ChooseBox
; Description ...: Show box with choices and button
; Tested On .....: AutoIt Version : 3.3.6.1
; Syntax.........: _ChooseBox($ChooseList[, $Title = 'ChooseBox'[, $Width = 100[, $Height = 200[, $Left = -1[, $Top = -1[, $Parent = '']]]]]])
; Parameters ....: $ChooseList  - The array of choices and icons
;                                       The array must be two dimensions .Like This:
;                                           $Array[X][0] = Choice Text
;                                           $Array[X][1] = Choice Icon File
;                                           $Array[X][2] = Choice Icon Index
;                                               X = Number of choice
;                  $Title       - Title of ChooseBox GUI [Default = ChooseBox]
;                  $Width       - Width of ChooseBox GUI [Default = 100]
;                  $Height      - Height of ChooseBox GUI [Default = 200]
;                  $Left        - Left postion of ChooseBox GUI [Default = -1]
;                  $Top         - Top  postion of ChooseBox GUI [Default = -1]
;                  $Parent      - Parent of ChooseBox GUI [Default = '']
; Return values .: Success      - The Choosen Text
;                                   @Extended = Index of choosen choice at the array
;                  Failure      - 0
; Remarks .......: If User click X button (Close) , @Error will be 1
; Author ........: Ahmad Alshaikh (Ashalshaikh)
; Link ..........: http://www.autoitscript.com/forum/index.php?showtopic=120920
; ======================================================================================================
Func _ChooseBox($ChooseList, $Title = 'ChooseBox', $Width = 100, $Height = 200, $Left = -1, $Top = -1, $Parent = '')
    Local $GUI = GUICreate($Title, $Width, $Height, $Left, $Top, Default, Default, $Parent)
    Local $ChooseBtn = GUICtrlCreateButton('Choose', 5, $Height - 40 + 10, $Width - 10, 25)
    Local $TreeView = _GUICtrlTreeView_Create($GUI, 5, 5, $Width - 10, $Height - 40)
    Local $IList = _GUIImageList_Create(16, 16, 5), $ILtmp
    _GUICtrlTreeView_SetNormalImageList($TreeView, $IList)
    GUISetState()
    For $i = 0 To UBound($ChooseList) - 1
        $ILtmp = _GUIImageList_AddIcon($IList, $ChooseList[$i][1], $ChooseList[$i][2])
        _GUICtrlTreeView_Add($TreeView, 0, $ChooseList[$i][0], $ILtmp, $ILtmp)
    Next
    _GUICtrlTreeView_SelectItem($TreeView, _GUICtrlTreeView_GetFirstItem($TreeView), 0)
    While 1
        Switch GUIGetMsg()
            Case -3
                _GUIImageList_Destroy($IList)
                GUIDelete($GUI)
                Return SetError(1, 0, 0)
                ExitLoop
            Case $ChooseBtn
                Local $tmp = _GUICtrlTreeView_GetText($TreeView, _GUICtrlTreeView_GetSelection($TreeView))
                For $t = 0 To UBound($ChooseList) - 1
                    If $tmp = $ChooseList[$t][0] Then
                        _GUIImageList_Destroy($IList)
                        GUIDelete($GUI)
                        Return SetExtended($t, $tmp)
                        ExitLoop
                    EndIf
                Next
        EndSwitch
    WEnd
EndFunc   ;==>_ChooseBox

Note : It needs include (GuiTreeView.au3 | GuiImageList.au3) to work.

I hope to be useful to someone.

Edited by Ashalshaikh
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...