asdasdasd 发表于 2012-5-13 21:43:02

使用Ex_Create创建下拉组合框,编辑框内容获取不到的问题

帮助里面的例子原文:#include <GuiComboBoxEx.au3>
#include <GuiImageList.au3>
#include <GuiConstantsEx.au3>

Opt('MustDeclareVars', 1)

$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
   
    ; Create GUI
    $hGUI = GUICreate("ComboBoxEx Get Edit Text", 400, 300)
    $hCombo = _GUICtrlComboBoxEx_Create ($hGUI, "", 2, 2, 394, 100, $CBS_SIMPLE)
    GUISetState()

    $hImage = _GUIImageList_Create (16, 16, 5, 3)
    _GUIImageList_AddIcon ($hImage, @SystemDir & "\shell32.dll", 110)
    _GUIImageList_AddIcon ($hImage, @SystemDir & "\shell32.dll", 131)
    _GUIImageList_AddIcon ($hImage, @SystemDir & "\shell32.dll", 165)
    _GUIImageList_AddIcon ($hImage, @SystemDir & "\shell32.dll", 168)
    _GUIImageList_AddIcon ($hImage, @SystemDir & "\shell32.dll", 137)
    _GUIImageList_AddIcon ($hImage, @SystemDir & "\shell32.dll", 146)
    _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)

    For $x = 0 To 8
      _GUICtrlComboBoxEx_AddString ($hCombo, StringFormat("%03d : Random string", Random(1, 100, 1)), $x, $x)
    Next
   
    ;Set Edit Text
    _GUICtrlComboBoxEx_SetEditText ($hCombo, StringFormat("%03d : Random string", Random(1, 100, 1)))
   
    ;Get Edit Text
    MsgBox(4160, "Information", "Edit Text: " & _GUICtrlComboBoxEx_GetEditText ($hCombo))
   
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>_Main

可以很正常地取到编辑框中的文本内容,但是如果把 $hCombo = _GUICtrlComboBoxEx_Create ($hGUI, "", 2, 2, 394, 100, $CBS_SIMPLE)这行,改为 $hCombo = _GUICtrlComboBoxEx_Create ($hGUI, "", 2, 2, 394, 100),即去掉那个样式,大家再试下,就取不到了,似乎是因为图标的问题,我尝试过直接用Guictrlgethandle取Edit的句柄,都取不到编辑框的文本,请大家帮帮忙,谢谢!

3mile 发表于 2012-5-14 10:59:01

#include <GuiComboBoxEx.au3>
#include <GuiImageList.au3>
#include <GuiConstantsEx.au3>

Opt('MustDeclareVars', 1)

$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
   
    ; Create GUI
    $hGUI = GUICreate("ComboBoxEx Get Edit Text", 400, 300)
;~   $hCombo = _GUICtrlComboBoxEx_Create ($hGUI, "", 2, 2, 394, 100, $CBS_SIMPLE)
        $hCombo = _GUICtrlComboBoxEx_Create ($hGUI, "", 2, 2, 394, 100)
    GUISetState()

    $hImage = _GUIImageList_Create (16, 16, 5, 3)
    _GUIImageList_AddIcon ($hImage, @SystemDir & "\shell32.dll", 110)
    _GUIImageList_AddIcon ($hImage, @SystemDir & "\shell32.dll", 131)
    _GUIImageList_AddIcon ($hImage, @SystemDir & "\shell32.dll", 165)
    _GUIImageList_AddIcon ($hImage, @SystemDir & "\shell32.dll", 168)
    _GUIImageList_AddIcon ($hImage, @SystemDir & "\shell32.dll", 137)
    _GUIImageList_AddIcon ($hImage, @SystemDir & "\shell32.dll", 146)
    _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)

    For $x = 0 To 8
      _GUICtrlComboBoxEx_AddString ($hCombo, StringFormat("%03d : Random string", Random(1, 100, 1)), $x, $x)
    Next
   
    ;Set Edit Text
;~   _GUICtrlComboBoxEx_SetEditText ($hCombo, StringFormat("%03d : Random string", Random(1, 100, 1)))
    SENDMESS_SETTEXT($hCombo,StringFormat("%03d : Random string", Random(1, 100, 1)))
    ;Get Edit Text
    MsgBox(4160, "Information", "Edit Text: " & SENDMESS_GETTEXT ($hCombo))
   
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>_Main

Func SENDMESS_GETTEXT($hWnd)
      Local $Len = _SendMessage($hWnd, 0x000E) + 1
      Local $Buffer = DllStructCreate("wchar Text[" & $Len & "]")
      _SendMessage($hWnd, 0x000D, $Len, $Buffer, 0, "wparam", "struct*")
      Return DllStructGetData($Buffer, "Text")
EndFunc
       
Func SENDMESS_SETTEXT($hWnd,$sText)
      _SendMessage($hWnd, 0x000C, 0, $sText, 0, "wparam", "wstr")
EndFunc       

asdasdasd 发表于 2012-5-14 12:17:06

本帖最后由 asdasdasd 于 2012-5-14 12:19 编辑

多谢3MILE,又学会发送消息,另外经测试,可以用ContrlGetText和SetText操作,此外,您的上例中,GetText没取到,不知道是不是个数组。#include <GuiComboBoxEx.au3>
#include <GuiImageList.au3>
#include <GuiConstantsEx.au3>

Opt('MustDeclareVars', 1)

$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
   
    ; Create GUI
    $hGUI = GUICreate("ComboBoxEx Get Edit Text", 400, 300)
    $hCombo = _GUICtrlComboBoxEx_Create ($hGUI, "", 2, 2, 394, 100, $CBS_SIMPLE)
    GUISetState()

    $hImage = _GUIImageList_Create (16, 16, 5, 3)
    _GUIImageList_AddIcon ($hImage, @SystemDir & "\shell32.dll", 110)
    _GUIImageList_AddIcon ($hImage, @SystemDir & "\shell32.dll", 131)
    _GUIImageList_AddIcon ($hImage, @SystemDir & "\shell32.dll", 165)
    _GUIImageList_AddIcon ($hImage, @SystemDir & "\shell32.dll", 168)
    _GUIImageList_AddIcon ($hImage, @SystemDir & "\shell32.dll", 137)
    _GUIImageList_AddIcon ($hImage, @SystemDir & "\shell32.dll", 146)
    _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)

    For $x = 0 To 8
      _GUICtrlComboBoxEx_AddString ($hCombo, StringFormat("%03d : Random string", Random(1, 100, 1)), $x, $x)
    Next
   
    ;Set Edit Text
   ControlGetText($hGUI, "", $hCombo,"send send send send")   
    ;Get Edit Text
    MsgBox(4160, "Information", "Edit Text: " &ControlGetText($hGUI, "", $hCombo) )   
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>_Main
页: [1]
查看完整版本: 使用Ex_Create创建下拉组合框,编辑框内容获取不到的问题