Jump to content

Recommended Posts

Posted

I have a combobox already and I would like to add a separator (horizontal line) in the list. I know how to add a separator line in menus and tray menus by adding an item "", but this does not seem to work for a combobox list.

Is this even possible?

I know that I could add a fake item with characters to create a line, but then it would also become possible to select that fake item and I don't want that.

Thank you for your time.

Posted

Without subclassing the control you only try to revert to the old entry, when the user selects it:

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("ComboBox with Fake Separator", 300, 200)

$hCombo = GUICtrlCreateCombo("", 50, 50, 200)
GUICtrlSetData($hCombo, "Option 1|Option 2|----------|Option 3|Option 4")

GUISetState()

Local $prevSelection = "Option 1"
GUICtrlSetData($hCombo, $prevSelection)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case Else
            Local $sel = GUICtrlRead($hCombo)
            If $sel = "----------" Then
                GUICtrlSetData($hCombo, $prevSelection)
            Else
                $prevSelection = $sel
            EndIf
    EndSwitch
WEnd

 

Posted
6 hours ago, WildByDesign said:

Is it possible to add separator (horizontal line) to ComboBox list?

Is it possible to add separator (horizontal line)  popup a listview when I click ComboBox list?
Is it possible to have a listview under a combobox button ?

I know that am not answering the OP question but, is there another way to graphically present the data/info that you'd like to show in a creative way ?
I was thinking of you click a control ( button or label or anything ) and a child GUI with a listview without header in it could have sections.
( I'd code an example but am busy. In any case, if you like the idea as an alternative, try it out )

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

Posted (edited)

You have something like this in mind?

 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>

Global $mainGUI = GUICreate("Custom Dropdown ListView", 300, 150)
Global $btnSelect = GUICtrlCreateButton("Select option", 50, 40, 200, 30)
Global $lblSelected = GUICtrlCreateLabel("Selected: None", 50, 90, 200, 20)

GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btnSelect
            ShowCustomDropdown()
    EndSwitch
WEnd

Func ShowCustomDropdown()
    Local $childGUI = GUICreate("", 220, 150, WinGetPos($mainGUI)[0] + 50, WinGetPos($mainGUI)[1] + 70, _
            $WS_POPUP, $WS_EX_TOOLWINDOW, $mainGUI)

    Local $dummyBegin = GUICtrlCreateDummy()
    Local $lv = GUICtrlCreateListView("Option 0", 0, 0, 220, 150, BitOR($LVS_REPORT, $LVS_SINGLESEL))
    GUICtrlSendMsg($lv, $LVM_SETCOLUMNWIDTH, 0, 200)

    Local $items[6] = ["Option 1", "Option 2", "---", "Option 3", "---", "Option 4"]
    For $i = 0 To UBound($items) - 1
        Local $itemID = GUICtrlCreateListViewItem($items[$i], $lv)
        If $items[$i] = "---" Then
            GUICtrlSetColor($itemID, 0x888888)
            GUICtrlSetBkColor($itemID, 0xF0F0F0)
        EndIf
    Next
    Local $dummyEnd = GUICtrlCreateDummy()
    GUISetState(@SW_SHOW, $childGUI)

    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_CLOSE
                GUIDelete($childGUI)
                ExitLoop
            Case $dummyBegin To $dummyEnd
                If GUICtrlRead($msg) <> "---" Then
                    GUICtrlSetData($lblSelected, "Selected: " & GUICtrlRead($msg))
                    GUIDelete($childGUI)
                    ExitLoop
                EndIf
        EndSwitch
    WEnd
EndFunc   ;==>ShowCustomDropdown

 

Edited by IronFine
Posted (edited)

following the instructions of argumentum 
I got this far

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

Global $g_idListView
Global $g_bListViewVisible = False
Global $g_InputCombo

_MainGUI()

Func _MainGUI()

    Local $hGUI = GUICreate("fake combo", 364, 250)

    Local $iX = 65, $iY = 30, $iW = 150, $iH = 21

    ; fake combo
    $g_InputCombo = GUICtrlCreateInput("", $iX, $iY, $iW, $iH)
    Local $idBtnCombo = GUICtrlCreateButton("🔻", $iX + $iW, $iY - 1, $iH + 2, $iH + 2)

    ; ListView
    $g_idListView = GUICtrlCreateListView("", $iX, $iY + $iH, $iW + $iH, 180, BitOR($LVS_NOCOLUMNHEADER, $LVS_REPORT), BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_TRACKSELECT))
    GUICtrlSetState($g_idListView, $GUI_HIDE) ; hidden

    ; Add columns
    _GUICtrlListView_AddColumn($g_idListView, "", $iW)

    ; Enable group view
    _GUICtrlListView_EnableGroupView($g_idListView)

    ; Group 1
    _GUICtrlListView_InsertGroup($g_idListView, -1, 1, "Fruits")
    _GUICtrlListView_AddItem($g_idListView, "Apple")
    _GUICtrlListView_SetItemGroupID($g_idListView, _GUICtrlListView_GetItemCount($g_idListView) - 1, 1)
    _GUICtrlListView_AddItem($g_idListView, "Banana")
    _GUICtrlListView_SetItemGroupID($g_idListView, _GUICtrlListView_GetItemCount($g_idListView) - 1, 1)

    ; Group 2
    _GUICtrlListView_InsertGroup($g_idListView, -1, 2, "Vegetables")
    _GUICtrlListView_AddItem($g_idListView, "Carrot")
    _GUICtrlListView_SetItemGroupID($g_idListView, _GUICtrlListView_GetItemCount($g_idListView) - 1, 2)
    _GUICtrlListView_AddItem($g_idListView, "Spinach")
    _GUICtrlListView_SetItemGroupID($g_idListView, _GUICtrlListView_GetItemCount($g_idListView) - 1, 2)

    ; Group 3
    _GUICtrlListView_InsertGroup($g_idListView, -1, 3, "Dairy")
    _GUICtrlListView_AddItem($g_idListView, "Milk")
    _GUICtrlListView_SetItemGroupID($g_idListView, _GUICtrlListView_GetItemCount($g_idListView) - 1, 3)

    ; Register the message handler
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
    GUISetState(@SW_SHOW)


    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit

            Case $idBtnCombo
                ; Toggle ListView visibility
                If Not $g_bListViewVisible Then
                    GUICtrlSetState($g_idListView, $GUI_SHOW + $GUI_FOCUS)
                    $g_bListViewVisible = True
                Else
                    GUICtrlSetState($g_idListView, $GUI_HIDE)
                    $g_bListViewVisible = False
                EndIf
        EndSwitch
    WEnd
