Ich habe die Problematik mal auf ein mimimales Skript runtergebrochen.
Im Original lese ich Daten aus einer INI in eine Map, habe ich hier nachgestellt.
Diese Daten sollen abhängig von dem Wert in 'access' (0/1) in rot oder Schwarz in der Combobox gelistet werden. Das funktioniert auch grundlegend.
Versuche ich jedoch innerhalb der WM_DRAWITEM-Funktion aus der Map den Wert für 'access' abzufragen, um entsprechend einzufärben, bekomme ich einen Fehler:
==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
If $mUnit[GUICtrlRead($cCombo)]['access'] = 0 Then $clrForeground = 0x0000FF
If $mUnit[GUICtrlRead($cCombo)]^ ERROR
Wie aber im Skript sichtbar ist, lasse ich zur Kontrolle die gesamte Map vorab in die Konsole ausgeben - problemlos.
Eigentlich könnte ich statt GUICtrlRead($cCombo) auf das funktionsintern gelesene $sText zugreifen. Hatte das aber mal testweise geändert, um es als Fehlerquelle auszuschließen.
Vielleicht hat ja schonmal jemand das Problem gehabt.
In Zeilen #90 / #91 mal die Kommentierung tauschen, um den Effekt zu sehen.
#include <GUIComboBox.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
Global Const $ODT_COMBOBOX = 3
Global Const $ODA_DRAWENTIRE = 1
Global Const $ODA_SELECT = 2
Global Const $ODS_SELECTED = 1
Global $hGUI
Global $cCombo, $inPath
Global $sStr = ''
$hGUI = GUICreate('Test', 600, 400)
$cCombo = GUICtrlCreateCombo('', 100, 20, 300, 300, BitOR($WS_CHILD, $CBS_OWNERDRAWFIXED, $CBS_HASSTRINGS, $CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL, $WS_VSCROLL))
$inPath = GUICtrlCreateInput('', 100, 50, 300, 20)
Global $sPathRoot = 'D:\Units'
Global $mUnit[] ; $m['Einheit']['path'] / $m['Einheit']['template'] / $m['Einheit']['access']
For $i = 1 To 15
Local $m[]
$mUnit['Einheit_' & $i] = $m
$mUnit['Einheit_' & $i]['path'] = $sPathRoot & '\Einheit_' & $i
$mUnit['Einheit_' & $i]['template'] = 'Template_' & Random(1,100,1)
$mUnit['Einheit_' & $i]['access'] = Random(0,1,1)
Next
For $key in MapKeys($mUnit)
$sStr &= '|' & $key
Next
GUICtrlSetData($cCombo, $sStr)
; ============================= Testausgabe Inhalt Map:
For $key in MapKeys($mUnit)
ConsoleWrite($key & ': ' & $mUnit[$key]['path'] & ' | ' & $mUnit[$key]['template'] & ' | ' & $mUnit[$key]['access'] & @CRLF)
Next
; =============================================
GUIRegisterMsg($WM_DRAWITEM, '_WM_DRAWITEM')
GUISetState()
While True
Switch GUIGetMsg()
Case -3
Exit
Case $cCombo
$sSel = GUICtrlRead($cCombo)
GUICtrlSetData($inPath, $mUnit[$sSel]['path'])
EndSwitch
WEnd
Func _WM_DRAWITEM($hWnd, $iMsg, $iwParam, $ilParam)
Local Const $tagDRAWITEMSTRUCT = 'uint CtlType;' & 'uint CtlID;' & 'uint itemID;' & 'uint itemAction;' & _
'uint itemState;' & 'hwnd hwndItem;' & 'hwnd hDC;' & $tagRECT & ';ulong_ptr itemData;'
Local $tDIS = DllStructCreate($tagDRAWITEMSTRUCT, $ilParam)
Local $clrForeground = 0x000000, $clrBackground = 0xFFFFFF, $sText
Local Static $clrPrev = $clrForeground
$clrForeground = $clrPrev
Local $iCtlType = $tDIS.CtlType
Local $iCtlID = $tDIS.CtlID
Local $iItemID = $tDIS.itemID
Local $iItemAction = $tDIS.itemAction
Local $iItemState = $tDIS.itemState
Local $hWndItem = $tDIS.hwndItem
Local $hDC = $tDIS.hDC
Local $tRect = DllStructCreate($tagRECT)
If $iCtlType = $ODT_COMBOBOX And $iCtlID = $cCombo Then
For $i = 1 To 4
DllStructSetData($tRect, $i, DllStructGetData($tDIS, $i+7))
Next
_GUICtrlComboBox_GetLBText($hWndItem, $iItemID, $sText)
Switch $iItemAction
Case $ODA_DRAWENTIRE
$clrForeground = 0x000000
If BitAND($iItemState, $ODS_SELECTED) Then
$clrBackground = _WinAPI_SetBkColor($hDC, 0xD8D8D8)
Else
$clrBackground = _WinAPI_SetBkColor($hDC, 0xFFFFFF)
EndIf
; ##################################################################################################
;~ If $mUnit[GUICtrlRead($cCombo)]['access'] = 0 Then $clrForeground = 0x0000FF
If Random(0,1,1) = 0 Then $clrForeground = 0x0000FF
; ##################################################################################################
$clrPrev = _WinAPI_SetTextColor($hDC, $clrForeground)
_WinAPI_DrawText($hDC, $sText, $tRect, $DT_LEFT)
_WinAPI_SetTextColor($hDC, $clrForeground)
_WinAPI_SetBkColor($hDC, $clrBackground)
EndSwitch
EndIf
Return $GUI_RUNDEFMSG
EndFunc
Alles anzeigen