Sign in to follow this  
Followers 0
twelo

combo color & update entries

2 posts in this topic

i want to set text & background colors for dropdown input combobox how can i ?

i tried "GUICtrlSetColor" & "GUICtrlSetBkColor" but no luck

and how to add, update, reset, limit entries in combo ?

Share this post


Link to post
Share on other sites



#include <GUIComboBox.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.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 $clrHightlight     = _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 $sStr = ''

GUIRegisterMsg($WM_MEASUREITEM, '_WM_MEASUREITEM')
GUIRegisterMsg($WM_DRAWITEM, '_WM_DRAWITEM')

$hGUI = GUICreate('Test', 200, 200)
$ComboBox = GUICtrlCreateCombo('', 0, 0, 200, 200, BitOR($WS_CHILD, $CBS_OWNERDRAWFIXED, $CBS_HASSTRINGS, $CBS_DROPDOWNLIST))
GUICtrlSetFont($ComboBox, 14, 800)

For $i = 1 To 20
    $sStr &= 'String ' & $i & '|'
Next

GUICtrlSetData($ComboBox, StringTrimRight($sStr, 1))
GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

GUIDelete()
Exit

Func _WM_MEASUREITEM($hWnd, $iMsg, $iwParam, $ilParam)
    Local $tMIS = DllStructCreate($tagMEASUREITEMSTRUCT, $ilParam)
    Local $iCtlType, $iCtlID, $iItemID, $iItemWidth, $iItemHeight
    Local $hComboBox
    Local $tSize
    Local $hDC
    
    $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
        $hDC = _WinAPI_GetDC($hComboBox)
        $tSize = _WinAPI_GetTextExtentPoint32($hDC, 'S')
        DllStructSetData($tMIS, 'itemHeight', DllStructGetData($tSize, 'Y')+8)
    EndIf
    
    Return $GUI_RUNDEFMSG
EndFunc


Func _WM_DRAWITEM($hWnd, $iMsg, $iwParam, $ilParam)
    Local $tDIS = DllStructCreate($tagDRAWITEMSTRUCT, $ilParam)
    Local $iCtlType, $iCtlID, $iItemID, $iItemAction, $iItemState
    Local $clrForeground, $clrBackground
    Local $hWndItem, $hDC
    Local $tRect
    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 And $iCtlID = $ComboBox Then
        Switch $iItemAction
            Case $ODA_DRAWENTIRE
                For $i = 1 To 4
                    DllStructSetData($tRect, $i, DllStructGetData($tDIS, $i+7))
                Next
                
                _GUICtrlComboBox_GetLBText($hWndItem, $iItemID, $sText)
                
                $clrForeground = _WinAPI_SetTextColor($hDC, 0xFFFFFF)
                If BitAND($iItemState, $ODS_SELECTED) Then
                    $clrBackground = _WinAPI_SetBkColor($hDC, $clrHightlight) ; The background color when highlighted
                Else
                    $clrBackground = _WinAPI_SetBkColor($hDC, 0xBFBFBF)
;~                     $clrBackground = _WinAPI_SetBkColor($hDC, $clrWindow)      ; The normal background color
                EndIf
                
                _WinAPI_DrawText($hDC, $sText, $tRect, $DT_LEFT)
                _WinAPI_SetTextColor($hDC, $clrForeground)
                _WinAPI_SetBkColor($hDC, $clrBackground)
                
            Case $ODA_SELECT
                For $i = 1 To 4
                    DllStructSetData($tRect, $i, DllStructGetData($tDIS, $i+7))
                Next
                
                _GUICtrlComboBox_GetLBText($hWndItem, $iItemID, $sText)
                
                $clrForeground = _WinAPI_SetTextColor($hDC, 0xFFFFFF)
                If BitAND($iItemState, $ODS_SELECTED) Then
                    $clrBackground = _WinAPI_SetBkColor($hDC, $clrHightlight)
                Else
                    $clrBackground = _WinAPI_SetBkColor($hDC, 0xBFBFBF)
;~                     $clrBackground = _WinAPI_SetBkColor($hDC, $clrWindow)
                EndIf
                
                _WinAPI_DrawText($hDC, $sText, $tRect, $DT_LEFT)
                _WinAPI_SetTextColor($hDC, $clrForeground)
                _WinAPI_SetBkColor($hDC, $clrBackground)
                
        EndSwitch
    EndIf
    
    Return $GUI_RUNDEFMSG
EndFunc

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0