EndFunc   ;==>_MainGUI

;---------------------------------------------------------------------------------------
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndListView = GUICtrlGetHandle($g_idListView)
    Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    Local $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_CLICK
                    Local $iIndex = _GUICtrlListView_GetSelectionMark($g_idListView) ; Get the index of the last selected item
                    ; Ensure a valid item was selected
                    If $iIndex <> -1 Then
                        Local $sItemText = _GUICtrlListView_GetItemText($g_idListView, $iIndex, 0)
                        If $sItemText <> "" Then
                            GUICtrlSetData($g_InputCombo, $sItemText)
                            GUICtrlSetState($g_idListView, $GUI_HIDE)
                            GUICtrlSetState($g_InputCombo, $GUI_FOCUS)
                            $g_bListViewVisible = False
                        EndIf
                    EndIf
                    Return 0

                Case $NM_DBLCLK
                    Return 0

            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
;---------------------------------------------------------------------------------------

 

Edit:
Normally it would require handling $WM_KILLFOCUS
and keyboard navigation, but the code would grow.
Just the central idea

Edited by ioa747
Edit

I know that I know nothing

Posted (edited)

There are some great responses and creative ideas here. Thank you all so much.

I apologize for my delay in responding. I hope that I don’t seem rude for the delay. I had moved forward with other parts of the GUI while my mind (and ideas) was fresh.

Later today I am going to return to this important part of my GUI and I will try the various ideas. Once I get a chance to try them, I will respond here to each of your ideas.

As always, I am grateful for your time and your help. :)

Edited by WildByDesign
Posted
54 minutes ago, argumentum said:

Edit: With the _GUICtrlMenu_* functions you can do a lot. Do look at them if you feel the built in are not enough

This is actually quite interesting. The only problem I could imagine is that the user might not be able to scroll through it with the up and down keys. But I will still look into it some more.

Posted
2 minutes ago, WildByDesign said:

the user might not be able to scroll through it

You can add the & to a number or Fkey...
image.png.00cca96929799aa0abd17019418d9126.png
 

