Sign in to follow this  
Followers 0
Sypher

Combox Disabled Color

7 posts in this topic

Hey,

In the following example you can see my gui having a greenish color. Then the combobox is enabled, everything is OK. The text background from the combobox is white. But when it's disabled, it isn't gray (like i hoped i would be) but takes the background color of the GUI.

I think this is annoying, and not really nice.. Is there a way to fix this?

I tried setting GUICtrlSetBkColor and GUICtrlSetColor but that didn't work out.

Example code:

#include <GUIConstants.au3>

GUICreate("Example Window", 240, 110)
GUISetBkColor(0x99CC33)
$chkComboSwitchState = GUICtrlCreateCheckbox("Enable ComboBox", 20, 14, 200, 21)
GUICtrlSetState(-1, $GUI_CHECKED)

$cboItems = GUICtrlCreateCombo("", 20, 40, 200, 21, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, "Item 1|Item 2|Item 3|Item 4", "Item 1")
$cmdOK = GUICtrlCreateButton("OK", 85, 74, 75, 21)
GUICtrlSetState(-1, $GUI_FOCUS)

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()

    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $cmdOK
            Exit
        Case $msg = $chkComboSwitchState
            If GUICtrlRead($chkComboSwitchState) = $GUI_CHECKED Then
                GUICtrlSetState($cboItems, $GUI_ENABLE)
            Else
                GUICtrlSetState($cboItems, $GUI_DISABLE)
            EndIf
    EndSelect
WEnd

Thanks

Share this post


Link to post
Share on other sites



I can't work this one out either.

