Jump to content
argumentum

ComboBox Set DROPDOWNLIST Colors/size UDF

Recommended Posts

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

8OoP4-p4T-eoYb4aNvkXFw.png

 

 

Saludos

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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 

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

  • Similar Content

    • By DannyJ
      Hello Forum, 
      I have one special Combo-box [with BitOR($CBS_DROPDOWNLIST, $GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE) ] and if I press one button I want to change the Combo-box's background color, and after I press Button B I want to change it to the basic settings and it not works.
      I wanna do this with one combo-box.
      I have already tried several methods and I tried  GUICtrlComboSetColors that I have found on this forum.
      (But this methods works perfectly with Cobo boxes that don't have BitOR($CBS_DROPDOWNLIST, $GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE). 
      Here is the example code
      #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= ;$CBS_DROPDOWNLIST ;$GUI_SS_DEFAULT_COMBO $Form1 = GUICreate("Form1", 504, 249, 252, 227) $Combo1 = GUICtrlCreateCombo("", 136, 24, 193, 25,BitOR($CBS_DROPDOWNLIST, $GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE)) ; I want to change this special combo's background color if I press button 1 $Button1 = GUICtrlCreateButton("Button1", 112, 96, 75, 25) $Button2 = GUICtrlCreateButton("Button2", 264, 96, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUICtrlSetData($Combo1," " & "|" & "apple" & "|" & "banana" & "|" & "cherry" ," ") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 GUICtrlSetBkColor($Combo1,0x0078D7) Case $Button2 ;Makes the original bc color GUICtrlSetBkColor($Combo1,0xFFFFFF) EndSwitch WEnd  
      Thanks you in advance your help
    • By rudi
      Hello,
       
      I found a couple of threads asking quite similar questions, but without finding a "straight" solution to Access the internal phone storage as well as the plugged in SD-Card.
       
      While the SD Card is quite an easy Job (shutdown phone, remove SD, plug into some Card Reader, Access it using a drive letter), the internal storage isn't accessible this way.
       
      Of course I *CAN* Access all the (regular visible) Content, when connected to a Windows box.
       
      But this way I cannot estimate, where all the space was eaten up. So I'd like to know, how to address the "root" Folder of the internal storage of my Android Phone to get it's subfolders and files. Going through the whole Folder tree recursively isn't my Problem, it's just howto address the very first Folder and then to read all files (with sizes) and names of the subfolders.
       
       
      Regards, Rudi.
    • By user4157124
      ConsoleWrite('>Message here.' & @CRLF) outputs colored text (per + > - ! characters).
      ConsoleWrite('warning' & @TAB & '38' & @TAB & 'more text ...' & @CRLF) enables jump to line 38 on doubleclick.

      Using "jump to line" format, only red and pink text coloring seems possible (simply prefixing color directives to output-text disables jump to line functionality). Is it possible to combine the two (define custom color while keeping "jump to line" functionality)?
    • By Miliardsto
      I have the following code. You can see there are $color_normal and $color_trans
      In my case normal is too dark . And color trans is to much violet.
      If you run it you will see how its looks. I want gui with listView have the same color like taskbar in windows 10.
      How to achieve that?
       
       
      #include <Date.au3> #include <MsgBoxConstants.au3> #include <GuiListBox.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> HotKeySet("{ESC}", "Terminate") $color_normal = "0x" & StringLeft(StringRight(RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Accent", "AccentPalette"), 24), 6) $color_trans = "0x" & StringLeft(StringRight(RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Accent", "AccentPalette"), 16), 6) $trans = RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize", "EnableTransparency") ConsoleWrite("Transpart = " & $trans & @CRLF) ConsoleWrite("Color normal = " & $color_normal & @CRLF) ConsoleWrite("Color trans = " & $color_trans & @CRLF) ConsoleWrite(_Get_taskbar_color()); It return AARRGGBB $taskbarColor = _Get_taskbar_color() Global $gui = GUICreate("Test", 150, 58,@DesktopWidth-300,@DesktopHeight-58,$WS_POPUP,BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW)) Global $idListview = GUICtrlCreateListView("", 0, 0, 150, 58,BitOR($LBS_NOTIFY,$LBS_SORT), 0) ;_GuiCtrlMakeTrans(-1,100) ; Add column _GUICtrlListView_AddColumn($idListview, "Msgs", 100) GUICtrlSetFont(-1, 7, 400, 0, "Segoe UI") GUICtrlSetColor(-1, 0x470C4F) GUICtrlSetBkColor($idListview, 0x310638) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func Terminate() Exit EndFunc Func _Get_taskbar_color() If RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize", "ColorPrevalence") Then If RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize", "EnableTransparency") Then Return "0xD9" & StringLeft(StringRight(RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Accent", "AccentPalette"), 16), 6) Else Return "0xFF" & StringLeft(StringRight(RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Accent", "AccentPalette"), 24), 6) EndIf Else If RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize", "EnableTransparency") Then Return "0xD9000000" Else Return "0xFF000000" EndIf EndIf EndFunc  
×
×
  • Create New...