Sign in to follow this  
Followers 0
smashly

Combbox help please

6 posts in this topic

#1 ·  Posted (edited)

Hi and thank you for taking the time to read my post.

I'm sure I'd seen a function to do what I'm after a while ago, but after searching profusely I can't seem to find it again.

Can anyone please point me in the right direction to create a combobox like this?

Edited by smashly

Share this post


Link to post
Share on other sites



can u attach ur picture cause I can't see it


[quote]Baby you're all that I want, When you're lyin' here in my armsI'm findin' it hard to believe, We're in heavenAnd love is all that I need , And I found it there in your heartIt isn't too hard to see, We're in heaven .Bryan Adams[/quote].............................................................................[u]AUTOIT[/u]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi and thank you for taking the time to read my post.

I'm sure I'd seen a function to do what I'm after a while ago, but after searching profusely I can't seem to find it again.

Can anyone please point me in the right direction to create a combobox like this?

I think it might not be possible to do exactly what you want. In case I'm right, and in case your are interested in a 'not very nice idea but it would work' sort of approach then maybe you could do this:

Have a little image designed to have just the colour blocks and place it so that it is just under the combobox with its right edge level with the combobox left edge. So this image will be just say 20 pixels wide and the height of the drop down list.

Make it invisible.

Set an event so that when the list drops down the image shows and it will appear to be part of the drop down list. Set the events, (or notifications actually) so that when a selection is made or the list closes up the image is made invisible again.

I think that would work, and I expect very few people would notice anything odd.

If you want an example then I will create something.

Of course, if someone now comes along with a proper solution this will look pretty stupid, but I can take it!

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Of course it is possible to do what you want if you have a custom drawn combobox. Maybe someone has an example of doing this.

Meanwhile, here is an example of doing what I suggested.

and this is the code

#include <GUIConstants.au3>
#include <guicombo.au3>
#include <misc.au3>
Global Const  $CBN_DROPDOWN = 7
Global Const $CBN_CLOSEUP = 8
Global Const $WM_NOTIFY = 0x004E
Global Const $WM_COMMAND = 0x0111
Global Const $CBN_EDITCHANGE = 5;
Global Const $CBN_SELCHANGE = 1;
Global Const $CBN_EDITUPDATE = 6;
Dim $cols[16] = [0,0x800000,0x008000,0x808000,0x000080,0x800008,0x008080,0x808080,0xC0C0C0,0xFF0000,0x00FF00,0XFFFF00,0x0000FF,0xFF00FF,0x00FFFF,0xFFFFFF]
$Formname = "colour pickier combobox"
$formwid=413
$formht = 280;short so that can demonstarte drop down dropping outside of form.
$Form3 = GUICreate($Formname, $formwid,$formht, 303, 249)
$Combo1 = GUICtrlCreateCombo("black", 145, 62, 145)
GUICtrlSetData(-1,"maroon|green|olive|navy|purple|teal|gray|silver|red|lime|yellow|blue|fuchsia|aqua|white")
;create the graphic for the chosen colour
$cp = ControlGetPos($Formname,'',$combo1)
$b = GUICtrlCreateGraphic($cp[0] - 26,$cp[1],31,$cp[3])
GUICtrlSetBkColor(-1,0xFFFFFF)
GUICtrlSetColor(-1,0x7996DE)

$a=GUICtrlCreateGraphic($cp[0] - 24, $cp[1] + 2, 23,$cp[3] - 4)
GUICtrlSetBkColor(-1,0x000000)
GUICtrlSetColor(-1,0x000000)
$bb=GUICtrlCreateButton("button",119,130)
GUICtrlCreateCheckbox("ticked Or Not",119,158)
GUICtrlCreateEdit("an edit box under the drop down area",100,180,200,100)
GUISetState(@SW_SHOW)

;$cp = ControlGetPos($Formname,'',$combo1)
GUIRegisterMsg($WM_COMMAND,"MY_WM_COMMAND")

;work out the form border width and title height
$mfp = WinGetPos($Formname)
$borderwid = ($mfp[2]- $formwid)/2
$TitleHt = $mfp[3] - $formht - $borderwid

$itemht = _GUICtrlComboGetItemHeight($combo1,1)

;creat a Form To hold the list of colours
$containerht= $itemht*16 + 2
$fhide = GUICreate("container",26,$containerht,$mfp[0] + $borderwid+$cp[0] - 26,$mfp[1] + $TitleHt+$cp[1]+21,$WS_POPUP)

GUICtrlCreateGraphic(0,0,27,$itemht*16 + 2)
GUICtrlSetBkColor(-1,0xFFFFFF)
GUICtrlSetColor(-1,0);0x7996DE)

For $nn = 0 To 15
    GuiCtrlCreateGraphic(2, 2+$itemht*$nn,22,$itemht - 2)
    GUICtrlSetBkColor(-1,$cols[$nn])
    GUICtrlSetColor(-1,0);0x7996DE)
Next

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $bb ;to test when dropdown goes above combo because too near bottom of screen
            $mfp = WinGetPos($Formname)
            WinMove($Formname,'',$mfp[0],$mfp[1]+1)
    EndSwitch
WEnd

Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    Local $nNotifyCode = _HiWord($wParam)
    Local $nID = _LoWord($wParam)
    Local $hCtrl = $lParam

    Switch $nID
        Case $combo1
            Switch $nNotifyCode
                Case $CBN_DROPDOWN
                    GUISetState(@SW_SHOW,WinGetHandle($fhide))
                    WinSetOnTop("container","",1)
                    $mfp = WinGetPos($Formname)
                    $tobottom = $mfp[1] + $TitleHt + $cp[1] + $cp[3]
                    If $tobottom > @DesktopHeight - $containerht Then
                        $shift = -$cp[3]- $containerht
                    Else
                        $shift = 0
                    EndIf
                    
                    WinMove("container","",$mfp[0] + $borderwid + $cp[0] - 26,$shift + $mfp[1] + $TitleHt + $cp[1]+$cp[3])

                Case $CBN_CLOSEUP
                    GUISetState(@SW_HIDE,WinGetHandle($fhide))
                    $re = GUICtrlRead($combo1)
                    $it = _GUICtrlComboFindString($combo1,$re)
                    GUICtrlSetBkColor($a,$cols[$it])
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;MY_WM_COMMAND




Func _HiWord($x)
    Return BitShift($x, 16)
EndFunc   ;==>_HiWord

Func _LoWord($x)
    Return BitAND($x, 0xFFFF)
EndFunc   ;==>_LoWord

Edit: Changed the script so that it is not limited by having controls under the drop down area, and colour chart made by script.

Still restricted to a fixed drop down list.

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

You could always use _ChooseColor() in <Misc.au3>

Share this post


Link to post
Share on other sites

Thank you Martin for taking the time to create/post your example.

I'm impressed, nice work m8 and it's greatly appreciated. :rambo:

Paulie I was using the choose color udf but I couldn't work out how to get the Gui of the color chooser to match and dock with my gui. I didn't want an ugly grey box popping up separate from my gui to choose a color, I was after more non obtrusive method that would blend in with my gui and match the color theme of my gui with only a basic few colors for a user to choose.

Cheers for the suggestions and Example :rolleyes:

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