Sign in to follow this  
Followers 0
RegiOween

Transparent Label always on top

3 posts in this topic

Hi, folks!

I'm trying to make a transparent label to appear "always on top" over applications, desktop area or even over screensaver if it's running, but it has strange behaviours: sometimes it appears, sometimes not. When it appears, sometimes it is totally transparent, sometimes parts transparent, and sometimes worst, background totally white. If I disable the transparency, the script works without any flaws.

I set the font to bright green to facilitate visualization, and define position to appear a little above the task bar. I believe this is a tough one :) , so here's the code:

#include <GUIConstants.au3>
$GUITITLE="Transparent Label"
$TITLE="Title test from creation of a transparent GUI label"
GUICreate($GUITITLE, @DeskTopWidth, 60, 0, @DesktopHeight-120, $WS_POPUP, $WS_EX_TRANSPARENT)
GUICtrlCreateLabel($TITLE, 5, 10, @DeskTopWidth, 35, $SS_CENTER+$SS_NOPREFIX)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetFont(-1, 22)
GUICtrlSetColor(-1, 0x00FF00)
GUISetState()
For $X = 1 to 500
    WinSetOnTop($GUITITLE, "", 1)
    Sleep(10)
Next
GUIDelete()

Thanks in advance,

Reginald0

Share this post


Link to post
Share on other sites



Hi, folks!

I'm trying to make a transparent label to appear "always on top" over applications, desktop area or even over screensaver if it's running, but it has strange behaviours: sometimes it appears, sometimes not. When it appears, sometimes it is totally transparent, sometimes parts transparent, and sometimes worst, background totally white. If I disable the transparency, the script works without any flaws.

I set the font to bright green to facilitate visualization, and define position to appear a little above the task bar. I believe this is a tough one :) , so here's the code:

#include <GUIConstants.au3>
$GUITITLE="Transparent Label"
$TITLE="Title test from creation of a transparent GUI label"
GUICreate($GUITITLE, @DeskTopWidth, 60, 0, @DesktopHeight-120, $WS_POPUP, $WS_EX_TRANSPARENT)
GUICtrlCreateLabel($TITLE, 5, 10, @DeskTopWidth, 35, $SS_CENTER+$SS_NOPREFIX)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetFont(-1, 22)
GUICtrlSetColor(-1, 0x00FF00)
GUISetState()
For $X = 1 to 500
    WinSetOnTop($GUITITLE, "", 1)
    Sleep(10)
Next
GUIDelete()

Thanks in advance,

Reginald0

Try this which is using a post by Prog@ndy

#include <GUIConstants.au3>
$GUITITLE = "Transparent Label"
$TITLE = "Title test from creation of a transparent GUI label"
$gui = GUICreate($GUITITLE, @DesktopWidth, 60, 0, @DesktopHeight - 120, $WS_POPUP, $WS_EX_LAYERED);, $WS_EX_TRANSPARENT)
GUISetBkColor(0xABCDEF);any colour as long as we use the same colour in the call to _API_SetLayeredWindowAttributes and it's not the font colour.
GUICtrlCreateLabel($TITLE, 5, 10, @DesktopWidth, 35, $SS_CENTER + $SS_NOPREFIX)
GUICtrlSetFont(-1, 22)
GUICtrlSetColor(-1, 0x00FF00)
_API_SetLayeredWindowAttributes($gui, 0xABCDEF)
GUISetState()
WinSetOnTop($GUITITLE, "", 1)
Sleep(10000)
GUIDelete()



;===============================================================================
;
; Function Name:   _API_SetLayeredWindowAttributes
; Description:: Sets Layered Window Attributes:) See MSDN for more informaion
; Parameter(s):
;                 $hwnd - Handle of GUI to work on
;                 $i_transcolor - Transparent color
;                 $Transparency - Set Transparancy of GUI
;                 $isColorRef - If True, $i_transcolor is a COLORREF-Strucure, else an RGB-Color
; Requirement(s):  Layered Windows
; Return Value(s): Success: 1
;                 Error: 0
;                  @error: 1 to 3 - Error from DllCall
;                  @error: 4 - Function did not succeed - use
;                              _WinAPI_GetLastErrorMessage or _WinAPI_GetLastError to get more information
; Author(s):       Prog@ndy
;
;===============================================================================
;
Func _API_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency = 255, $isColorRef = False)

    Local Const $AC_SRC_ALPHA = 1
    Local Const $ULW_ALPHA = 2
    Local Const $LWA_ALPHA = 0x2
    Local Const $LWA_COLORKEY = 0x1
    If Not $isColorRef Then
        $i_transcolor = Hex(String($i_transcolor), 6)
        $i_transcolor = Execute('0x00' & StringMid($i_transcolor, 5, 2) & StringMid($i_transcolor, 3, 2) & StringMid($i_transcolor, 1, 2))
    EndIf
    Local $Ret = DllCall("user32.dll", "int", "SetLayeredWindowAttributes", "hwnd", $hwnd, "long", $i_transcolor, "byte", $Transparency, "long", $LWA_COLORKEY + $LWA_ALPHA)
    Select
        Case @error
            Return SetError(@error, 0, 0)
        Case $Ret[0] = 0
            Return SetError(4, 0, 0)
        Case Else
            Return 1
    EndSelect
EndFunc  ;==>_API_SetLayeredWindowAttributes

I liked the word "aleatory", I didn't know that one- thanks.


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

Martin, this did the trick flawlessly! The more I see experts like you and Prog@ndy, more I feel like a newbie... I was searching a solution for a few hours before post, but didn't go to the right way.

This remember me an old saying in my country (Brazil), it's something like: "You don't have to know to do the things when you know where the things are..."

Thanks a lot!

Reginald0

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