Jump to content

Recommended Posts

Posted (edited)

having problems getting this to work, no matter what I've tried it only returns 0.

Would greatly appreciate any help

this would almost finish up the GuiComboBox UDFs

#include <GuiConstants.au3>

Opt('MustDeclareVars',1)
If(Not IsDeclared('CB_GETCOUNT')) Then Global Const $CB_GETCOUNT = 0x146
If(Not IsDeclared('CB_GETITEMDATA')) Then Global Const $CB_GETITEMDATA = 0x150

Dim $Combo,$Btn_Exit,$Status,$msg,$Btn_Get

GuiCreate("ComboBox Get Item Data", 392, 254)

$Combo = GuiCtrlCreateCombo("", 70, 10, 270, 100,BitOR($CBS_SIMPLE,$CBS_DISABLENOSCROLL,$WS_VSCROLL))
GUICtrlSetData($Combo,"AutoIt|v3|is|freeware|BASIC-like|scripting|language|designed|for|automating")
$Btn_Get = GuiCtrlCreateButton("Get Item 3", 150, 140, 90, 30)
$Btn_Exit = GuiCtrlCreateButton("Exit", 150, 180, 90, 30)
$Status = GUICtrlCreateLabel("",0,234,392,20,BitOR($SS_SUNKEN,$SS_CENTER))
GUICtrlSetData($Status,"Items: " & _GUICtrlComboBoxGetCount($Combo))
GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $Btn_Exit
            ExitLoop
        Case $msg = $Btn_Get
            GUICtrlSetData($Status,"Item: " & _GUICtrlComboBoxGetItemData($Combo, 3))
    EndSelect
WEnd
Exit

;===============================================================================
;
; Description:            _GUICtrlComboBoxGetCount
; Parameter(s):        $h_combobox - controlID
; Requirement:            None
; Return Value(s):    The return value is the number of items in the list box.
;                            If an error occurs, it is CB_ERR
; User CallTip:        _GUICtrlComboBoxGetCount($h_combobox) Retrieve the number of items in the list box of a combo box (required: <ComboBox.au3>)
; Author(s):            Gary Frost (custompcs@charter.net)
; Note(s):                The index is zero-based, so the returned count is one greater
;                            than the index value of the last item.
;
;===============================================================================
Func _GUICtrlComboBoxGetCount($h_combobox)
   Return GUICtrlSendMsg ( $h_combobox, $CB_GETCOUNT , 0, 0 )
EndFunc

;===============================================================================
;
; Description:            _GUICtrlComboBoxGetItemData
; Parameter(s):        $h_combobox - controlID
;                            $i_index - Specifies the zero-based index of the string
; Requirement:            None
; Return Value(s):    The return value is the value associated with the item.
;                            If an error occurs, it is CB_ERR
; User CallTip:        _GUICtrlComboBoxGetItemData($h_combobox, $i_index) Retrieve the application-supplied value associated with the specified item in the combo box (required: <ComboBox.au3>)
; Author(s):            Gary Frost (custompcs@charter.net)
; Note(s):                If the item is in an owner-drawn combo box created without
;                            the CBS_HASSTRINGS style, the return value is the value 
;                            contained in the lParam parameter of the CB_ADDSTRING or 
;                            CB_INSERTSTRING message, that added the item to the combo box.
;                            If the CBS_HASSTRINGS style was not used, the return value is
;                            the lParam parameter contained in a CB_SETITEMDATA message.
; can't seem to make this one work correctly
;===============================================================================
Func _GUICtrlComboBoxGetItemData($h_combobox, $i_index)
   Return GUICtrlSendMsg ( $h_combobox, $CB_GETITEMDATA , $i_index, 0 )
EndFunc
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Posted (edited)

There's no data to Get unless you Set it first :D

Add the following immediately after GUICtrlSetData($Combo,"AutoIt|v3|is|freeware|BASIC-like|scripting|language|designed|for|automating")

and see the result when you click the button:

_GUICtrlComboBoxSetItemData($Combo, 0, 123)
_GUICtrlComboBoxSetItemData($Combo, 1, 456)
_GUICtrlComboBoxSetItemData($Combo, 3, 987)

Func _GUICtrlComboBoxSetItemData($h_combobox, $i_index, $n_number)
    Dim $CB_SETITEMDATA = 0x151
    Return GUICtrlSendMsg ( $h_combobox, $CB_SETITEMDATA , $i_index, $n_number )
EndFunc

Attached is a list box example that uses SetItemData...

The list shows names of Gui Style Constants; and I use SetItemData to store each constant's numeric value in the list. I could have stored the values in an AutoIt array iinstead, but SetItemData is handy in this case. If you want to get fancy, you could store numeric references to other GUI controls or data structures :)

Hope that helps

styleSelector.zip

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!

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
  • Recently Browsing   0 members

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