Teiltransparenter Label-Background

  • Hallo miteinander,

    ich stehe nun vor folgendem Problem:
    In einem GUI habe ich ein Bild als GUI-Background. Darauf werden Labels plaziert. Diese Labels sind aber teilweise schlecht zu erkennen, da kein Kontrast zwischen entsprechendem GUI-Hintergrund und Label-Farbe besteht. Nun kann ich den Labels ja eine Backgroundfarbe für eine gute Lesbarkeit zuweisen, was aber bei 100% Hintergrund unschön ausschaut.
    Daher möchte ich - wenn möglich - den Hintergrund der Labels teiltransparent anzeigen, sodass z.B. 50 % weißer Hintergrund hinterm Label ist und 50% der GUI-Background-Bildes zu sehen ist...

    Ich hoffe jemand kann mir dabei einen Denkanstoß geben, Grüße Andy :)

    Edit:
    [Blockierte Grafik: http://img32.imageshack.us/img32/441/bsplh.jpg]

    2 Mal editiert, zuletzt von AndyTR (5. Oktober 2011 um 22:49)

  • Hab auf die schnelle diese Funktion gefunden. Da wird allerdings auch die Schrift transparent.

    Spoiler anzeigen
    [autoit]

    GUICreate("Test", 500, 500)
    GUISetBkColor(0xFF0000)

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

    GUICtrlCreateLabel("Transparent 1", 10, 10, 100, 30, 0x201)
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    _GuiCtrlMakeTrans(-1, 200)

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

    GUICtrlCreateLabel("Transparent 2", 10, 90, 100, 30, 0x201)
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    _GuiCtrlMakeTrans(-1, 100)

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

    GUISetState()

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

    Do
    Until GUIGetMsg() = -3

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

    Func _GuiCtrlMakeTrans($iCtrlID,$iTrans=255)

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

    Local $pHwnd, $nHwnd, $aPos, $a

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

    $hWnd = GUICtrlGetHandle($iCtrlID);Get the control handle
    If $hWnd = 0 then Return SetError(1,1,0)
    $pHwnd = DllCall("User32.dll", "hwnd", "GetParent", "hwnd", $hWnd);Get the parent Gui Handle
    If $pHwnd[0] = 0 then Return SetError(1,2,0)
    $aPos = ControlGetPos($pHwnd[0],"",$hWnd);Get the current pos of the control
    If @error then Return SetError(1,3,0)
    $nHwnd = GUICreate("", $aPos[2], $aPos[3], $aPos[0], $aPos[1], 0x80000000, 0x00080000 + 0x00000040, $pHwnd[0]);greate a gui in the position of the control
    If $nHwnd = 0 then Return SetError(1,4,0)
    $a = DllCall("User32.dll", "hwnd", "SetParent", "hwnd", $hWnd, "hwnd", $nHwnd);change the parent of the control to the new gui
    If $a[0] = 0 then Return SetError(1,5,0)
    If NOT ControlMove($nHwnd,'',$hWnd,0,0) then Return SetError(1,6,-1);Move the control to 0,0 of the newly created child gui
    GUISetState(@SW_Show,$nHwnd);show the new child gui

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

    WinSetTrans($nHwnd,"",$iTrans);set the transparency
    If @error then Return SetError(1,7,0)
    GUISwitch($pHwnd[0]);switch back to the parent Gui

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

    Return $nHwnd;Return the handle for the new Child gui

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

    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit]
  • Auf jeden Fall eine nützliche Funktion, hilft mir aber leider nicht weiter, da es sich bei mir um Labels in verschiedenen Tabs handelt und dort überzeichnen sie sich gegenseitig... :(

  • Dann wirst du sowieso nicht drum herum kommen, die einzelnen Labels auf den verschiedenen Seiten manuell sichtbar und unsichtbar zu schalten, egal ob du es mit dieser Funktion oder mit GDIPlus oder so erledigst.
    Eine andere Variante kenne ich noch nicht, bzw. fällt mir jetzt keine ein. :(

  • Also hier mal ein angepasstes Beispielscript:

    Spoiler anzeigen
    [autoit]

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

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

    HotKeySet("{ESC}", "_Exit")
    Opt("GUIOnEventMode", 1)

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

    Global $Episoden[9] = [25, 25, 24, 25, 25, 24, 22, 23, 14]
    Gui()

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

    While 1
    Sleep(100)
    WEnd

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

    Func Gui()
    $Breite = 462
    $Hoehe = 266
    $GUI = GUICreate("", $Breite, $Hoehe)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    ;GUICtrlCreatePic(@ScriptDir & "/test.jpg", 2, 22, 458, 242)
    GUICtrlCreateLabel("", 2, 22, 458, 242) ; anstatt GUICtrlCreatePic
    GUICtrlSetBkColor(-1, 0xABCDEF) ; anstatt GUICtrlCreatePic
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlCreateTab(1, 1, $Breite, $Hoehe - 1)
    For $i = 1 To 9
    GUICtrlCreateTabItem("Staffel " & $i)
    For $j = 1 To $Episoden[$i - 1]
    $X_Koord = 10
    $Y_Koord = $j * 18 + 10
    If $j > 13 Then
    $X_Koord = 240
    $Y_Koord = ($j - 13) * 18 + 10
    EndIf
    $Laenge = Random(10, 50, 1)
    $String = "["
    For $k = 1 To $Laenge
    $String &= "."
    Next
    $String &= "]"
    GUICtrlCreateLabel($j & ". " & $String, $X_Koord, $Y_Koord, -1, 14)
    GUICtrlSetCursor(-1, 0)
    GUICtrlSetBkColor(-1, 0xFFFFFF) ; hier muss etwas passieren
    Next
    Next
    GUISetState(@SW_SHOW)
    EndFunc

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

    Func _Exit()
    Exit
    EndFunc

    [/autoit]


    Gruß :)

    Einmal editiert, zuletzt von AndyTR (5. Oktober 2011 um 14:16)

  • Vielleicht so?

    Spoiler anzeigen
    [autoit]


    ;coded by UEZ 2011
    #include <GDIPlus.au3>
    #include <GUIConstantsEx.au3>
    _GDIPlus_Startup()
    Global Const $IMAGE_BITMAP = 0
    Global Const $STM_SETIMAGE = 0x0172

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

    Global Const $path = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir")
    Global Const $sFile = $path & "\Examples\GUI\mslogo.jpg"
    Global Const $hImage = _GDIPlus_ImageLoadFromFile($sFile)
    Global Const $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    Global Const $iImgWidth = _GDIPlus_ImageGetWidth($hImage)
    Global Const $iImgHeight = _GDIPlus_ImageGetHeight($hImage)
    Global Const $hGUI = GUICreate("Test", $iImgWidth, $iImgHeight)
    Global Const $idPic = GUICtrlCreatePic("", 0, 0, $iImgWidth, $iImgHeight)
    GuiCtrlSetState(-1, $GUI_DISABLE)
    GUISetState()
    _WinAPI_DeleteObject(GUICtrlSendMsg($idPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap))

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

    Global Const $iLabelW = 130
    Global Const $iLabelH = 25
    Global Const $iLabelX = 0
    Global Const $iLabelY= 0
    Global Const $idLabelBg = GUICtrlCreatePic("", $iLabelX, $iLabelY, $iLabelW, $iLabelH)
    Global Const $hBG_Bitmap = Create_BgBitmap($iLabelW, $iLabelH)
    _WinAPI_DeleteObject(GUICtrlSendMsg($idLabelBg, $STM_SETIMAGE, $IMAGE_BITMAP, $hBG_Bitmap))

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

    Global Const $idLabel = GUICtrlCreateLabel("This is a test!", $iLabelX, $iLabelY, $iLabelW, $iLabelH)
    GUICtrlSetFont(-1, 16)
    GUICtrlSetColor(-1, 0x40FF40)
    GUICtrlSetBkColor(-1, -2)

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

    While True
    $msg = GUIGetMsg()
    Switch $msg
    Case $GUI_EVENT_CLOSE
    _GDIPlus_ImageDispose($hImage)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteObject($hBG_Bitmap)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
    Exit
    EndSwitch
    WEnd

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

    Func Create_BgBitmap($iWidth, $iHeight, $iColor = 0x80FFFFFF)
    Local Const $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0)
    Local Const $hBitmap = $aResult[6]
    Local Const $hBrush = _GDIPlus_BrushCreateSolid($iColor)
    Local Const $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsFillRect($hContext, 0, 0, $iWidth, $iHeight, $hBrush)
    _GDIPlus_GraphicsDispose($hContext)
    _GDIPlus_BrushDispose($hBrush)
    Return _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    EndFunc

    [/autoit]

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

    Einmal editiert, zuletzt von UEZ (5. Oktober 2011 um 15:08)

  • Dein Code, UEZ, hilft mir leider auch nicht weiter, außerdem wird beim mini-und maximieren der Hintergrund gestaucht, aber das lässt sich auch nicht auf mehrere tabs anwenden, schade

  • Um das Stauchen abzustellen, kannst du

    [autoit]


    Global Const $idPic = GUICtrlCreatePic("", 0, 0, $iImgWidth, $iImgHeight)

    [/autoit]

    nehmen.

    Mit den Tabs muss ich mal schauen, ob das funzt.

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

  • Hier ein Ansatz:

    Spoiler anzeigen
    [autoit]


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

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

    HotKeySet("{ESC}", "_Exit")
    Opt("GUIOnEventMode", 1)

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

    _GDIPlus_Startup()
    ;~ Global Const $IMAGE_BITMAP = 0
    Global Const $STM_SETIMAGE = 0x0172
    Global Const $path = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir")
    Global Const $sFile = $path & "\Examples\GUI\msoobe.jpg"
    Global Const $hImage = _GDIPlus_ImageLoadFromFile($sFile)
    Global Const $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    _GDIPlus_ImageDispose($hImage)

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

    Global $iTabs = 9
    Global $iEpisoden = 9
    Global $Episoden[$iEpisoden] = [25, 25, 24, 25, 25, 24, 22, 23, 14]
    Global $aBG[$Episoden[UBound($Episoden) - 2] * $iTabs][2]

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

    Gui()

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

    While 1
    Sleep(100)
    WEnd

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

    Func Gui()
    $kk = 0
    $Breite = 462
    $Hoehe = 266
    $GUI = GUICreate("", $Breite, $Hoehe)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    $idPic = GUICtrlCreatePic("", 2, 22, 458, 242)
    GuiCtrlSetState(-1, $GUI_DISABLE)
    ;~ GUICtrlCreateLabel("", 2, 22, 458, 242) ; anstatt GUICtrlCreatePic
    ;~ GUICtrlSetBkColor(-1, 0xABCDEF) ; anstatt GUICtrlCreatePic
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlCreateTab(1, 1, $Breite, $Hoehe - 1)
    For $i = 1 To $iTabs
    GUICtrlCreateTabItem("Staffel " & $i)
    For $j = 1 To $Episoden[$i - 1]
    $X_Koord = 10
    $Y_Koord = $j * 18 + 10
    If $j > 13 Then
    $X_Koord = 240
    $Y_Koord = ($j - 13) * 18 + 10
    EndIf
    $Laenge = Random(10, 50, 1)
    $String = "["
    For $k = 1 To $Laenge
    $String &= "."
    Next
    $String &= "]"

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

    $aBG[$kk][0] = GUICtrlCreatePic("", $X_Koord, $Y_Koord)
    $aBG[$kk][1] = Create_BgBitmap(StringLen($j & ". " & $String) * 3.4, 14)
    _WinAPI_DeleteObject(GUICtrlSendMsg($aBG[$kk][0], $STM_SETIMAGE, $IMAGE_BITMAP, $aBG[$kk][1]))
    GUICtrlSetState(-1, $GUI_DISABLE)

    GUICtrlCreateLabel($j & ". " & $String, $X_Koord, $Y_Koord, StringLen($j & ". " & $String) * 3.385, 14)
    GUICtrlSetCursor(-1, 0)
    GUICtrlSetColor(-1, 0x101010)
    GUICtrlSetBkColor(-1, -2)
    $kk += 1
    Next
    Next
    GUISetState(@SW_SHOW)
    _WinAPI_DeleteObject(GUICtrlSendMsg($idPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap))
    _WinAPI_RedrawWindow($GUI)
    EndFunc

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

    Func _Exit()
    For $kk = 0 To UBound($aBG) - 1
    _WinAPI_DeleteObject($aBG[$kk][1])
    Next
    _WinAPI_DeleteObject($hBitmap)
    _GDIPlus_Shutdown()
    Exit
    EndFunc

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

    Func Create_BgBitmap($iWidth, $iHeight, $iColor = 0x10FFFFFF)
    Local Const $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0)
    Local Const $hBitmap = $aResult[6]
    Local Const $hBrush = _GDIPlus_BrushCreateSolid($iColor)
    Local Const $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsFillRect($hContext, 0, 0, $iWidth, $iHeight, $hBrush)
    _GDIPlus_GraphicsDispose($hContext)
    _GDIPlus_BrushDispose($hBrush)
    Return _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    EndFunc

    [/autoit]


    Ist nicht perfekt, aber kannst ja dran schrauben! ;)

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

    2 Mal editiert, zuletzt von UEZ (5. Oktober 2011 um 21:57)

  • Also UEZ, Du hast Dir echt viel Mühe gegeben damit, war sicherlich kein Leichtes, vielen Dank für Deine Hilfe :)
    Sieht wirklich gut aus, wenn auch durch GDI für mich leider zu schwierig, aber werds super verwenden können, Dankeschön.

    Grüße, Andy :)