Fragen zu transparenten Fenstern

  • Hallo.
    Bin auf das Beispiel zur Funktion _WinAPI_SetLayeredWindowAttributes gestoßen, welches mich verwirrt.

    Spoiler anzeigen
    [autoit]

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

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

    $gui = GUICreate("trans", 300, 400, -1, -1, -1, $WS_EX_LAYERED)
    GUICtrlCreateLabel("This is text on a transparent Layered GUI", 10, 10, 200, 20, -1, $GUI_WS_EX_PARENTDRAG)
    GUICtrlSetTip(-1, "Click label to drag layered window")
    $layButt = GUICtrlCreateButton("Button", 10, 40, 40)
    GUISetBkColor(0xABCDEF)
    _WinAPI_SetLayeredWindowAttributes($gui, 0x010101)
    GUISetState()

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

    $guicontrol = GUICreate("ControlGUI", 300, 400, 100, 100)
    $checkTrans = GUICtrlCreateCheckbox("Transparent color 0xABCDEF (Checked) Or 0x010101", 10, 10)
    $checkBorder = GUICtrlCreateCheckbox("POPUP-Style", 10, 30)
    GUICtrlCreateLabel("Transparency for Layered GUI", 10, 50)
    $slidTrans = GUICtrlCreateSlider(10, 70, 200, 30)
    GUICtrlSetLimit($slidTrans, 255, 0)
    GUICtrlSetData(-1, 255)
    GUISetState()

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

    While 1
    $extMsg = GUIGetMsg(1)
    $msg = $extMsg[0]
    Switch $extMsg[1]
    Case $guicontrol
    Select
    Case $msg = $GUI_EVENT_CLOSE
    Exit
    Case $msg = $checkTrans Or $msg = $slidTrans

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

    ; Change Attributes of Trans-Color and Window Transparency

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

    If BitAND(GUICtrlRead($checkTrans), $GUI_CHECKED) = $GUI_CHECKED Then
    _WinAPI_SetLayeredWindowAttributes($gui, 0xABCDEF, GUICtrlRead($slidTrans))
    Else
    _WinAPI_SetLayeredWindowAttributes($gui, 0x010101, GUICtrlRead($slidTrans))
    EndIf

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

    Case $msg = $checkBorder
    If BitAND(GUICtrlRead($checkBorder), $GUI_CHECKED) = $GUI_CHECKED Then
    GUISetStyle($WS_POPUP, -1, $gui)
    Else
    GUISetStyle($GUI_SS_DEFAULT_GUI, -1, $gui)
    EndIf
    EndSelect
    Case $gui
    Select
    Case $msg = $layButt
    Dim $transcolor, $alpha
    $info = _WinAPI_GetLayeredWindowAttributes($gui,$transcolor, $alpha)
    MsgBox(0, 'Layered GUI', "Button on layered Window Clicked" & @CRLF & "Information about this window: " & @CRLF & _
    "Transparent Color: " & $transcolor & @CRLF & _
    "Alpha Value: " & $alpha & @CRLF & _
    "LWA_COLORKEY: " & (BitAND($info,$LWA_COLORKEY)=$LWA_COLORKEY) & @CRLF & _
    "LWA_ALPHA: " & (BitAND($info,$LWA_ALPHA)=$LWA_ALPHA) )
    Case $msg = $GUI_EVENT_CLOSE
    Exit MsgBox(0, '', "Close from Layered GUI")
    EndSelect
    EndSwitch
    WEnd

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

    1. Frage: Wofür gibt es den Parameter $i_transcolor - Transparent color? Wofür ne Transparenzfarbe, entweder es ist transparent oder eben nicht... Außerdem: Warum habe ich, wenn die obere Checkbox nicht aktiviert ist, einen hellblauen Hintergrund, und nur wenn ich sie aktiviere, eine Transparenz?

    2. Frage: Man aktiviere die obere Checkbox im ControlGUI und hat, wenn möglich, keinen einfarbigen Desktophintergrund. Wenn man jetzt die Transparente GUI über verschiedene Hintergrundfarben schiebt, ist der Text teilweise gut, teilweise sehr schlecht lesbar, weil er quasi verpixelt. Warum passiert das? Wie kann man das verhindern?

    Das wärs erstmal, vielleicht kommt ja später noch mehr.

    Grüße.

  • Nein du musst davon augehen, dass es keiner weiß oder derjenige der es weiß diesen Thread noch nicht bemerkt hat ;).
    Das Problem ist, dass durch Anti-Aliasing die Farben der Pixel die deiner Meinung nach transparent sein sollten einen geringfügig anderen Farbton haben als 0xABCDEF.
    Es gibt bestimmt Möglichkeiten mit _WinAPI_UpdateLayeredWindow o. so, aber ich weiß nicht wie das mit den Controls einer GUI Funktioniert, da ich die Funktion bisher nur mit Bitmaps verwendet habe... :S

  • Mit den Parametern von _WinAPI_UpdateLayeredWindow komme ich nicht klar^^
    Gibt ja auch kein Beispiel dafür...

    Kann mir denn sonst keiner helfen? =O

    Mir würde es ja schon reichen, wenn mir jemand sagt, wie ich den Text so hinbekomme, dass er nicht mehr verpixelt.

  • Zitat


    Mir würde es ja schon reichen, wenn mir jemand sagt, wie ich den Text so hinbekomme, dass er nicht mehr verpixelt.


    Das geht aus dem von mir genannten Grund nicht mit deiner Methode, da sie nur exakt eine Farbe ohne Alpha Kanal (z.B.0xABDCEF) transparent schaltet...

  • Zitat

    Achso, ok. Geht es denn mit einer anderen Methode?


    Bestimmt, aber ich weiß leider nicht wie :D. Mit _WinAPI_UpdateLayeredWindow geht es vielleicht und ich kann dir sogar ein Beispiel geben wie man die Funktion verwenden kann, aber ich weiß nur wie man das z.B. mit Bitmaps (wie bei meinem GDI+ ToolTip) macht. Wie das mit dem gewöhlichen Fensterinhalt und seinen Controls geht weiß ich nicht. :(

  • Kannst mir gerne das Beispiel geben, schadet ja nicht =)

    Bin trotzdem weiterhin offen für andere Lösungen.

  • Hier mal ein Beispiel:

    Spoiler anzeigen
    [autoit]

    #include <GDIPlus.au3>
    #include <GUIConstants.au3>
    #include <WindowsConstants.au3>
    #include <WinAPI.au3>
    #include <Misc.au3>
    #include <Constants.au3>

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

    Opt("GUIOnEventMode", 1)

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

    HotKeySet("{ESC}", "_Exit")

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

    $vU32DLL = DllOpen("User32.dll")

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

    $iGUIColorBG = 0xFFFFFFFF
    $iGUIWidth = @DesktopWidth
    $iGUIHeight = @DesktopHeight

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

    $hWnd = GUICreate("Test", $iGUIWidth, $iGUIHeight, 0, 0, BitOR(0x80000000, 0x08000000), BitOR(0x00080000, 0x00000008, 0x00000080))
    GUISetState()

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

    _GDIPlus_Startup()

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

    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iGUIWidth, $iGUIHeight, $hGraphic)
    $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2)

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

    $hPen = _GDIPlus_PenCreate(0xFF000000, 2)

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

    $hDC = _WinAPI_GetDC($hWnd)
    $hCDC = _WinAPI_CreateCompatibleDC($hDC)

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

    $tSize = DllStructCreate($tagSIZE)
    $pSize = DllStructGetPtr($tSize)
    DllStructSetData($tSize, "X", $iGUIWidth)
    DllStructSetData($tSize, "Y", $iGUIHeight)
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", 255)
    DllStructSetData($tBlend, "Format", 1)
    $tPoint = DllStructCreate($tagPOINT)
    $pPoint = DllStructGetPtr($tPoint)
    DllStructSetData($tPoint, "X", 0)
    DllStructSetData($tPoint, "Y", 0)

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

    GUIRegisterMsg($WM_PAINT, "_ReDraw")
    $aMousePosOld = MouseGetPos()

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

    While True
    $aMousePosNew = MouseGetPos()
    If _IsPressed("10", $vU32DLL) Then
    If $aMousePosOld[0] <> $aMousePosNew[0] Or $aMousePosOld[1] <> $aMousePosNew[1] Then _GDIPlus_GraphicsDrawLine($hBuffer, $aMousePosOld[0], $aMousePosOld[1], $aMousePosNew[0], $aMousePosNew[1], $hPen)
    _ReDraw()
    EndIf
    If BitOR(WinGetState($hWnd), 2) <> 2 Then _WinAPI_SetWindowPos($hWnd, $HWND_TOPMOST, 0, 0, 0, 0, BitOR($SWP_NOMOVE, $SWP_NOSIZE))
    $aMousePosOld = $aMousePosNew
    WEnd

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

    Func _ReDraw()
    Local $hBitmapTmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    _WinAPI_SelectObject($hCDC, $hBitmapTmp)
    _WinAPI_UpdateLayeredWindow($hWnd, $hDC, 0, $pSize, $hCDC, $pSource, 0, $pBlend, 2)
    _WinAPI_DeleteObject($hBitmapTmp)
    EndFunc

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

    Func _Exit()
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_GraphicsDispose($hBuffer)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_Shutdown()
    DllClose($vU32DLL)
    Exit
    EndFunc

    [/autoit]


    Shift gedrückt halten, um mit der Maus auf den Bildschirm zu malen. Mit Escape kannst du das ganze beenden ;). Ich hoffe es ist verständlich geschrieben, falls nicht gibt es hier auch noch ein paar andere Scripts die mit dieser Funktion arbeiten z.B. die MouseChaser UDF von H112... Einfach die Forensuche benutzen.

  • Danke vielmals. Durch dein Beispiel bin ich auf die Idee gekommen, den String mit GDI+ zu zeichnen, als per DrawStringEx:

    Spoiler anzeigen
    [autoit]

    #include <GDIPlus.au3>
    #include <GUIConstants.au3>
    #include <WindowsConstants.au3>
    #include <WinAPI.au3>
    #include <Misc.au3>
    #include <Constants.au3>

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

    Opt("GUIOnEventMode", 1)

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

    HotKeySet("{ESC}", "_Exit")

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

    $iGUIWidth = 200
    $iGUIHeight = 50

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

    $hWnd = GUICreate("Test", $iGUIHeight, 50, 0, 0, -1, BitOR(0x00080000, 0x00000080));0x80000000
    GUISetState()

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

    _GDIPlus_Startup()

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

    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iGUIWidth, $iGUIHeight, $hGraphic)
    $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2)

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

    $hPen = _GDIPlus_PenCreate(0xFF000000, 2)

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

    $hDC = _WinAPI_GetDC($hWnd)
    $hCDC = _WinAPI_CreateCompatibleDC($hDC)

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

    $tSize = DllStructCreate($tagSIZE)
    $pSize = DllStructGetPtr($tSize)
    DllStructSetData($tSize, "X", $iGUIWidth)
    DllStructSetData($tSize, "Y", $iGUIHeight)
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", 255)
    DllStructSetData($tBlend, "Format", 1)
    $tPoint = DllStructCreate($tagPOINT)
    $pPoint = DllStructGetPtr($tPoint)
    DllStructSetData($tPoint, "X", 0)
    DllStructSetData($tPoint, "Y", 0)

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

    $hBrush = _GDIPlus_BrushCreateSolid (0xFFFBF3FE)
    $hFormat = _GDIPlus_StringFormatCreate ()
    $hFamily = _GDIPlus_FontFamilyCreate ("Arial")
    $hFont = _GDIPlus_FontCreate ($hFamily, 12)
    $tLayout = _GDIPlus_RectFCreate (0, 0, 0, 0)

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

    $i = 1

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

    While True
    _GDIPlus_GraphicsDrawStringEx($hBuffer, $i, $hFont, $tLayout, $hFormat, $hBrush)
    $hBitmapTmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    _WinAPI_SelectObject($hCDC, $hBitmapTmp)
    _WinAPI_UpdateLayeredWindow($hWnd, $hDC, 0, $pSize, $hCDC, $pSource, 0, $pBlend, 2)
    _WinAPI_DeleteObject($hBitmapTmp)
    ;_ReDraw()
    Sleep(1000)
    $i += 1
    WEnd

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

    Func _Exit()
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_GraphicsDispose($hBuffer)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_Shutdown()
    Exit
    EndFunc

    [/autoit]

    Der Text ist überall gut lesbar. Jetzt gibt es aber noch 2 Probleme:
    1. Die alten Zahlen sollen verschwinden, also es soll ur die aktuelle sichtbar sein (GraphicsClear geht ja nicht, Transparenz geht flöten).
    2. Text soll rechtsbündig sein (Fenster hat ja eine Breite von 200px).

    MfG

    Einmal editiert, zuletzt von NoName (29. Dezember 2010 um 20:40)

  • Klar geht GraphicsClear ;). Und mit GraphicsMeasureString kannst du die Stringbreite messen und diesen von der Fensterbreite subtrahieren um die X Koordinate zu erhalten.

    Spoiler anzeigen
    [autoit]

    #include <GDIPlus.au3>
    #include <GUIConstants.au3>
    #include <WindowsConstants.au3>
    #include <WinAPI.au3>
    #include <Misc.au3>
    #include <Constants.au3>

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

    Opt("GUIOnEventMode", 1)

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

    HotKeySet("{ESC}", "_Exit")

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

    $iGUIWidth = 200
    $iGUIHeight = 50

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

    $hWnd = GUICreate("Test", $iGUIHeight, 50, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOOLWINDOW))
    GUISetState()

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

    _GDIPlus_Startup()

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

    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iGUIWidth, $iGUIHeight, $hGraphic)
    $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2)

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

    $hPen = _GDIPlus_PenCreate(0xFF000000, 2)

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

    $hDC = _WinAPI_GetDC($hWnd)
    $hCDC = _WinAPI_CreateCompatibleDC($hDC)

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

    $tSize = DllStructCreate($tagSIZE)
    $pSize = DllStructGetPtr($tSize)
    DllStructSetData($tSize, "X", $iGUIWidth)
    DllStructSetData($tSize, "Y", $iGUIHeight)
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", 255)
    DllStructSetData($tBlend, "Format", 1)
    $tPoint = DllStructCreate($tagPOINT)
    $pPoint = DllStructGetPtr($tPoint)
    DllStructSetData($tPoint, "X", 0)
    DllStructSetData($tPoint, "Y", 0)

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

    $hBrush = _GDIPlus_BrushCreateSolid(0xFFFBF3FE)
    $hFormat = _GDIPlus_StringFormatCreate()
    $hFamily = _GDIPlus_FontFamilyCreate("Arial")
    $hFont = _GDIPlus_FontCreate($hFamily, 12)
    $tLayout = _GDIPlus_RectFCreate()

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

    $i = 1

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

    While Sleep(1000)
    _GDIPlus_GraphicsClear($hBuffer, 0x00000000)
    $aMeasure = _GDIPlus_GraphicsMeasureString($hBuffer, $i, $hFont, $tLayout, $hFormat)
    DllStructSetData($aMeasure[0], "X", $iGUIWidth - DllStructGetData($aMeasure[0], "Width"))
    _GDIPlus_GraphicsDrawStringEx($hBuffer, $i, $hFont, $aMeasure[0], $hFormat, $hBrush)

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

    $hBitmapTmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)

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

    _WinAPI_SelectObject($hCDC, $hBitmapTmp)
    _WinAPI_UpdateLayeredWindow($hWnd, $hDC, 0, $pSize, $hCDC, $pSource, 0, $pBlend, 2)
    _WinAPI_DeleteObject($hBitmapTmp)

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

    $i += 1
    WEnd

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

    Func _Exit()
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_GraphicsDispose($hBuffer)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_Shutdown()
    _WinAPI_ReleaseDC($hWnd, $hDC)
    _WinAPI_DeleteDC($hCDC)
    Exit
    EndFunc

    [/autoit]


    Du hast vergessen den Brush etc. wieder aus dem Speicher zu entfernen (BrushDispose)...

  • Was soll ich sagen, vielen Dank =D

    Werde jetzt ein paar Tests machen und mein eigentliches Vorhaben umsetzen. Falls ich wieder Probleme bekomme, melde ich mich, deshalb lasse ich den Präfix offen erstmal stehen.

    MfG

    Edit: Von wegen... Genauso verpixelt.

    Spoiler anzeigen
    [autoit]

    #include <GDIPlus.au3>
    #include <GUIConstants.au3>
    #include <WindowsConstants.au3>
    #include <WinAPI.au3>
    #include <Misc.au3>
    #include <Constants.au3>

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

    HotKeySet("{ESC}", "_Exit")

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

    ;Höhe der Taskleiste bestimmen
    $hTask = WinList("[CLASS:Shell_TrayWnd]")
    $hTaskPos = ControlGetPos($hTask[1][1], "", "MSTaskListWClass1")
    If IsArray($hTaskPos) Then
    $vHoeheTaskleiste = $hTaskPos[3]
    Else
    $vHoeheTaskleiste = 40
    EndIf

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

    Dim $vDesktopWidth = -1, $vDesktopHeight = -1, $vGUIWidth = 50, $vGUIHeight = 20, $vGUILeft = 0, $vGUITop = 0
    Dim $hGUI, $vOldPixelColor, $vTextgroesse = 12

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

    $hWnd = GUICreate("Test", $vGUIWidth, $vGUIHeight, $vGUILeft, $vGUITop, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
    GUISetState()

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

    _GDIPlus_Startup()

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

    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($vGUIWidth, $vGUIHeight, $hGraphic)
    $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2)

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

    $hPen = _GDIPlus_PenCreate(0xFF000000, 2)

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

    $hDC = _WinAPI_GetDC($hWnd)
    $hCDC = _WinAPI_CreateCompatibleDC($hDC)

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

    $tSize = DllStructCreate($tagSIZE)
    $pSize = DllStructGetPtr($tSize)
    DllStructSetData($tSize, "X", $vGUIWidth)
    DllStructSetData($tSize, "Y", $vGUIHeight)
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", 255)
    DllStructSetData($tBlend, "Format", 1)
    $tPoint = DllStructCreate($tagPOINT)
    $pPoint = DllStructGetPtr($tPoint)
    DllStructSetData($tPoint, "X", 0)
    DllStructSetData($tPoint, "Y", 0)

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

    AdlibRegister("_Check_Color", 500)
    AdlibRegister("_Check_Resolution", 100)

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

    $i = 1

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

    While Sleep(1000)

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

    $hBrush = _GDIPlus_BrushCreateSolid(BitOR(0xFF000000, "0x" & Hex(0xFFFFFF-$vOldPixelColor, 6)))
    $hFormat = _GDIPlus_StringFormatCreate()
    $hFamily = _GDIPlus_FontFamilyCreate("Arial")
    $hFont = _GDIPlus_FontCreate($hFamily, $vTextgroesse)
    $tLayout = _GDIPlus_RectFCreate()

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

    _GDIPlus_GraphicsClear($hBuffer, 0x00000000)
    $aMeasure = _GDIPlus_GraphicsMeasureString($hBuffer, $i, $hFont, $tLayout, $hFormat)
    DllStructSetData($aMeasure[0], "X", $vGUIWidth - DllStructGetData($aMeasure[0], "Width"))
    _GDIPlus_GraphicsDrawStringEx($hBuffer, $i, $hFont, $aMeasure[0], $hFormat, $hBrush)

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

    $hBitmapTmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)

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

    _WinAPI_SelectObject($hCDC, $hBitmapTmp)
    _WinAPI_UpdateLayeredWindow($hWnd, $hDC, 0, $pSize, $hCDC, $pSource, 0, $pBlend, 2)
    _WinAPI_DeleteObject($hBitmapTmp)

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

    $i += 1
    WEnd

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

    Func _Check_Color()
    $vNewPixelColor = PixelGetColor($vGUILeft + $vGUIWidth, $vGUITop - 1)

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

    If $vNewPixelColor <> $vOldPixelColor Then
    $vOldPixelColor = $vNewPixelColor
    EndIf
    EndFunc

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

    Func _Check_Resolution()
    If $vDesktopWidth <> @DesktopWidth Or $vDesktopHeight <> @DesktopHeight Then
    $vDesktopWidth = @DesktopWidth
    $vDesktopHeight = @DesktopHeight

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

    $vGUILeft = $vDesktopWidth - 4 * $vTextgroesse - 10
    $vGUITop = $vDesktopHeight - $vHoeheTaskleiste - 2 * $vTextgroesse
    $vGUIWidth = 4 * $vTextgroesse
    $vGUIHeight = 2 * $vTextgroesse

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

    WinMove($hGUI, "", $vGUILeft, $vGUITop, $vGUIWidth, $vGUIHeight)
    EndIf
    EndFunc

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

    Func _Exit()
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_GraphicsDispose($hBuffer)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_Shutdown()
    _WinAPI_ReleaseDC($hWnd, $hDC)
    _WinAPI_DeleteDC($hCDC)
    Exit
    EndFunc

    [/autoit]


    Unten rechts über der Taskleiste sollte der Counter jetzt sein. Wenn man jetzt http://www.farbtabelle.net öffnet und die verschiedenen Farbfelder hinter den Counter setzt, verändert sich die Farbe des Counters (soll sich automatisch anpassen), bei einigen Hintergrundfarben ziemlich verpixelt.

    2 Mal editiert, zuletzt von NoName (29. Dezember 2010 um 21:25)

  • Hatte dasselbe Problem und hab inzwischen ein paar Funktionen geschrieben, mit denen es möglich wäre. Ist allergings sehr langsam.
    Also, falls jemand Lust auf's optimieren hat...

    Im Grunde funktioniert es so:
    1. Man zeichnet einen String (weiß) in ein undurchsichtiges schwarzes hBitmap.
    2. Man erstellt ein hBitmap der selben Größe und färbt es beliebig ein.
    3. Man übergibt beide hBitmaps der Funktion _GDIPlus_BitmapSetAlpha, der String ist der Alpha-Kanal

    Spoiler anzeigen

    #include <GDIPlus.au3>

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _GDIPlus_BitmapSetAlpha
    ; Description ...: Gives a new Alpha-channal to the bitmap
    ; Syntax.........: _GDIPlus_BitmapSetAlpha($hBitmap, $hAlpha)
    ; Parameters ....: $hBitmap - Handle to a bitmap object
    ; $hAlpha - Handle to a bitmap object with the same width and height as $hBitmap
    ; Return values .: Success - Handle to a new bitmap object
    ; Failure - Handle to an empty bitmap object
    ; Author ........: 5tewurzel
    ; Modified.......:
    ; Remarks .......:
    ; Related .......:
    ; Link ..........:
    ; Example .......: No
    ; ===============================================================================================================================
    Func _GDIPlus_BitmapSetAlpha( $hBitmap, $hAlpha )
    Local $iWidth = _GDIPlus_ImageGetWidth( $hBitmap )
    Local $iHeight = _GDIPlus_ImageGetHeight( $hBitmap )
    Local $hReturn = _GDIPlus_BitmapCreateFromScan0( $iWidth, $iHeight )
    Local $iX, $iY, $iColor, $iAlpha
    For $iY = 0 To $iHeight - 1
    For $iX = 0 To $iWidth - 1
    $iColor = _GDIPlus_BitmapGetPixel( $hBitmap, $iX, $iY )
    $iAlpha = ColorGetBW( _GDIPlus_BitmapGetPixel( $hAlpha, $iX, $iY ), 0 )
    _GDIPlus_BitmapSetPixel( $hReturn, $iX, $iY, MultiplyAlpha( $iColor, $iAlpha ) )
    Next
    Next
    Return $hReturn
    EndFunc

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _GDIPlus_BitmapGetPixel
    ; Description ...: Gets the color of a pixel
    ; Syntax.........: _GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY)
    ; Parameters ....: $hBitmap - Handle to a bitmap object
    ; $iX - The x-coordinates of the pixel
    ; $iY - The y-coordinates of the pixel
    ; Return values .: Success - The color of the pixel
    ; Failure - 0
    ; Author ........: 5tewurzel
    ; Modified.......:
    ; Remarks .......:
    ; Related .......: @@MsdnLink@@ GdipBitmapGetPixel
    ; Link ..........:
    ; Example .......: No
    ; ===============================================================================================================================
    Func _GDIPlus_BitmapGetPixel( $hBitmap, $iX, $iY )
    Local $Color, $aResult
    $aResult = DllCall( $ghGDIPDll, "uint", "GdipBitmapGetPixel", "handle", $hBitmap, "int", $iX, "int", $iY, "uint*", $Color )
    Return $aResult[4]
    EndFunc

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _GDIPlus_BitmapSetPixel
    ; Description ...: Sets the color of a pixel
    ; Syntax.........: _GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY)
    ; Parameters ....: $hBitmap - Handle to a bitmap object
    ; $iX - The x-coordinates of the pixel
    ; $iY - The y-coordinates of the pixel
    ; Return values .:
    ; Author ........: 5tewurzel
    ; Modified.......:
    ; Remarks .......:
    ; Related .......: @@MsdnLink@@ GdipBitmapSetPixel
    ; Link ..........:
    ; Example .......: No
    ; ===============================================================================================================================
    Func _GDIPlus_BitmapSetPixel( $hBitmap, $iX, $iY, $Color )
    Local $aResult
    $aResult = DllCall( $ghGDIPDll, "uint", "GdipBitmapSetPixel", "handle", $hBitmap, "int", $iX, "int", $iY, "uint", $Color )
    EndFunc

    Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0); Erstellt leere Bitmap mit Alphakanal
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[6]
    EndFunc ;==>_GDIPlus_BitmapCreateFromScan0

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: MultiplyAlpha
    ; Description ...: Multiplies an alpha value to a color
    ; Syntax.........: MultiplyAlpha($iColor, $iAlpha)
    ; Parameters ....: $iColor - Alpha, Red, Green and Blue components of color
    ; $iAlpha - Only Alpha component (or integer in renge of 0 to 255
    ; Return values .: Success - The color with the new Alpha component
    ; Author ........: 5tewurzel
    ; Modified.......:
    ; Remarks .......:
    ; Related .......:
    ; Link ..........:
    ; Example .......: No
    ; ===============================================================================================================================
    Func MultiplyAlpha( $iColor, $iAlpha )
    Local $aReturn[4];ARGB
    $aReturn[3] = BitAND( $iColor , 0xff )
    $aReturn[2] = BitAND( BitShift( $iColor, 8 ), 0xff )
    $aReturn[1] = BitAND( BitShift( $iColor, 16 ), 0xff )
    $aReturn[0] = BitAND( BitShift( $iColor, 24 ), 0xff )
    $iAlpha = $aReturn[0] * $iAlpha / 255
    Return BitOR( BitShift( $iAlpha, -24 ), BitShift( $aReturn[1], -16 ), BitShift( $aReturn[2], -8 ), $aReturn[3] )
    EndFunc

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: ColorGetBW
    ; Description ...: Converts a color to BW
    ; Syntax.........: ColorGetBW($iColor, $Methode)
    ; Parameters ....: $iColor - (Alpha,) Red, Green and Blue components of color
    ; $Methode - How the BW will be calculated
    ; 0 = Brightness
    ; 1 = Luminosity
    ; 2 = Both
    ; Return values .: Success - The value for the Red, Green and Blue components of color
    ; Author ........: 5tewurzel
    ; Modified.......:
    ; Remarks .......:
    ; Related .......:
    ; Link ..........:
    ; Example .......: No
    ; ===============================================================================================================================
    Func ColorGetBW( $iColor, $Methode )
    Local $iBW, $aReturn[4];ARGB
    $aReturn[3] = BitAND( $iColor , 0xff )
    $aReturn[2] = BitAND( BitShift( $iColor, 8 ), 0xff )
    $aReturn[1] = BitAND( BitShift( $iColor, 16 ), 0xff )
    $aReturn[0] = BitAND( BitShift( $iColor, 24 ), 0xff )
    Switch $Methode
    Case 0
    $iBW = ($aReturn[1] + $aReturn[2] + $aReturn[3]) / 3
    Case 1
    $iBW = ($aReturn[1] * 54 + $aReturn[2] * 182 + $aReturn[3] * 18) / 254
    Case 2
    $iBW = (($aReturn[1] + $aReturn[2] + $aReturn[3]) / 3 + ($aReturn[1] * 54 + $aReturn[2] * 182 + $aReturn[3] * 18) / 254) / 2
    EndSwitch
    Return $iBW
    EndFunc

    Oh, mist. Da hab ich ja schon fast so viel abgeschrieben, wie der Guttenb.... Weiß leider nur noch, das ich _GDIPlus_BitmapCreateFromScan0 aus dem TidyURLDownloader habe.