Here's a work around which is not very nice but it works. It depends how desperate you are.

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=d:\program files\autoit3\beta\koda\forms\play\test.kxf
$Form1 = GUICreate("AForm1", 415, 300, 303, 219)
GUISetBkColor(0x00FF00)
$cboItems = GUICtrlCreateCombo("cboItems", 152, 120, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL,$WS_BORDER))
GUICtrlSetData(-1, "aa|bb|cc")
$chkComboSwitchState = GUICtrlCreateCheckbox("chkComboSwitchState", 144, 48, 137, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlSetBkColor(-1, 0x00FF00)
$Label1 = GUICtrlCreateLabel("ALabel1", 48, 16, 43, 17, BitOR($SS_CENTER,$SS_GRAYFRAME,$SS_WHITEFRAME))
GUICtrlSetBkColor(-1, 0x00FF00)
$Graphic1 = GUICtrlCreateGraphic(153, 121, 126, 19, BitOR($SS_RIGHT,$SS_BLACKRECT,$SS_WHITERECT,$SS_NOTIFY))
$Label2 = GUICtrlCreateLabel("ALabel2", 154, 122, 111, 17)
GUICtrlSetColor(-1, 0x808080)
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUICtrlSetState($Label1,$GUI_HIDE)
GUICtrlSetState($Graphic1,$GUI_HIDE)

GUICtrlSetState($cboItems, $GUI_ENABLE)
GUICtrlSetState($Label1,$GUI_HIDE)
GUICtrlSetState($Graphic1,$GUI_HIDE)
;sleep(50)
GUICtrlSetState($cboItems, $GUI_DISABLE)
GUICtrlSetState($Label1,$GUI_SHOW)
GUICtrlSetData($Label2,guictrlread($cboItems))
GUICtrlSetState($Graphic1,$GUI_SHOW)
;sleep(100)
GUICtrlSetState($cboItems, $GUI_ENABLE)
GUICtrlSetState($Label1,$GUI_HIDE)
GUICtrlSetState($Graphic1,$GUI_HIDE)




While 1
    $msg = GUIGetMsg()

    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit

        Case $msg = $chkComboSwitchState
            If GUICtrlRead($chkComboSwitchState) = $GUI_CHECKED Then
                GUICtrlSetState($cboItems, $GUI_ENABLE)
                GUICtrlSetState($Label1,$GUI_HIDE)
                GUICtrlSetState($Graphic1,$GUI_HIDE)
            Else
                GUICtrlSetState($cboItems, $GUI_DISABLE)
                GUICtrlSetState($Label1,$GUI_SHOW)
                GUICtrlSetData($Label2,guictrlread($cboItems))
                GUICtrlSetState($Graphic1,$GUI_SHOW)
            EndIf
    EndSelect
WEnd

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

Another workaround:

You can seldefine a background color for the disabled state.

#include <GUIConstants.au3>

Global Const $WM_CTLCOLORSTATIC = 0x0138

GUIRegisterMsg($WM_CTLCOLORSTATIC, "WndProc")


GUICreate("Example Window", 240, 110)
GUISetBkColor(0x99CC33)
$chkComboSwitchState = GUICtrlCreateCheckbox("Enable ComboBox", 20, 14, 200, 21)
GUICtrlSetState(-1, $GUI_CHECKED)

$cboItems = GUICtrlCreateCombo("", 20, 40, 200, 21, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, "Item 1|Item 2|Item 3|Item 4", "Item 1")
$cmdOK = GUICtrlCreateButton("OK", 85, 74, 75, 21)
GUICtrlSetState(-1, $GUI_FOCUS)

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()

    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $cmdOK
            Exit
        Case $msg = $chkComboSwitchState
            If GUICtrlRead($chkComboSwitchState) = $GUI_CHECKED Then
                GUICtrlSetState($cboItems, $GUI_ENABLE)
            Else
                GUICtrlSetState($cboItems, $GUI_DISABLE)
            EndIf
    EndSelect
WEnd


Func WndProc($hWnd, $Msg, $wParam, $lParam)
    If $Msg = $WM_CTLCOLORSTATIC And $lParam = GUICtrlGetHandle($cboItems) Then
        ; Change the background color or just use Return
        ;SetBkColor($wParam, GetSysColor(17)) ; COLOR_GRAYTEXT
        SetBkColor($wParam, 0xCCCCCC) ; BGR-value
        Return 0
    EndIf
EndFunc


Func GetSysColor($nIndex)
    Local $nColor = DllCall("user32.dll", "int", "GetSysColor", _
                                                "int", $nIndex)
    Return $nColor[0]
EndFunc


Func SetBkColor($hDC, $nColor)
    Local $nOldColor = DllCall("gdi32.dll", "int", "SetBkColor", _
                                                "hwnd", $hDC, _
                                                "int", $nColor)
    Return $nOldColor[0]
EndFunc

Greets

Holger

Share this post


Link to post
Share on other sites

I like your method Holger.

The only problems i'm having are:

- I have multiple combo boxes needing this (around 10, 15...)

- I use the EventMode GUI, not $msg.. Would that cause any problems with WndProc?

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Hehe, i guess i got it working :shocked:

#include <GUIConstants.au3>

Global Const $WM_CTLCOLORSTATIC = 0x0138
GUIRegisterMsg($WM_CTLCOLORSTATIC, "WndProcNew")

GUICreate("Example Window", 240, 110)
GUISetBkColor(0x99CC33)
$chkComboSwitchState = GUICtrlCreateCheckbox("ComboBox 1", 10, 14)
GUICtrlSetState(-1, $GUI_CHECKED)

$chkComboSwitchState2 = GUICtrlCreateCheckbox("ComboBox 2", 120, 14)
GUICtrlSetState(-1, $GUI_CHECKED)

$cboItems = GUICtrlCreateCombo("", 20, 40, 200, 21, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, "Item 1|Item 2|Item 3|Item 4", "Item 1")
$cboItems2 = GUICtrlCreateCombo("", 20, 62, 200, 21, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, "Item 1|Item 2|Item 3|Item 4", "Item 1")
$cmdOK = GUICtrlCreateButton("OK", 85, 84, 75, 21)
GUICtrlSetState(-1, $GUI_FOCUS)

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()

    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $cmdOK
            Exit
        Case $msg = $chkComboSwitchState
            If GUICtrlRead($chkComboSwitchState) = $GUI_CHECKED Then
                GUICtrlSetState($cboItems, $GUI_ENABLE)
            Else
                GUICtrlSetState($cboItems, $GUI_DISABLE)
            EndIf
        Case $msg = $chkComboSwitchState2
            If GUICtrlRead($chkComboSwitchState2) = $GUI_CHECKED Then
                GUICtrlSetState($cboItems2, $GUI_ENABLE)
            Else
                GUICtrlSetState($cboItems2, $GUI_DISABLE)
            EndIf
    EndSelect
WEnd


Func WndProcNew($hWnd, $msg, $wParam, $lParam)
    If $msg = $WM_CTLCOLORSTATIC Then
        If $lParam = GUICtrlGetHandle($cboItems) Then
            ; Change the background color or just use Return
            ;SetBkColor($wParam, GetSysColor(17)) ; COLOR_GRAYTEXT
            SetBkColor($wParam, 0xFFFFFF) ; BGR-value
            Return 0
        ElseIf $lParam = GUICtrlGetHandle($cboItems2) Then
            ; Change the background color or just use Return
            ;SetBkColor($wParam, GetSysColor(17)) ; COLOR_GRAYTEXT
            SetBkColor($wParam, 0xFFFFFF) ; BGR-value
            Return 0
        EndIf
    EndIf
EndFunc   ;==>WndProcTest

Func GetSysColor($nIndex)
    Local $nColor = DllCall("user32.dll", "int", "GetSysColor", _
            "int", $nIndex)
    Return $nColor[0]
EndFunc   ;==>GetSysColor


Func SetBkColor($hDC, $nColor)
    Local $nOldColor = DllCall("gdi32.dll", "int", "SetBkColor", _
            "hwnd", $hDC, _
            "int", $nColor)
    Return $nOldColor[0]
EndFunc   ;==>SetBkColoroÝ÷ Øh¥ëaÌ"V¥²(®L"¶axKÞÙ¨uíý°º(ÉbëaÍý(®F¬Áéejëh×6#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)
Global Const $WM_CTLCOLORSTATIC = 0x0138
GUIRegisterMsg($WM_CTLCOLORSTATIC, "WndProcNew")

GUICreate("Example Window", 240, 110)
GUISetOnEvent($GUI_EVENT_CLOSE, "Bye")
GUISetBkColor(0x99CC33)
$chkComboSwitchState = GUICtrlCreateCheckbox("ComboBox 1", 10, 14)
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlSetOnEvent(-1, "Check1")

$chkComboSwitchState2 = GUICtrlCreateCheckbox("ComboBox 2", 120, 14)
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlSetOnEvent(-1, "Check2")

$cboItems = GUICtrlCreateCombo("", 20, 40, 200, 21, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, "Item 1|Item 2|Item 3|Item 4", "Item 1")
$cboItems2 = GUICtrlCreateCombo("", 20, 62, 200, 21, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, "Item 1|Item 2|Item 3|Item 4", "Item 1")
$cmdOK = GUICtrlCreateButton("OK", 85, 84, 75, 21)
GUICtrlSetOnEvent(-1, "Bye")
GUICtrlSetState(-1, $GUI_FOCUS)

GUISetState(@SW_SHOW)

Func Bye()
    Exit
EndFunc   ;==>Bye

Func Check1()
    If (GUICtrlRead($chkComboSwitchState) == $GUI_CHECKED) Then
        GUICtrlSetState($cboItems, $GUI_ENABLE)
    Else
        GUICtrlSetState($cboItems, $GUI_DISABLE)
    EndIf
EndFunc   ;==>Check1

Func Check2()
    If (GUICtrlRead($chkComboSwitchState2) == $GUI_CHECKED) Then
        GUICtrlSetState($cboItems2, $GUI_ENABLE)
    Else
        GUICtrlSetState($cboItems2, $GUI_DISABLE)
    EndIf
EndFunc   ;==>Check2

While 1
;~  $msg = GUIGetMsg()

;~  Select
;~      Case $msg = $GUI_EVENT_CLOSE
;~          Exit
;~      Case $msg = $cmdOK
;~          Exit
;~      Case $msg = $chkComboSwitchState
;~          If GUICtrlRead($chkComboSwitchState) = $GUI_CHECKED Then
;~              GUICtrlSetState($cboItems, $GUI_ENABLE)
;~          Else
;~              GUICtrlSetState($cboItems, $GUI_DISABLE)
;~          EndIf
;~      Case $msg = $chkComboSwitchState2
;~          If GUICtrlRead($chkComboSwitchState2) = $GUI_CHECKED Then
;~              GUICtrlSetState($cboItems2, $GUI_ENABLE)
;~          Else
;~              GUICtrlSetState($cboItems2, $GUI_DISABLE)
;~          EndIf
;~  EndSelect
    Sleep(500)
WEnd


Func WndProcNew($hWnd, $msg, $wParam, $lParam)
    If $msg = $WM_CTLCOLORSTATIC Then
        If $lParam = GUICtrlGetHandle($cboItems) Then
            ; Change the background color or just use Return
            ;SetBkColor($wParam, GetSysColor(17)) ; COLOR_GRAYTEXT
            SetBkColor($wParam, 0xFFFFFF) ; BGR-value
            Return 0
        ElseIf $lParam = GUICtrlGetHandle($cboItems2) Then
            ; Change the background color or just use Return
            ;SetBkColor($wParam, GetSysColor(17)) ; COLOR_GRAYTEXT
            SetBkColor($wParam, 0xFFFFFF) ; BGR-value
            Return 0
        EndIf
    EndIf
EndFunc   ;==>WndProcNew

Func GetSysColor($nIndex)
    Local $nColor = DllCall("user32.dll", "int", "GetSysColor", _
            "int", $nIndex)
    Return $nColor[0]
EndFunc   ;==>GetSysColor


Func SetBkColor($hDC, $nColor)
    Local $nOldColor = DllCall("gdi32.dll", "int", "SetBkColor", _
            "hwnd", $hDC, _
            "int", $nColor)
    Return $nOldColor[0]
EndFunc   ;==>SetBkColor

Can't get it to work in my currentgui though :/ Stange!

I've attached a debug file to this post. You can see what your functions do then...

result_debug.txt

Edited by Sypher

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