Spoiler
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    Local $hGui = GUICreate("My GUI", 170, 40)

    Local $idOptionsBtn = GUICtrlCreateButton("&Options", 10, 10, 70, 20, $BS_FLAT)

    ; At first create a dummy control for the options and a contextmenu for it
    Local $idOptionsDummy = GUICtrlCreateDummy()
    Local $idOptionsContext = GUICtrlCreateContextMenu($idOptionsDummy)
    GUICtrlCreateMenuItem("Common" & @TAB & "&A", $idOptionsContext)
    GUICtrlCreateMenuItem("File" & @TAB & "&B", $idOptionsContext)
    GUICtrlCreateMenuItem("", $idOptionsContext)
    Local $idOptionsExit = GUICtrlCreateMenuItem("Exit" & @TAB & "(ESC)", $idOptionsContext)

    Local $idHelpBtn = GUICtrlCreateButton("&Help", 90, 10, 70, 20, $BS_FLAT)

    ; Create a dummy control and a contextmenu for the help too
    Local $idHelpDummy = GUICtrlCreateDummy()
    Local $idHelpContext = GUICtrlCreateContextMenu($idHelpDummy)
    GUICtrlCreateMenuItem("Website", $idHelpContext)
    GUICtrlCreateMenuItem("", $idHelpContext)
    Local $idHelpAbout = GUICtrlCreateMenuItem("About...", $idHelpContext)

    GUISetState(@SW_SHOW)

    Local $idMsg

    ; Loop until the user exits.
    While 1
        $idMsg = GUIGetMsg()

        Switch $idMsg
            Case $idOptionsExit, $GUI_EVENT_CLOSE
                ExitLoop

            Case $idOptionsBtn
                ShowMenu($hGui, $idMsg, $idOptionsContext)

            Case $idHelpBtn
                ShowMenu($hGui, $idMsg, $idHelpContext)

            Case $idHelpAbout
                MsgBox($MB_SYSTEMMODAL, "About...", "GUICtrlGetHandle-Sample")
        EndSwitch
    WEnd
    GUIDelete()
EndFunc   ;==>Example

; Show a menu in a given GUI window which belongs to a given GUI ctrl
Func ShowMenu($hWnd, $idCtrl, $idContext)
    Local $aPos, $x, $y
    Local $hMenu = GUICtrlGetHandle($idContext)

    $aPos = ControlGetPos($hWnd, "", $idCtrl)

    $x = $aPos[0]
    $y = $aPos[1] + $aPos[3]

    ClientToScreen($hWnd, $x, $y)
    TrackPopupMenu($hWnd, $hMenu, $x, $y)
EndFunc   ;==>ShowMenu

; Convert the client (GUI) coordinates to screen (desktop) coordinates
Func ClientToScreen($hWnd, ByRef $x, ByRef $y)
    Local $tPoint = DllStructCreate("int;int")

    DllStructSetData($tPoint, 1, $x)
    DllStructSetData($tPoint, 2, $y)

    DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "struct*", $tPoint)

    $x = DllStructGetData($tPoint, 1)
    $y = DllStructGetData($tPoint, 2)
    ; release Struct not really needed as it is a local
    $tPoint = 0
EndFunc   ;==>ClientToScreen

; Show at the given coordinates (x, y) the popup menu (hMenu) which belongs to a given GUI window (hWnd)
Func TrackPopupMenu($hWnd, $hMenu, $x, $y)
    DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0)
EndFunc   ;==>TrackPopupMenu

It all depends on how many items you're thinking of. Since you wanted dividers I thought that maybe with submenus..., don't know. You only said so much.

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

Posted

Story time:
I love my parents but I needed to move out and I told a woman I loved her, she told me she loved me to.
My parents whom I loved used to do my laundry and in her case, it was the same.
We divorced because we did not find in each other the love we got from our parents.
If we were to share more we would have realized that we were looking for an attendant, ..some one to cook and clean after ourselves 🤪

The more you share, ex: I want this towards solving this, brings about context :)

PS: the story is fictional, mostly :lol:

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

Posted
9 minutes ago, argumentum said:

It all depends on how many items you're thinking of. Since you wanted dividers I thought that maybe with submenus

I load my main combo box from an array of about 15-20 items but it could be more or less depending on user configuration.

I also loaded that same array into a menubar during testing. So I could use that same function to load the array into the context menu like you suggested. I will try this tonight and see how it goes.

Posted
5 minutes ago, argumentum said:

