#include <GUIComboBox.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <FontConstants.au3>
#include <WinAPI.au3>
Global Const $ODT_MENU = 1
Global Const $ODT_LISTBOX = 2
Global Const $ODT_COMBOBOX = 3
Global Const $ODT_BUTTON = 4
Global Const $ODT_STATIC = 5
Global Const $ODT_HEADER = 100
Global Const $ODT_TAB = 101
Global Const $ODT_LISTVIEW = 102
Global Const $ODA_DRAWENTIRE = 1
Global Const $ODA_SELECT = 2
Global Const $ODA_FOCUS = 4
Global Const $ODS_SELECTED = 1
Global Const $ODS_GRAYED = 2
Global Const $ODS_DISABLED = 4
Global Const $ODS_CHECKED = 8
Global Const $ODS_FOCUS = 16
Global Const $ODS_DEFAULT = 32
Global Const $ODS_HOTLIGHT = 64
Global Const $ODS_INACTIVE = 128
Global Const $ODS_NOACCEL = 256
Global Const $ODS_NOFOCUSRECT = 512
Global Const $ODS_COMBOBOXEDIT = 4096
Global Const $clrWindowText = _WinAPI_GetSysColor($COLOR_WINDOWTEXT)
Global Const $clrHighlightText = _WinAPI_GetSysColor($COLOR_HIGHLIGHTTEXT)
Global Const $clrHighlight = _WinAPI_GetSysColor($COLOR_HIGHLIGHT)
Global Const $clrWindow = _WinAPI_GetSysColor($COLOR_WINDOW)
Global Const $tagDRAWITEMSTRUCT = _
'uint CtlType;' & _
'uint CtlID;' & _
'uint itemID;' & _
'uint itemAction;' & _
'uint itemState;' & _
'hwnd hwndItem;' & _
'hwnd hDC;' & _
$tagRECT & _
';ulong_ptr itemData;'
Global Const $tagMEASUREITEMSTRUCT = _
'uint CtlType;' & _
'uint CtlID;' & _
'uint itemID;' & _
'uint itemWidth;' & _
'uint itemHeight;' & _
'ulong_ptr itemData;'
Global $hGUI
Global $ComboBox
Global $hBrushNorm = _WinAPI_CreateSolidBrush($clrWindow)
Global $hBrushSel = _WinAPI_CreateSolidBrush($clrHighlight)
Global $hBrushes[20] = [_WinAPI_CreateSolidBrush(0xFFFFFF)]
For $i = 1 To UBound($hBrushes) - 1
$hBrushes[$i] = _WinAPI_CreateSolidBrush(Random(0, 16777215, 1))
Next
GUIRegisterMsg($WM_MEASUREITEM, '_WM_MEASUREITEM')
GUIRegisterMsg($WM_DRAWITEM, '_WM_DRAWITEM')
$hGUI = GUICreate('Test', 220, 300)
$ComboBox = GUICtrlCreateCombo('', 10, 10, 200, 300, BitOR($WS_CHILD, $CBS_OWNERDRAWVARIABLE, $CBS_HASSTRINGS, $CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL, $__COMBOBOXCONSTANT_WS_VSCROLL))
GUICtrlSetData($ComboBox, "Auto|||||||||||||||||||")
GUISetState()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
For $i = 0 To UBound($hBrushes) - 1
_WinAPI_DeleteObject($hBrushes[$i])
Next
_WinAPI_DeleteObject($hBrushSel)
_WinAPI_DeleteObject($hBrushNorm)
GUIDelete()
Func _WM_MEASUREITEM($hWnd, $iMsg, $iwParam, $ilParam)
Local $tMIS = DllStructCreate($tagMEASUREITEMSTRUCT, $ilParam)
Local $iCtlType, $iCtlID, $iItemID, $iItemWidth, $iItemHeight
Local $hComboBox
Local $tSize
Local $sText
$iCtlType = DllStructGetData($tMIS, 'CtlType')
$iCtlID = DllStructGetData($tMIS, 'CtlID')
$iItemID = DllStructGetData($tMIS, 'itemID')
$iItemWidth = DllStructGetData($tMIS, 'itemWidth')
$iItemHeight = DllStructGetData($tMIS, 'itemHeight')
$hComboBox = GUICtrlGetHandle($iCtlID)
If $iCtlType = $ODT_COMBOBOX Then DllStructSetData($tMIS, 'itemHeight', 50)
Return $GUI_RUNDEFMSG
EndFunc ;==>_WM_MEASUREITEM
Func _WM_DRAWITEM($hWnd, $iMsg, $iwParam, $ilParam)
Local $tDIS = DllStructCreate($tagDRAWITEMSTRUCT, $ilParam)
Local $iCtlType, $iCtlID, $iItemID, $iItemAction, $iItemState
Local $clrForeground, $clrBackground
Local $hWndItem, $hDC, $hOldPen, $hOldBrush
Local $tRect, $aRect[4]
Local $sText
$iCtlType = DllStructGetData($tDIS, 'CtlType')
$iCtlID = DllStructGetData($tDIS, 'CtlID')
$iItemID = DllStructGetData($tDIS, 'itemID')
$iItemAction = DllStructGetData($tDIS, 'itemAction')
$iItemState = DllStructGetData($tDIS, 'itemState')
$hWndItem = DllStructGetData($tDIS, 'hwndItem')
$hDC = DllStructGetData($tDIS, 'hDC')
$tRect = DllStructCreate($tagRECT)
If $iCtlType = $ODT_COMBOBOX Then
Switch $iCtlID
Case $ComboBox
For $i = 1 To 4
DllStructSetData($tRect, $i, DllStructGetData($tDIS, $i + 7))
$aRect[$i - 1] = DllStructGetData($tRect, $i)
Next
_GUICtrlComboBox_GetLBText($hWndItem, $iItemID, $sText)
If BitAND($iItemState, $ODS_SELECTED) Then
$clrForeground = _WinAPI_SetTextColor($hDC, $clrHighlightText)
$clrBackground = _WinAPI_SetBkColor($hDC, $clrHighlight)
_WinAPI_FillRect($hDC, DllStructGetPtr($tRect), $hBrushSel)
Else
$clrForeground = _WinAPI_SetTextColor($hDC, $clrWindowText)
$clrBackground = _WinAPI_SetBkColor($hDC, $clrWindow)
_WinAPI_FillRect($hDC, DllStructGetPtr($tRect), $hBrushNorm)
EndIf
_WinAPI_SetBkMode($hDC, $TRANSPARENT)
$hFont = _WinAPI_CreateFont(50, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, _
$OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Arial')
$hOldFont = _WinAPI_SelectObject($hDC, $hFont)
If $sText <> "" Then
_WinAPI_DrawText($hDC, $sText, $tRect, BitOR($DT_CENTER, $DT_VCENTER))
Else
If $iItemID <> 4294967295 Then
DllStructSetData($tRect, "Left", $aRect[0] + 10)
DllStructSetData($tRect, "Top", $aRect[1] + 2)
DllStructSetData($tRect, "Right", $aRect[2] - 10)
DllStructSetData($tRect, "Bottom", $aRect[3] - 2)
_WinAPI_FillRect($hDC, DllStructGetPtr($tRect), $hBrushes[$iItemID])
_WinAPI_FrameRect($hDC, DllStructGetPtr($tRect), $hBrushes[Random(1,19,1)])
_WinAPI_DrawText($hDC, "Test", $tRect, BitOR($DT_CENTER, $DT_VCENTER))
Else
_WinAPI_FillRect($hDC, DllStructGetPtr($tRect), $hBrushes[0])
EndIf
EndIf
_WinAPI_SetTextColor($hDC, $clrForeground)
_WinAPI_SetBkColor($hDC, $clrBackground)
_WinAPI_SetBkMode($hDC, $TRANSPARENT)
EndSwitch
EndIf
Return $GUI_RUNDEFMSG
EndFunc ;==>_WM_DRAWITEM
|