Jump to content
argumentum

ComboBox Set DROPDOWNLIST Colors/size UDF

Recommended Posts

argumentum

v0.0.0.3 = fixed some minor details ... but still need to fix the "remove ControlID" thing, as it'd create problems if one really uses the return value from the function.

Edited by argumentum
 thought of the code

Share this post


Link to post
Share on other sites
argumentum

Thanks @UEZ, now I believe the only control left to be colorized is the Date/Time Picker ( GUICtrlCreateDate ) on Win7+. All help is always welcome ( hint, hint ) :D 

Share this post


Link to post
Share on other sites
Danyfirex

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
argumentum
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
Danyfirex

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

  • Like 1

Share this post


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

awesome work, thanks a lot argumentum !!

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

    • Skeletor
      By Skeletor
      Hi All,
      While creating a few excel spreadsheets using AutoIt, I came across something which to my limiting time to research the forums I don't anyone has mentioned. 
      The color pallettes are reversed. 
      Huge shock to me.
       
      I wanted to produce a red row but kept on getting blue. 
      Seems like 0xFF0000 was red on the charts but when running the script, I got blue. 
      I then played around with the colors, and after a few tries, I finally got Red. 
      Reversed the FF0000 and the result is 0000FF.
       
      So for Excel compared to Html
      0000FF (Red) - Excel
      0000FF (Blue) - Html

      FFFF00 (Cyan) - Excel
      FFFF00(Yellow) - Html
       
    • Pricehacker
      By Pricehacker
      Hello!
      I want to make a script that changes the filesize of program files while still having them run as usual.
      I tried FileWrite() but then the program wouldnt be recognized as a runnable program, could you guys help me to the right path?
    • xtcislove
      By xtcislove
      Hello,
      i stuck again,
      Im using this function to create a treeview from root dir.
       
      ;https://autoit.de/index.php?thread/86082-treeview-root-verbergen/&postID=691139#post691139 #include <File.au3> #include <WindowsConstants.au3> Global $sPath = @ScriptDir Global $hGui = GUICreate('TreeView-Example', 400, 600) Global $idTreeView = GUICtrlCreateTreeView(10, 10, 380, 580, Default, $WS_EX_CLIENTEDGE) GUISetState() _CreatePath($sPath, $idTreeView) Do Until GUIGetMsg() = -3 Func _CreatePath($sPath, $idParent) Local $aFolder, $aFiles, $idItem If StringRight($sPath, 1) <> '\' Then $sPath &= '\' $aFolder = _FileListToArray($sPath, '*', $FLTA_FOLDERS) If Not @error Then For $i = 1 To $aFolder[0] $idItem = GUICtrlCreateTreeViewItem($aFolder[$i], $idParent) _CreatePath($sPath & $aFolder[$i], $idItem) Next EndIf $aFiles = _FileListToArray($sPath, '*', $FLTA_FILES) If @error Then Return For $i = 1 To $aFiles[0] $idItem = GUICtrlCreateTreeViewItem($aFiles[$i], $idParent) Next EndFunc Folder Structure:

      Folder1
      Folder2
      Folder3
      If a file exists in multiple folders, i like to color it red, if not green. 

      I know how to do this for files, but nut for the folders.

      Because if there is only 1 file in Folder2 that is also in Folder1 that it should only color this single file red, inlcuding its whole tree.

      The Folder1 and Folder2 should be red in this case, too. Other files and trees should stay green.
       
      Edit:
      Basically i like to color a file and its belonging tree red if the file exists more than 1 time.
    • odaylton
      By odaylton
      Hello everyone ,
      Text translated from Portuguese by google - please apologize for any errors

      Once again I need a light from the gurus of this wonderful website
      I am fanatic by combobox for its usability but I am not able to uncertain images within lists ...
      I know uncertain icons, and cursors but I am not able to insert gif or jpg images.
      1) How to solve this ...
      2) will the path is to convert gif into bmp and then uncertain ... how to do that?
      #include <GUIConstantsEx.au3> #include <GuiImageList.au3> #include <GuiListView.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> ;dados de mouse #include <WinAPIRes.au3> ;COMBO #include <GuiComboBoxEx.au3> ;Fonts #include <FontConstants.au3> ;obter imagem de arquivo #include <GDIPlus.au3> #include <WinAPIGdi.au3> Example() Func Example() Local $hGUI, $hImage, $hCombo, $hFont Local $idListview, $hImage Local $sWow64 = "" Local $Pasta = "C:\WINDOWS\Cursors\3dgarro.cur" Local $PastaROMs = @MyDocumentsDir & "\Stella\ROMs\" ;com barra no final $hGUI = GUICreate("ImageList", 500, 310) GUISetFont(14, 400, 0, "Arial") ;<<<<<<<<<<this does not work for _GUICtrlComboBoxEx_Create $hCombo = _GUICtrlComboBoxEx_Create($hGUI, "", 2, 2, 494, 200) ;GUICtrlSetFont($hCombo, 14, 400, 0, "Arial");<<<<<<<<<<It does not work ; ;Create a handle to a font object $hFont = _WinAPI_CreateFont(30, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Arial') ;Pass the handle to _WinAPI_SetFont _WinAPI_SetFont($hCombo, $hFont) $idListview = GUICtrlCreateListView("", 2, 50, 494, 250, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT)) _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER)) GUISetState(@SW_SHOW) ; Initialize GDI+ library _GDIPlus_Startup() ; Load images $hImage = _GUIImageList_Create(120, 70, 6, 2) ;32,32,5,5) ; $DadosCombo = "Escolha|" & _GUIImageList_Add($hImage, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, 0x0000FF, 120, 70)) ;Local $aCursors[] = [32650, 32512, 32515, 32649, 32651, 32513, 32648, 32646, 32643, 32645, 32642, 32644, 32516, 32514] For $i = 1 To 10 $sFile = FileOpenDialog("Please select an image", $PastaROMs, "Image (*.jpg;*.png;*.bmp;*.gif;*.tif)", BitOR($FD_PATHMUSTEXIST, $FD_FILEMUSTEXIST)) If @error Then Exit MsgBox(BitOR($MB_TOPMOST, $MB_ICONERROR), "Error", "No image file has been selected", 30) $a = _GDIPlus_BitmapCreateFromFile ($sFile);<<<<< ok If @error Or Not $hImage Then MsgBox(BitOR($MB_TOPMOST, $MB_ICONERROR), "Error", "This file isn't supported by GDIPlus!") Else $b=_GUIImageList_Add($hImage, $a);<<<<<< Return -1 $DadosCombo &= "|" & $i & "_img_princ.gif""|" & $b EndIf Next _GUICtrlListView_SetImageList($idListview, $hImage, 1) _GUICtrlComboBoxEx_SetImageList($hCombo, $hImage) ; Add columns _GUICtrlListView_AddColumn($idListview, "Icons - Mouses", 350) ; Add items $a = StringSplit($DadosCombo, "|") For $i = 1 To $a[0] Step 2 _GUICtrlListView_AddItem($idListview, $a[$i], $a[$i + 1]) _GUICtrlComboBoxEx_AddString($hCombo, $a[$i], $a[$i + 1], $a[$i + 1]) Next ;AutoIt_Debugger_Command:Disable_Debug ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() ;AutoIt_Debugger_Command:Enable_Debug EndFunc ;==>Example tks
    • aiter
      By aiter
      I  possibly misunderstood the value of combo boxes, but I thought you could type a value, press enter and the combo box would store that value.
      The reason for wanting this is to store a history of typed commands into the combo box (accepted by pressing enter).
       
      After hours of trying to trap enter on a combobox I realized that the enter event was not registering.
      I had code like this (which used to work on a input box), but it does not for a combobox (because it does not accept enter)
      unc WM_COMMAND($hWnd, $Msg, $wParam, $lParam) Local $nNotifyCode = BitShift($wParam, 16) Local $nID = BitAND($wParam, 0x0000FFFF) If $hWnd = $CmdForm Then If $nID = $ComboInput Then ; useed to work on a normal input box If _IsPressed('0D') Then ; enter was pressed, respond DoCmd() Anyone able to help?
×