The more you share, ex: I want this towards solving this, brings about context

I will send you the code later in the evening for the GUI that I am working on so that you can see the code and also play with the functionality. This will help with context. I just won’t be at my PC for a few hours because it’s too nice outside right now. :)

  • Solution
Posted

I found this on my drive:

#include <GUIComboBox.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <FontConstants.au3>
#include <BorderConstants.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 $iItemWidth, $iItemHeight

Global $hGUI
Global $ComboBox
Global $hBrushNorm = _WinAPI_CreateSolidBrush($clrWindow)
Global $hBrushSel = _WinAPI_CreateSolidBrush($clrHighlight)

GUIRegisterMsg($WM_MEASUREITEM, '_WM_MEASUREITEM')
GUIRegisterMsg($WM_DRAWITEM, '_WM_DRAWITEM')
;GUIRegisterMsg($WM_COMMAND, '_WM_COMMAND')

$hGUI = GUICreate('Test', 220, 300)
$ComboBox = GUICtrlCreateCombo('', 10, 10, 200, 300, BitOR($WS_CHILD, $CBS_OWNERDRAWVARIABLE, $CBS_HASSTRINGS, $CBS_DROPDOWNLIST))
GUICtrlSetData($ComboBox, "Medabi|V!c†o®|joelson0007-|JScript|Belini|Jonatas-|AutoIt v3|www.autoitbrasil.com-|www.autoitscript.com", "Medabi")
GUISetState()

Do

Until GUIGetMsg() = $GUI_EVENT_CLOSE

_WinAPI_DeleteObject($hBrushSel)
_WinAPI_DeleteObject($hBrushNorm)
GUIDelete()

Func _WM_MEASUREITEM($hWnd, $iMsg, $iwParam, $ilParam)

    Local $stMeasureItem = DllStructCreate($tagMEASUREITEMSTRUCT, $ilParam)

    If DllStructGetData($stMeasureItem, 1) = $ODT_COMBOBOX Then
        Local $iCtlType, $iCtlID, $iItemID
        Local $ComboBoxBox
        Local $tSize
        Local $sText
        $iCtlType = DllStructGetData($stMeasureItem, 'CtlType')
        $iCtlID = DllStructGetData($stMeasureItem, 'CtlID')
        $iItemID = DllStructGetData($stMeasureItem, 'itemID')
        $iItemWidth = DllStructGetData($stMeasureItem, 'itemWidth')
        $iItemHeight = DllStructSetData($stMeasureItem, "itemHeight", DllStructGetData($stMeasureItem, 'itemHeight') + 4)
        ;$iItemHeight = DllStructGetData($stMeasureItem, 'itemHeight')
        $ComboBoxBox = GUICtrlGetHandle($iCtlID)
    EndIf

    $stMeasureItem = 0

    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
    Local $sText
    Local $iLeft, $iTop, $iRight, $iBottom
    $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)

                Local $iTop = DllStructGetData($tRect, 2), $iBottom = DllStructGetData($tRect, 4)

                DllStructSetData($tRect, 2, $iTop + 2)
                DllStructSetData($tRect, 4, $iBottom - 1)
                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
                DllStructSetData($tRect, 2, $iTop)
                DllStructSetData($tRect, 4, $iBottom)

                If $sText <> "" Then
                    If StringInStr($sText, "-", 0, -1) Then
                        ; Draw a "line" for a separator item
                        If Not BitAND($iItemState, $ODS_COMBOBOXEDIT) Then
                            DllStructSetData($tRect, 2, $iTop + ($iItemHeight))
                            _WinAPI_DrawEdge($hDC, DllStructGetPtr($tRect), $EDGE_ETCHED, $BF_TOP)
                        EndIf
                        $sText = StringTrimRight($sText, 1)
                    EndIf
                    DllStructSetData($tRect, 2, $iTop + 4)
                    _WinAPI_DrawText($hDC, $sText, $tRect, $DT_LEFT)
                    _WinAPI_SetTextColor($hDC, $clrForeground)
                    _WinAPI_SetBkColor($hDC, $clrBackground)
                EndIf
                _WinAPI_SetBkMode($hDC, $TRANSPARENT)

            Case $ODA_SELECT, $ODA_FOCUS
                For $i = 1 To 4
                    DllStructSetData($tRect, $i, DllStructGetData($tDIS, $i + 7))
                Next

                _GUICtrlComboBox_GetLBText($hWndItem, $iItemID, $sText)

                Local $iTop = DllStructGetData($tRect, 2), $iBottom = DllStructGetData($tRect, 4)

                DllStructSetData($tRect, 2, $iTop + 2)
                DllStructSetData($tRect, 4, $iBottom - 1)
                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
                DllStructSetData($tRect, 2, $iTop)
                DllStructSetData($tRect, 4, $iBottom)

                If $sText <> "" Then
                    If StringInStr($sText, "-", 0, -1) Then
                        ; Draw a "line" for a separator item
                        If Not BitAND($iItemState, $ODS_COMBOBOXEDIT) Then
                            DllStructSetData($tRect, 2, $iTop + ($iItemHeight))
                            _WinAPI_DrawEdge($hDC, DllStructGetPtr($tRect), $EDGE_ETCHED, $BF_TOP)
                        EndIf
                        $sText = StringTrimRight($sText, 1)
                    EndIf
                    DllStructSetData($tRect, 2, $iTop + 4)
                    _WinAPI_DrawText($hDC, $sText, $tRect, $DT_LEFT)
                    _WinAPI_SetTextColor($hDC, $clrForeground)
                    _WinAPI_SetBkColor($hDC, $clrBackground)
                EndIf
                _WinAPI_SetBkMode($hDC, $TRANSPARENT)
        EndSwitch
    EndIf

    $tRect = 0

    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_DRAWITEM

