本帖最后由 chzj589 于 2020-8-23 21:27 编辑
用以下代码试试
#include <GUIComboBox.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <GUIListView.au3>
#include <GuiImageList.au3>
#include <GuiEdit.au3>
#include <GuiComboBoxEx.au3>
Global $sText, $sText1, $hCombo, $hComboa
Local $hGUI = GUICreate('ComboBoxEx GetEditText', 400, 420)
Global $hCombo = _GUICtrlComboBoxEx_Create($hGUI, '这是测试|资料行 2', 2, 2, 154, 268) ;样式不能变
Local $sRead1 = "張三|李四|王五|陳六"
Local $hComboa = _GUICtrlComboBox_Create($hGUI, $sRead1, 160, 2, 154, 296)
;Local $ListView1 = GUICtrlCreateListView('序号|此列下拉框 |XXXX |下拉框 | BBBB', 2, 30, 396, 248, $LVS_REPORT, $WS_EX_CLIENTEDGE)
;Dim $hListView1 = GUICtrlGetHandle(-1)
;_GUICtrlListView_SetExtendedListViewStyle($ListView1, $LVS_EX_GRIDLINES + $LVS_EX_FULLROWSELECT)
;GUICtrlSetFont(-1, 12, 400, 0, "微软雅黑")
Local $ListView1 = GUICtrlCreateListView('', 2, 30, 396, 250, $LVS_REPORT, $WS_EX_CLIENTEDGE);序号|此列下拉框|XXXX|下拉框|BBBB
Dim $hListView1 = GUICtrlGetHandle(-1)
GUICtrlSetFont(-1, 11, 400, 0, "微软雅黑")
GUICtrlSetBkColor($ListView1, 0xC0E0FF)
_GUICtrlListView_SetBkColor($ListView1, 14675183)
_GUICtrlListView_AddColumn($hListView1, "编号", 60, 2);设置列属性
_GUICtrlListView_AddColumn($hListView1, "此列下拉框", 80, 2)
_GUICtrlListView_AddColumn($hListView1, "XXXX", 80, 2)
_GUICtrlListView_AddColumn($hListView1, "此列下拉框", 90, 2)
_GUICtrlListView_AddColumn($hListView1, "BBBB", 90, 2)
_GUICtrlListView_SetExtendedListViewStyle($ListView1, $LVS_EX_GRIDLINES + $LVS_EX_FULLROWSELECT)
$iStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $WS_EX_CLIENTEDGE, $LVS_EX_INFOTIP, $LVS_EX_SUBITEMIMAGES)
GUICtrlSetBkColor($ListView1, 0xC0E0FF)
_GUICtrlListView_SetBkColor($hListView1, 14675183)
; 添加项目
For $ii = 1 To 8
GUICtrlCreateListViewItem($ii & '|aaa|bbb|CCCC|DDDD', $ListView1)
Next
$Edit = GUICtrlCreateEdit("", 2, 290, 396, 70, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL));, $BS_BITMAP, $WS_EX_DLGMODALFRAME);, $WS_VSCROLL)
GUICtrlSetFont(-1, 12, 400, 0, "微软雅黑")
GUICtrlSetColor(-1, 0xFF000F7F)
Local $BUTTON = GUICtrlCreateButton('读取COMBO数据', 10, 390, 150, 25)
$GInputuk7 = GUICtrlCreateLabel("", 360, 390, 30, 25);, $SS_CENTER + $SS_CENTERIMAGE + $WS_BORDER, $WS_EX_DLGMODALFRAME)
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
GUISetState()
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
While 1
Switch GUIGetMsg()
Case -3
Exit
Case $BUTTON
_GUICtrlComboBoxEx_GetItemText($hCombo, _GUICtrlComboBoxEx_GetCurSel($hCombo), $sText)
_GUICtrlComboBoxEx_GetItemText($hComboa, _GUICtrlComboBoxEx_GetCurSel($hComboa), $sText1)
MsgBox(0, '', $sText & @CRLF & $sText1)
;_GUICtrlComboBox_Destroy($hComboa)
;_GUICtrlComboBox_Destroy($hCombo)
EndSwitch
WEnd
Func _GUICtrlComboBox_GetEditTextEx($hWnd) ; _GUICtrlComboBoxEx_GetEditText 修改版
Local $hCBEdit = _GUICtrlComboBoxEx_GetEditControl($hCombo)
Return ControlGetText('', '', $hCBEdit)
EndFunc ;==>_GUICtrlComboBox_GetEditTextEx
Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo, $zhucaidan
;Local $hWndListView1 = $hListView1
;If Not IsHWnd($hListView1) Then $hWndListView1 = GUICtrlGetHandle($hListView1)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hListView1
Switch $iCode
#cs
Case $NM_DBLCLK ; 按兩下 Case $NM_CLICK ; 滑鼠左鍵按一下
Local $index = _GUICtrlListView_GetSelectedIndices($hListView1)
GUICtrlSetData($GInputuk7, $index)
;GUISetState(@SW_HIDE, $hEditForm)
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
$iIndex = DllStructGetData($tInfo, "Index")
$iSub = DllStructGetData($tInfo, "SubItem")
$x = DllStructGetData($tInfo, "X")
Local $SubItem = DllStructGetData($tInfo, 'SubItem')
Global $aHit = _GUICtrlListView_SubItemHitTest($hListView1)
Global $aHit = _GUICtrlListView_SubItemHitTest($hListView1)
;$SubItem = $iSub
Local $ax = 1
Local $ay = 1
Local $aRect = _GUICtrlListView_GetSubItemRect($hListView1, $iIndex, $iSub)
;MsgBox($MB_SYSTEMMODAL, "消息", StringFormat("子項矩形 : [%d, %d, %d, %d]", $aRect[0], $aRect[1], $aRect[2], $aRect[3]))
Local $iEdit_X = $aRect[0] ;+ 4
Local $iEdit_Y = $aRect[1] ;- 25;+ 3
Local $iEdit_Width = _GUICtrlListView_GetColumnWidth($hListView1, $iSub) + 3
Local $iEdit_Height = $aRect[3] - $aRect[1] + 3
Local $sItem = _GUICtrlListView_GetItemText($ListView1, $iIndex, $iSub);取listview$iIndex行 $iSub列的文本
Local $sRead = "男|女"
If $SubItem = 1 Then
;_GUICtrlComboBox_Destroy($hCombo)
$hCombo = _GUICtrlComboBox_Create($hListView1, $sRead, $iEdit_X, $iEdit_Y, $iEdit_Width, $iEdit_Height);, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
ElseIf $SubItem = 3 Then
;_GUICtrlComboBox_Destroy($hComboa)
;Local $sRead = "張三|李四|王五|陳六"
Local $sComboTxt = ""
$sFilePath1 = @ScriptDir & "\config.ini";读取
Local $aArray = IniReadSection($sFilePath1, "1")
; 检查是否发生错误.
If Not @error Then
; 枚举显示数组中关键字及其各自的值.
For $i = 1 To $aArray[0][0]
$totalini = $aArray[$i][1]
If Not StringInStr($sComboTxt, $totalini) Then $sComboTxt &= $totalini & "|"
Next
EndIf
$hComboa = _GUICtrlComboBox_Create($hListView1, $sComboTxt, $iEdit_X, $iEdit_Y, $iEdit_Width, $iEdit_Height);, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
ElseIf ($iIndex <> -1) And ($iSub >= 2) And ($x > 16) Then;點擊的x>16才回應原地編輯
$hEdit = GUICtrlCreateInput($sItem, $iEdit_X, $iEdit_Y, $iEdit_Width, $iEdit_Height, BitOR($WS_CHILD, $WS_VISIBLE, $ES_LEFT))
Else
;MsgBox(0, "提示", "按一下了空白處", 1)
EndIf
$index = _GUICtrlListView_GetSelectedIndices($hListView1)
GUICtrlSetData($GInputuk7, $index)
GUICtrlSetColor($GInputuk7, 0x990000)
#ce
Case $NM_CLICK ; 滑鼠左鍵按一下
Local $index = _GUICtrlListView_GetSelectedIndices($hListView1)
GUICtrlSetData($GInputuk7, $index)
EndSwitch
EndSwitch
#forceref $hWnd, $iMsg, $iwParam
Local $MyGuiFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$MyGuiFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $iIDFrom
Case $ListView1
Switch $iCode
Case $NM_CUSTOMDRAW
Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $ilParam)
Local $iDrawStage = DllStructGetData($tCustDraw, "dwDrawStage")
If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW
If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW
Local $iSubItem = DllStructGetData($tCustDraw, "iSubItem")
Switch $iSubItem
Case 2
If $iSubItem = 2 Then ;設置首列, 即專案
$iColor = RGB2BGR(0x990000)
DllStructSetData($tCustDraw, "clrText", $iColor)
EndIf
Case 3
If $iSubItem = 3 Then ;設置首列, 即專案
$iColor = RGB2BGR(0x009900)
DllStructSetData($tCustDraw, "clrText", $iColor)
EndIf
Case 4
If $iSubItem = 4 Then ;設置首列, 即專案
$iColor = RGB2BGR(0xFF0000)
DllStructSetData($tCustDraw, "clrText", $iColor)
EndIf
EndSwitch
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>_WM_NOTIFY
Func RGB2BGR($iColor)
Return BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF)
EndFunc ;==>RGB2BGR
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg
Local $hWndFrom, $iIDFrom, $iCode, $sText
$hWndFrom = $ilParam
$iIDFrom = BitAND($iwParam, 0xFFFF) ; 低位字
$iCode = BitShift($iwParam, 16) ; 高位字
Local $aHit = _GUICtrlListView_SubItemHitTest($hListView1)
Switch $hWndFrom
Case $hCombo
Switch $iCode
Case $CBN_SELENDCANCEL ;发送用户选择一个项目, 然后选择另一个控件或关闭对话框消息
$sItemText1 = _GUICtrlEdit_GetText($hCombo)
GUICtrlSetData($Edit, $sItemText1 & @CRLF)
_GUICtrlComboBoxEx_GetItemText($hCombo, _GUICtrlComboBoxEx_GetCurSel($hCombo), $sText)
_GUICtrlListView_SetItemText($hListView1, $aHit[0], $sItemText1, 1)
Case $CBN_SELENDOK
$iCurSel = _GUICtrlComboBox_GetCurSel($hCombo)
_GUICtrlComboBox_GetLBText($hCombo, $iCurSel, $sText)
;MsgBox(0, "", $iCurSel)
GUICtrlSetData($Edit, $sText & @CRLF)
$idda = GUICtrlRead($GInputuk7)
_GUICtrlComboBoxEx_GetItemText($hCombo, _GUICtrlComboBoxEx_GetCurSel($hCombo), $sText)
_GUICtrlListView_SetItemText($hListView1, $idda, $sText, 1)
;GUICtrlSetFont($ListView1, 12, 400, 0, "微軟雅黑")
GUICtrlSetBkColor($ListView1, 0xC0E0FF)
_GUICtrlListView_SetBkColor($ListView1, 14675183)
;_GUICtrlComboBox_Destroy($hCombo)
EndSwitch
Case $hComboa
Switch $iCode
Case $CBN_SELENDCANCEL ;发送用户选择一个项目, 然后选择另一个控件或关闭对话框消息
$sItemText1 = _GUICtrlEdit_GetText($hComboa)
GUICtrlSetData($Edit, $sItemText1 & @CRLF)
_GUICtrlComboBoxEx_GetItemText($hComboa, _GUICtrlComboBoxEx_GetCurSel($hComboa), $sText)
_GUICtrlListView_SetItemText($hListView1, $aHit[0], $sItemText1, 3)
;MsgBox(0, '', $sText)
;_GUICtrlComboBox_Destroy($hComboa)
Case $CBN_SELENDOK
$iCurSel = _GUICtrlComboBox_GetCurSel($hComboa)
_GUICtrlComboBox_GetLBText($hComboa, $iCurSel, $sText)
;MsgBox(0, "", $iCurSel)
GUICtrlSetData($Edit, $sText & @CRLF)
$idda = GUICtrlRead($GInputuk7)
_GUICtrlComboBoxEx_GetItemText($hComboa, _GUICtrlComboBoxEx_GetCurSel($hComboa), $sText)
_GUICtrlListView_SetItemText($hListView1, $idda, $sText, 3)
;GUICtrlSetFont($ListView1, 12, 400, 0, "微軟雅黑")
GUICtrlSetBkColor($ListView1, 0xC0E0FF)
_GUICtrlListView_SetBkColor($ListView1, 14675183)
;MsgBox(0, '', _GUICtrlComboBox_GetEditTextExa($hComboa))
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND
|