Jump to content

Recommended Posts

Posted

Hello. I really like this. new task for you. Allow the user to change the selected item color. 

8OoP4-p4T-eoYb4aNvkXFw.png

 

 

Saludos

Posted (edited)
15 minutes ago, Danyfirex said:

Allow the user to change the selected item color

I do not know how to do this. But it would be good to have the UDF do that too. If you have hints or code, share it :) 

Edit: actually at "GUI/Tray Menu with icons and colors" there may a hint but I'm really pressured by time. This UDF arouse out a need for one, as in my current project I added light and dark themes for the controls and when I whent to use this Control, looked bad to me, so I looked around the forums and made this adaptation.
But I really need to get back to my project. The next step to colorize stuff is the Date picker but I'd have to get into system.windows.automation and it'd be a steep learning curve for me or create a DLL Date/Time Picker, also out of my league.

Edited by argumentum

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted

Hello. For set color to that you need some owen drawn handling. something like this.

 

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <GUIComboBox.au3>
#include <ColorConstants.au3>
#include <WinAPI.au3>
#include <FontConstants.au3>

Global Const $ODA_DRAWENTIRE = 1
Global Const $ODA_SELECT = 2
Global Const $ODS_SELECTED = 1
Global Const $ODT_COMBOBOX = 3
Global Const $sTagDRAWITEMSTRUCT = "uint CtlType;uint CtlID;uint itemID;uint itemAction;uint itemState;" & _
        "hwnd hwndItem;hwnd hDC;long Left;long Top;long Right;long Bottom;ulong_ptr itmData"

;for custom Font
;~     Global $g_hFont = _WinAPI_CreateFont(15, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, _
;~         $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Segoe UI')

Global $idComboBox = 0
Example()

Func Example()
    ; Create a GUI with various controls.
    Local $hGUI = GUICreate("Example", 300, 200)

    ; Create a combobox control.
    $idComboBox = GUICtrlCreateCombo("Item 1", 10, 10, 185, 25, BitOR($CBS_OWNERDRAWFIXED, $CBS_HASSTRINGS, $CBS_DROPDOWNLIST))
    Local $idClose = GUICtrlCreateButton("Exit", 210, 170, 85, 25)
    ; Add additional items to the combobox.
    GUICtrlSetData($idComboBox, "Item 2|Item 3", "Item 1")

    GUIRegisterMsg($WM_DRAWITEM, "_WM_DRAWITEM")
    GUISetState(@SW_SHOW, $hGUI)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idClose
                ExitLoop
        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc   ;==>Example


Func _WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam)

    Local $tRawItem = DllStructCreate($sTagDRAWITEMSTRUCT, $lParam)
    Local $iCtlType = DllStructGetData($tRawItem, 'CtlType')
    Local $iCtlID = DllStructGetData($tRawItem, 'CtlID')
    Local $iItemID = DllStructGetData($tRawItem, 'itemID')
    Local $iItemAction = DllStructGetData($tRawItem, 'itemAction')
    Local $iItemState = DllStructGetData($tRawItem, 'itemState')
    Local $hWndItem = DllStructGetData($tRawItem, 'hwndItem')
    Local $hDC = DllStructGetData($tRawItem, 'hDC')
    Local $tRect = DllStructCreate($tagRECT, DllStructGetPtr($tRawItem, "Left"))
    Local $sText = ""
    Local $sDummyString = "                                                                                                                       " ;just for fill the whole rect this can be avoid using some fillrect APIs
    Local $iBackColor = 0xFFFFFF ;White
    Local $iFontColor = 0x000000 ;Black
;~  Local $g_hOldFont = _WinAPI_SelectObject($hDC, $g_hFont)


    If $iCtlType = $ODT_COMBOBOX And $iCtlID = $idComboBox Then
        Switch $iItemAction
            Case $ODA_DRAWENTIRE
                _GUICtrlComboBox_GetLBText($hWndItem, $iItemID, $sText)
                If BitAND($iItemState, $ODS_SELECTED) Then $iBackColor = 0x8000FF ;Pink
                _WinAPI_SetTextColor($hDC, $iFontColor)
                _WinAPI_SetBkColor($hDC, $iBackColor)
                _WinAPI_DrawText($hDC, $sText & $sDummyString, $tRect, $DT_LEFT)


            Case $ODA_SELECT
                _GUICtrlComboBox_GetLBText($hWndItem, $iItemID, $sText)
                If BitAND($iItemState, $ODS_SELECTED) Then $iBackColor = 0x8000FF ;Pink
                _WinAPI_SetTextColor($hDC, $iFontColor)
                _WinAPI_SetBkColor($hDC, $iBackColor)
                _WinAPI_DrawText($hDC, $sText & $sDummyString, $tRect, $DT_LEFT)

        EndSwitch
    EndIf
    Return $GUI_RUNDEFMSG

EndFunc   ;==>_WM_DRAWITEM

Saludos

Posted
On 11/4/2017 at 7:21 AM, Danyfirex said:

you need some owen drawn handling. something like this.

It did not trigger. Looked around the net and found that it needs to be subclassed to handle it. I don't know how to do that :( 
Also seen the notion that the control would be much better, if it autosized the listbox it drops down, so, we now have autosize :D 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

  • 2 months later...

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
×
×
  • Create New...