GUI Combo unbeschreibbar, weiß...

  • Ich möchte eine unbeschreibbare Combobox erstellen, dazu habe ich bis jetzt den code:

    "GuiCtrlCreatecombo("", 10, 30, 160, 50, 0x0003)"

    Doch ich finde diese grauen boxen die entstehen, wenn ich sie unbeschreibbar mache, ziemlich hässlich.
    Gibt es eine Möglichkeit die Combobox wieder weiß zu färben, so wie sie normal aussieht?

    Einmal editiert, zuletzt von llllll (14. Dezember 2008 um 11:14)

    • Offizieller Beitrag

    Ich hatte ein ähnliches Problem mit den Input-Elementen und habe das mit Hilfe von _WinAPI_SetSysColors (nochmal Danke an BugFix) gelöst:

    Spoiler anzeigen
    [autoit]


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

    [/autoit] [autoit][/autoit] [autoit]

    GUICreate("My GUI combo")

    [/autoit] [autoit][/autoit] [autoit]

    Global $aElements[2] = [$COLOR_HIGHLIGHTTEXT, $COLOR_HIGHLIGHT]
    Global $aColors[2] = [0x000000, 0xFFFFFF], $aSaveColors[2] ; Farben hier im BGR-Format!
    $aSaveColors[0] = _WinAPI_GetSysColor($COLOR_HIGHLIGHTTEXT)
    $aSaveColors[1] = _WinAPI_GetSysColor($COLOR_HIGHLIGHT)
    _WinAPI_SetSysColors($aElements, $aColors)

    [/autoit] [autoit][/autoit] [autoit]

    GUICtrlCreateCombo("item1", 10, 30, 160, 50, 0x0003)
    GUICtrlSetData(-1, "item2|item3", "item3")

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    [/autoit] [autoit][/autoit] [autoit]

    _WinAPI_SetSysColors($aElements, $aSaveColors)

    [/autoit]
  • Also erstmal: Hast du Readonly benutzt?

    Ja, du kannst ja die Hintergrundfarbe festlegen, in diesem Falle auf FFFFFF

  • Hmm, hab das Script von Oscar eben ausprobiert, aber es funktioniert bei mir nicht, die Box ist immer noch grau. :(
    Dafür ist jetzt alles weiß was ich auswähle (in windows)

  • $net = GuiCtrlCreatecombo("", 10, 30, 160, 50, 0x0003)
    GUICtrlSetBkColor($net,0xFFFFFF)

    Funktioniert auch nicht, oder was meintest du?

  • was meinst du denn mit Grau? Poste doch mal ein Bild wo das Graue und das gewünschte drauf sind
    //Edit: meinst du den grau gepunkteten rahmen?

  • Nein, ich glaube er meint den Hintergrund von dem Combo, oder?

    Versuch doch mal über Koda ein bisschen zu probieren...

  • Also sehen bei mir genau gleich aus mit und ohne beschreibbar, bis auf den gepunkteten Rahmen.

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <ComboConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt('MustDeclareVars', 1)

    [/autoit] [autoit][/autoit] [autoit]

    Example()

    [/autoit] [autoit][/autoit] [autoit]

    Func Example()
    Local $msg
    GUICreate("My GUI combo") ; will create a dialog box that when displayed is centered

    [/autoit] [autoit][/autoit] [autoit]

    GUICtrlCreateCombo("item1", 10, 10,300,500) ; create first item
    GUICtrlSetData(-1, "item2|item3", "item3") ; add other item snd set a new default


    GUICtrlCreateCombo("item1", 10, 50,300,500,$CBS_DROPDOWNLIST) ; create first item
    GUICtrlSetData(-1, "item2|item3", "item3") ; add other item snd set a new default


    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    ; Run the GUI until the dialog is closed
    While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
    EndFunc ;==>Example

    [/autoit]
    • Offizieller Beitrag

    Hi du hast recht, wenn du Windows Xp benutzt. Wenn man dein Script unter Vista oder Win 2008 Server laufen läßt ist die 2. Combobox grau . Nur wenn sie geöffnet ist sind die auszuwählenden einträge weiß hinterlegt. Wenn das 2. Combo nicht offen ist sieht es irgendwie wie ein Button aus .

    Edit: Bei Oscars Script aus Post 2 ist das genauso. Scheint an Windows Vista/2008 zu liegen.

    • Offizieller Beitrag

    Dann bastel Dir doch Deine eigene Combobox:

    Spoiler anzeigen
    [autoit]


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

    [/autoit] [autoit][/autoit] [autoit]

    Opt('GUIOnEventMode', 1)

    [/autoit] [autoit][/autoit] [autoit]

    $hGui = GUICreate('Combo-Experiment')
    GUISetOnEvent($GUI_EVENT_CLOSE, '_End')
    GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, '_Down')

    [/autoit] [autoit][/autoit] [autoit]

    $hLabel = GUICtrlCreateLabel('Eintrag 1', 10, 30, 160, 22, Default, $WS_EX_STATICEDGE)
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    GUICtrlSetColor(-1, 0x0000FF)
    GUICtrlSetFont(-1, 12, 600, 0, 'Arial')

    [/autoit] [autoit][/autoit] [autoit]

    $hCombo = GUICtrlCreateCombo('', 170, 30, 19, 25)

    [/autoit] [autoit][/autoit] [autoit]

    $hList = GUICtrlCreateList('', 10, 52, 179, 90)
    GUICtrlSetOnEvent(-1, '_ListSelect')
    GUICtrlSetFont(-1, 12, 400, 0, 'Arial')
    GUICtrlSetBkColor(-1, 0x000099)
    GUICtrlSetColor(-1, 0xFFFFFF)
    GUICtrlSetData(-1, 'Eintrag 1|Eintrag 2|Eintrag 3|Eintrag 4|Eintrag 5')
    GUICtrlSetState(-1, $GUI_HIDE)

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    $bOpen = True

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    Sleep(20)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _End()
    Exit
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _Down()
    Local $Info = GUIGetCursorInfo($hGui)
    Switch $Info[4]
    Case $hCombo, $hLabel
    If $bOpen Then
    GUICtrlSetState($hList, $GUI_SHOW)
    Else
    GUICtrlSetState($hList, $GUI_HIDE)
    EndIf
    $bOpen = Not $bOpen
    GUICtrlSetState($hList, $GUI_FOCUS)
    EndSwitch
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _ListSelect()
    GUICtrlSetData($hLabel, StringReplace(GUICtrlRead($hList), @CRLF, ''))
    GUICtrlSetState($hList, $GUI_HIDE)
    $bOpen = True
    EndFunc

    [/autoit]

    Da kann man dann die Farben selbst bestimmen. :)

    • Offizieller Beitrag

    Oscar sieht gut aus . Wenn man den öffnen Button bei deiner Combo drückt reagiert er aber net bein 1. mal . Ebenso verhält es sich mit der Auswahl der einzelnen Elemente. Mal klappt es bein 1. mal mal net . Irgendwie hakt des.

    RR04: Du hast die Lösung für das Anzeigeproblem.

    [autoit]

    DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0)

    [/autoit]


    Damit klappt des mit den Comboboxen :thumbup:

    • Offizieller Beitrag

    Bei Sleep auf 10 klappt es :thumbup:

  • Versuchs doch mal mit ownerdraw ;)

    Spoiler anzeigen
    [autoit]

    #include<GuiComboBox.au3>
    #include<WinAPI.au3>
    #include<ComboConstants.au3>
    #include<WindowsConstants.au3>
    #include<GUIConstantsEx.au3>

    [/autoit] [autoit][/autoit] [autoit]

    #include<StructureConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    GUIRegisterMsg(0x002C, "WM_MEASUREITEM")
    GUIRegisterMsg(0x002B, "WM_DRAWITEM")
    Global Const $ODT_COMBOBOX = 3
    Global Const $tagMEASUREITEMSTRUCT = "UINT CtlType; UINT CtlID; UINT itemID; UINT itemWidth; UINT itemHeight; DWORD itemData"
    Global Const $tagDRAWITEMSTRUCT = "UINT CtlType; UINT CtlID; UINT itemID; UINT itemAction; UINT itemState; dword hwndItem; dword hDC; int Left;int Top;int Right;int Bottom; long_ptr itemData"
    Global Const $ODS_HOTLIGHT = 0x40
    Global Const $ODS_SELECTED = 0x1
    Global Const $ODS_FOCUS = 0x10
    Global Const $BF_BOTTOM = 0x8
    Global Const $BDR_RAISEDOUTER = 0x1

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Global Const $CBS_MULTILINE = 2^11
    Global Const $CBS_BREAKWORDS = 2^12

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $GUI = GUICreate("hh")
    $com = GUICtrlCreateCombo("", 10, 10, 200, 800, BitOR($GUI_SS_DEFAULT_COMBO,$CBS_OWNERDRAWVARIABLE,$CBS_HASSTRINGS,$CBS_MULTILINE,$CBS_BREAKWORDS) )

    [/autoit] [autoit][/autoit] [autoit]

    _GUICtrlComboBox_AddString($com,"as")
    _GUICtrlComboBox_AddString($com,"sd" & @CRLF & "hh")
    _GUICtrlComboBox_AddString($com,"hällo" & @CRLF & "hh")
    _GUICtrlComboBox_AddString($com,"test" & @CRLF & "multiline jjjjjjj fgfgfgf jghd jghdlgjfdlhgl")
    _GUICtrlComboBox_AddString($com,"dgshs sfh jfshlkgfjj" & @CRLF & "multiline jjjjjjj fgfgfgf jghd jghdlgjfdlhgl")

    [/autoit] [autoit][/autoit] [autoit]

    $com = GUICtrlCreateCombo("item1", 10, 50, 200, 800, BitOR($GUI_SS_DEFAULT_COMBO,$CBS_OWNERDRAWVARIABLE,$CBS_HASSTRINGS) )
    GUICtrlSetData(-1, "item2|item3", "item3") ; add other item snd set a new default

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    While GUIGetMsg() <> -3

    WEnd
    MsgBox(0, 'Die Liste:', _GUICtrlComboBox_GetList($com))

    [/autoit] [autoit][/autoit] [autoit]

    ;********************************************************************
    ; WM_MEASURE procedure
    ; by Prog@ndy
    ;********************************************************************
    Func WM_MEASUREITEM($hWnd, $Msg, $wParam, $lParam)
    Local $nResult = False, $tRect, $aResult
    Local Const $DT_EDITCONTROL = 0x2000

    Local $stMeasureItem = DllStructCreate($tagMEASUREITEMSTRUCT, $lParam)
    If DllStructGetData($stMeasureItem, 1) = $ODT_COMBOBOX Then
    Local $pszString = DllStructGetData($stMeasureItem, "itemData")
    Local $ctlID = DllStructGetData($stMeasureItem, "CtlID")
    Local $ITEMID = DllStructGetData($stMeasureItem,"itemID")
    If $pszString = 0 Then
    Return 0
    EndIf
    Local $text
    _GUICtrlComboBox_GetLBText($ctlID,$itemID,$text)
    Local $Style = _WinAPI_GetWindowLong(_WinAPI_GetDlgItem($hWnd,DllStructGetData($stMeasureItem,2)),-16)
    Local $MULTISINGLE = $DT_SINGLELINE
    If BitAND($Style,$CBS_MULTILINE)=$CBS_MULTILINE Then $MULTISINGLE = 0
    If BitAND($Style,$CBS_MULTILINE)=$CBS_MULTILINE And BitAND($Style,$CBS_BREAKWORDS)=$CBS_BREAKWORDS Then $MULTISINGLE = $DT_WORDBREAK

    Local $hDC = _WinAPI_GetDC(GUICtrlGetHandle(DllStructGetData($stMeasureItem,2)))

    [/autoit] [autoit][/autoit] [autoit]

    Local $tRect = DllStructCreate($tagRect)
    $pos = ControlGetPos($hWnd,"",$ctlID)
    DllStructSetData($tRect,3,$pos[2])

    _WinAPI_DrawText($hDC,$text,$tRect,BitOR($DT_CALCRECT,$DT_EDITCONTROL,$MULTISINGLE))
    _WinAPI_ReleaseDC(GUICtrlGetHandle(DllStructGetData($stMeasureItem,2)),$hDC)
    DllStructSetData($stMeasureItem,4,DllStructGetData($tRect,3))
    DllStructSetData($stMeasureItem,5,DllStructGetData($tRect,4))

    [/autoit] [autoit][/autoit] [autoit]


    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc ;==>WM_MEASUREITEM

    [/autoit] [autoit][/autoit] [autoit]

    ;********************************************************************
    ; WM_DRAW procedure
    ; by Prog@ndy
    ;********************************************************************
    Func WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam)
    Local $stDrawItem = DllStructCreate($tagDRAWITEMSTRUCT, $lParam)

    If DllStructGetData($stDrawItem, 1) = $ODT_COMBOBOX Then
    Local Const $DT_EDITCONTROL = 0x2000
    ;~ 'Determine if I'm highlighting the current combo box item because
    ;~ 'I want the selected item to look different from those that are not selected.
    Local $state = DllStructGetData($stDrawItem,5)
    Local $ctlID = DllStructGetData($stDrawItem, "CtlID")
    Local $ITEMID = DllStructGetData($stDrawItem,"itemID")
    Local $bHighlightItem = (BitAND($state,$ODS_FOCUS) = $ODS_FOCUS) Or (BitAND($state,$ODS_HOTLIGHT) = $ODS_HOTLIGHT) Or (BitAND($state,$ODS_SELECTED) = $ODS_SELECTED)
    Local $hDC = DllStructGetData($stDrawItem,7)
    Local $text = "???????"

    [/autoit] [autoit][/autoit] [autoit]

    _GUICtrlComboBox_GetLBText(HWnd(DllStructGetData($stDrawItem,6)),$itemID,$text )
    Local $Style = _WinAPI_GetWindowLong(HWnd(DllStructGetData($stDrawItem,6)),-16)
    Local $MULTISINGLE = $DT_SINGLELINE
    If BitAND($Style,$CBS_MULTILINE)=$CBS_MULTILINE Then $MULTISINGLE = 0
    If BitAND($Style,$CBS_MULTILINE)=$CBS_MULTILINE And BitAND($Style,$CBS_BREAKWORDS)=$CBS_BREAKWORDS Then $MULTISINGLE = $DT_WORDBREAK

    If $bHighlightItem = True Then
    ;~ 'fill the background of the item
    Local $tRect = DllStructCreate($tagRect,DllStructGetPtr($stDrawItem,8))
    _MLC_WinAPI_SetBkMode($hDC,1)
    _WinAPI_FillRect($hDC,DllStructGetPtr($stDrawItem,8),_WinAPI_GetSysColorBrush(13))
    _WinAPI_SetTextColor($hDC,_WinAPI_GetSysColorBrush(14))
    _WinAPI_DrawText($hDC,$text,$tRect,BitOR($DT_EDITCONTROL,$MULTISINGLE))
    ;~ 'draw the text, position it so that it starts 5 pixels to the right of the image
    ;~ g.DrawString(str, Me.ComboBox1.Font, bWhite, e.Bounds.Left + myimage.Width + 5, e.Bounds.Top)
    Else
    ;~ 'this block does the same thing as above but uses different colors to represent the different state.
    Local $tRect = DllStructCreate($tagRect,DllStructGetPtr($stDrawItem,8))
    _MLC_WinAPI_SetBkMode($hDC,1)
    _WinAPI_FillRect($hDC,DllStructGetPtr($stDrawItem,8),_WinAPI_GetSysColorBrush(5))
    If $MULTISINGLE <> $DT_SINGLELINE Then _WinAPI_DrawEdge($hDC,DllStructGetPtr($stDrawItem,8),$BDR_RAISEDOUTER ,$BF_BOTTOM)
    _WinAPI_SetTextColor($hDC,_WinAPI_GetSysColorBrush(8))
    _WinAPI_DrawText($hDC,$text,$tRect,BitOR($DT_EDITCONTROL,$MULTISINGLE))
    EndIf
    EndIf
    EndFunc ;==>WM_MEASUREITEM

    [/autoit] [autoit][/autoit] [autoit]

    Func _MLC_WinAPI_SetBkMode($hDC, $iColor)
    Local $aResult

    [/autoit] [autoit][/autoit] [autoit]

    $aResult = DllCall("GDI32.dll", "int", "SetBkMode", "hwnd", $hDC, "int", $iColor)
    Return $aResult[0]
    EndFunc ;==>_WinAPI_SetBkColor

    [/autoit] [autoit][/autoit] [autoit][/autoit]
  • Wirkt ja alles recht kompliziert für einen Schönheitsfehler.....
    Kann man nicht einfach die Auswahl aufheben, sobald man in die combobox klickt?

    Einmal editiert, zuletzt von llllll (13. Dezember 2008 um 15:24)

    • Offizieller Beitrag

    Oh, das funktioniert tatsächlich! :)
    Man braucht dann aber irgendein zusätzliches GUI-Element, dem man den Focus zuweisen kann:

    Spoiler anzeigen
    [autoit]


    #include<ButtonConstants.au3>
    #include<ComboConstants.au3>
    #include <GUIConstantsEx.au3>

    [/autoit] [autoit][/autoit] [autoit]

    GUICreate("My GUI combo")

    [/autoit] [autoit][/autoit] [autoit]

    $hCombo = GUICtrlCreateCombo("item1", 10, 10, 150, 25, $CBS_DROPDOWNLIST)
    GUICtrlSetData(-1, "item2|item3", "item3")

    [/autoit] [autoit][/autoit] [autoit]

    $hButton = GUICtrlCreateButton('ok', 180, 10, 30, 22, $BS_DEFPUSHBUTTON)
    GUICtrlSetState(-1, $GUI_FOCUS)

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    Switch GUIGetMsg()
    Case $hCombo
    GUICtrlSetState($hButton, $GUI_FOCUS)
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch
    WEnd

    [/autoit]
  • teste mal, ob das auch reicht:

    Spoiler anzeigen
    [autoit]

    #include<ButtonConstants.au3>
    #include<ComboConstants.au3>
    #include <GUIConstantsEx.au3>

    [/autoit] [autoit][/autoit] [autoit]

    GUICreate("My GUI combo")

    [/autoit] [autoit][/autoit] [autoit]

    $hCombo = GUICtrlCreateCombo("item1", 10, 10, 150, 25, $CBS_DROPDOWNLIST)
    GUICtrlSetData(-1, "item2|item3", "item3")

    [/autoit] [autoit][/autoit] [autoit]

    $hButton = GUICtrlCreateButton('ok', 180, 10, 30, 22, $BS_DEFPUSHBUTTON)
    GUICtrlSetState(-1, $GUI_FOCUS)

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    Switch GUIGetMsg()
    Case $hCombo

    [/autoit] [autoit][/autoit] [autoit]

    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch
    WEnd

    [/autoit]
  • Also bei mir sind die boxen von vorneherein durch $CBS_DROPDOWNLIST grau und wenn ich es entferne hat sich auch nicht verändert (sind dann eben wie stinknormale Combo Felder, wo man reinschreiben kann). Liegt das jetzt daran das ich Windows Vista habe?