Jump to content

transparent background?


Recommended Posts

Is there a way to make the background of a gui itself transparent not just a control or winsettrans?

EDIT: nevermind solved.

Edited by EagleClaw

[quote name='PsaltyDS' post='635433' date='Jan 27 2009, 07:04 AM']Larry is a mass murderer?! It's always the quiet, clean cut, bald guys... [/quote]

Link to comment
Share on other sites

Is there a way to make the background of a gui itself transparent not just a control or winsettrans?

EDIT: nevermind solved.

Please post how for any other members that may search, so they can easily find the solution... :D Edited by Bert
Link to comment
Share on other sites

So, I will post an example from me:

#include <GUIConstants.au3>

#region - GUI Create
$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)
_API_SetLayeredWindowAttributes($gui,0x010101)
GUISetState()
$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()
#endregion

#region - GUI SelectLoop
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
                    
                    ; Change Attributes of Trans-Color and Window Transparency
                    
                    If BitAND(GUICtrlRead($checkTrans),$GUI_CHECKED) = $GUI_CHECKED Then
                        _API_SetLayeredWindowAttributes($gui,0xABCDEF,GUICtrlRead($slidTrans))
                    Else
                        _API_SetLayeredWindowAttributes($gui,0x010101,GUICtrlRead($slidTrans))
                    EndIf
                    
                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
                    MsgBox(0, '', "Button on layered Window Clicked")
                Case $msg = $GUI_EVENT_CLOSE
                    Exit MsgBox(0, '', "Close from Layered GUI")
            EndSelect
    EndSwitch
WEnd
#endregion


;===============================================================================
;
; 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
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

OOps :D Line 52 was wrong :D Corrected it.

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Thank you man. :D But in reality this is only one Funkction from MSDN.

I didn't understand, why a Layered Window only could be visible, if there was a Picture on it, so I searched MSDN :D

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...