Func _WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg
    Local $hWndFrom, $iIDFrom, $iCode, $hWndCombo
    If Not IsHWnd($ComboBox) Then $hWndCombo = GUICtrlGetHandle($ComboBox)
    $hWndFrom = $ilParam
    $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
    $iCode = BitShift($iwParam, 16) ; Hi Word

    Switch $hWndFrom
        Case $ComboBox, $hWndCombo
            Switch $iCode
                Case $CBN_CLOSEUP ; Sent when the list box of a combo box has been closed
                    _DebugPrint("$CBN_CLOSEUP" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
                Case $CBN_DBLCLK ; Sent when the user double-clicks a string in the list box of a combo box
                    _DebugPrint("$CBN_DBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
                Case $CBN_DROPDOWN ; Sent when the list box of a combo box is about to be made visible
                    _DebugPrint("$CBN_DROPDOWN" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
                Case $CBN_EDITUPDATE ; Sent when the edit control portion of a combo box is about to display altered text
                    _DebugPrint("$CBN_EDITUPDATE" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
                Case $CBN_ERRSPACE ; Sent when a combo box cannot allocate enough memory to meet a specific request
                    _DebugPrint("$CBN_ERRSPACE" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
                Case $CBN_KILLFOCUS ; Sent when a combo box loses the keyboard focus
                    _DebugPrint("$CBN_KILLFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
                Case $CBN_SELCHANGE ; Sent when the user changes the current selection in the list box of a combo box
                    _DebugPrint("$CBN_SELCHANGE" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
                    ; Select Item
                    ;_GUICtrlComboBox_SetCurSel($ComboBox, _GUICtrlComboBox_GetCurSel($ComboBox))

                    ; no return value
                Case $CBN_SELENDCANCEL ; Sent when the user selects an item, but then selects another control or closes the dialog box
                    _DebugPrint("$CBN_SELENDCANCEL" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
                Case $CBN_SELENDOK ; Sent when the user selects a list item, or selects an item and then closes the list
                    _DebugPrint("$CBN_SELENDOK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
                Case $CBN_SETFOCUS ; Sent when a combo box receives the keyboard focus
                    _DebugPrint("$CBN_SETFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_COMMAND

Func _DebugPrint($s_text, $line = @ScriptLineNumber)
    ConsoleWrite( _
            "!===========================================================" & @LF & _
            "+======================================================" & @LF & _
            "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
            "+======================================================" & @LF)
EndFunc   ;==>_DebugPrint

It's buried somewhere in this forum...

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted
8 hours ago, ioa747 said:

following the instructions of argumentum 
I got this far

This is really nice. Thank you for sharing. I've used listviews and many of my projects but I have never used groups before. While this might not be exactly what I need for my current project, I'm going to keep this script around because I have some other ideas for groups now.

Posted
On 7/3/2025 at 11:28 AM, IronFine said:

Without subclassing the control you only try to revert to the old entry, when the user selects it:

This is a really cool technique. Thank you for sharing, I appreciate it very much.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...