jycel 发表于 2009-6-27 19:05:43

[已解决]_GUICtrlComboBoxEx_Create读取错误

本帖最后由 jycel 于 2009-6-28 11:08 编辑

如图:按照普通的GUICtrlRead($hCombo)的值全都为0大家帮我看看问题在那儿
解决方法在二楼,说明三楼#include <GuiComboBoxEx.au3>
#include <GuiImageList.au3>
#include <GuiConstantsEx.au3>

Opt('MustDeclareVars', 1)
Dim $File ,$var1
        $File = @ScriptDir&"\Menu.ini"
        $var1 = IniReadSection($File, "在线影视")
$Debug_CB = False ; Check ClassName being passed to ComboBox/ComboBoxEx functions, set to True and use a handle to another control to see it work

_Main()

Func _Main()
        Local $hGUI, $hImage, $hCombo,$nMsg,$Button1,$rj
       
        ; Create GUI
        $hGUI = GUICreate("ComboBoxEx End Update", 400, 300)
        $hCombo = _GUICtrlComboBoxEx_Create ($hGUI, "", 2, 2, 394, 100)
        $Button1 = GUICtrlCreateButton("测试读取", 50, 100, 65, 25)
        GUISetState()

        $hImage = _GUIImageList_Create (16, 16, 5, 3)
                _GUIImageList_AddIcon ($hImage, "1.ico")
                _GUIImageList_AddIcon ($hImage, "2.ico")
                _GUIImageList_AddIcon ($hImage, "3.ico")
                _GUIImageList_AddIcon ($hImage, "4.ico")
                _GUIImageList_AddIcon ($hImage, "5.ico")
                _GUIImageList_AddIcon ($hImage, "6.ico")
                _GUIImageList_AddIcon ($hImage, "7.ico")
                _GUIImageList_AddIcon ($hImage, "8.ico")
                _GUIImageList_AddIcon ($hImage, "9.ico")
                _GUIImageList_AddIcon ($hImage, "10.ico")                               
                _GUIImageList_AddIcon ($hImage, "11.ico")
                _GUIImageList_AddIcon ($hImage, "12.ico")
                _GUIImageList_AddIcon ($hImage, "13.ico")
                _GUIImageList_AddIcon ($hImage, "14.ico")
                _GUIImageList_AddIcon ($hImage, "15.ico")               
        ;_GUIImageList_Add ($hImage, _GUICtrlComboBoxEx_CreateSolidBitMap ($hCombo, 0xFF0000, 16, 16))
        ;_GUIImageList_Add ($hImage, _GUICtrlComboBoxEx_CreateSolidBitMap ($hCombo, 0x00FF00, 16, 16))
        ;_GUIImageList_Add ($hImage, _GUICtrlComboBoxEx_CreateSolidBitMap ($hCombo, 0x0000FF, 16, 16))
        _GUICtrlComboBoxEx_SetImageList ($hCombo, $hImage)

        _GUICtrlComboBoxEx_InitStorage ($hCombo, 150, 300)
       
        _GUICtrlComboBoxEx_BeginUpdate ($hCombo)
        For $x = 0 To $var1
                _GUICtrlComboBoxEx_AddString ($hCombo, $var1[$x], $x, $x,-1,-1);_GUICtrlComboBoxEx_AddString ($hCombo, StringFormat("%03d : Random string", Random(1, 200, 1)), $x, $x)
        Next
        _GUICtrlComboBoxEx_EndUpdate ($hCombo)

        ;Do

        ;Until GUIGetMsg() = $GUI_EVENT_CLOSE
        While 1
        $nMsg = GUIGetMsg()
                        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        $rj=GUICtrlRead($hCombo)
                        MsgBox(0,"提示","你选择的是:"&$rj)
                EndSwitch
        WEnd
EndFunc   ;==>_Main

lynfr8 发表于 2009-6-28 04:14:20

本帖最后由 lynfr8 于 2009-6-28 04:15 编辑

修改这一段即可:      
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
_GUICtrlComboBoxEx_GetItemText ($hCombo, _GUICtrlComboBoxEx_GetCurSel ($hCombo), $sText)
MsgBox(4160, "提示", "你选择的是: " & $sText)
                EndSwitch
      WEnd

pusofalse 发表于 2009-6-28 04:23:21

autoit的内置GUI函数,GUICtrlRead, GUICtrlGetState等,它们的参数都是控件ID,而非控件句柄。
而UDF所创建的控件,都是返回其句柄,所以并不能使用内置函数来获取到任何信息,除非用API将句柄转换为ID,或直接用UDF来获取。

jycel 发表于 2009-6-28 11:07:14

搞定了!谢谢指点哈!
页: [1]
查看完整版本: [已解决]_GUICtrlComboBoxEx_Create读取错误