Jump to content

Trasperent GUI, And Buton


slaughter
 Share

Recommended Posts

Problem: I am using this UDF ( http://www.autoitscript.com/forum/index.php?showtopic=47651 ), And I have made an image Posted Image and aplayed my gui, But the control buttons looks ugly a bit. So I mage butons on bacgruond image. you shuld see thm as Licenzija : Darbuotojai : Pastabos ( Left top corner ), So how to make them active? not creating another butons?

I tryed to make

;~ $Button_3 = GUICtrlCreateButton ("Licenzija", 10, 10, 130)

$Button_3 = GUICtrlCreatePic("empty.png", 10, 10, 10, 130)

like this. Make transperent png image. Didint work it looks that buton is allways pressd down nad popups window asinget to buton.....

Link to comment
Share on other sites

Hello!

You should find what you need in this nice code done by Prog@ndy

CODE
#include <GUIConstants.au3>

#include <Constants.au3>

#include <WindowsConstants.au3>

#include <WINAPI.au3>

;############# Constants ##########

Global Const $LWA_ALPHA = 0x2

Global Const $LWA_COLORKEY = 0x1

;############# Example ############

#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)

_WinAPI_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 - GUI Create

#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

_WinAPI_SetLayeredWindowAttributes($gui, 0xABCDEF, GUICtrlRead($slidTrans))

Else

_WinAPI_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

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

#EndRegion - GUI SelectLoop

;############# EndExample #########

;===============================================================================

;

; Function Name: _WinAPI_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( 0x00bbggrr ), 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

;

; Link : @@MsdnLink@@ SetLayeredWindowAttributes

; Example : Yes

;===============================================================================

;

Func _WinAPI_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency = 255, $dwFlages = 0x03, $isColorRef = False)

If $dwFlages = Default Or $dwFlages = "" Or $dwFlages < 0 Then $dwFlages = 0x03

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", $dwFlages)

Select

Case @error

Return SetError(@error, 0, 0)

Case $Ret[0] = 0

Return SetError(4, _WinAPI_GetLastError(), 0)

Case Else

Return 1

EndSelect

EndFunc ;==>_WinAPI_SetLayeredWindowAttributes

;===============================================================================

;

; Function Name: _WinAPI_GetLayeredWindowAttributes

; Description:: Gets Layered Window Attributes:) See MSDN for more informaion

; Parameter(s):

; $hwnd - Handle of GUI to work on

; $i_transcolor - Returns Transparent color ( dword as 0x00bbggrr or string "0xRRGGBB")

; $Transparency - Returns Transparancy of GUI

; $isColorRef - If True, $i_transcolor will be a COLORREF( 0x00bbggrr ), else an RGB-Color

; Requirement(s): Layered Windows

; Return Value(s): Success: Usage of LWA_ALPHA and LWA_COLORKEY (use BitAnd)

; 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

; - @extended contains _WinAPI_GetLastError

; Author(s): Prog@ndy

;

; Link : @@MsdnLink@@ GetLayeredWindowAttributes

; Example : Yes

;===============================================================================

;

Func _WinAPI_GetLayeredWindowAttributes($hwnd, ByRef $i_transcolor, ByRef $Transparency,$asColorRef = False)

$i_transcolor = -1

$Transparency = -1

Local $Ret = DllCall("user32.dll", "int", "GetLayeredWindowAttributes", "hwnd", $hwnd, "long*", $i_transcolor, "byte*", $Transparency, "long*", 0)

Select

Case @error

Return SetError(@error, 0, 0)

Case $Ret[0] = 0

Return SetError(4, _WinAPI_GetLastError(), 0)

Case Else

If Not $asColorRef Then

$Ret[2] = Hex(String($Ret[2]), 6)

$Ret[2] = '0x' & StringMid($Ret[2], 5, 2) & StringMid($Ret[2], 3, 2) & StringMid($Ret[2], 1, 2)

EndIf

$i_transcolor = $Ret[2]

$Transparency = $Ret[3]

Return $Ret[4]

EndSelect

EndFunc ;==>_WinAPI_GetLayeredWindowAttributes

Link to comment
Share on other sites

Hello!

You should find what you need in this nice code done by Prog@ndy

CODE
#include <GUIConstants.au3>

#include <Constants.au3>

#include <WindowsConstants.au3>

#include <WINAPI.au3>

;############# Constants ##########

Global Const $LWA_ALPHA = 0x2

Global Const $LWA_COLORKEY = 0x1

;############# Example ############

#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)

_WinAPI_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 - GUI Create

#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

_WinAPI_SetLayeredWindowAttributes($gui, 0xABCDEF, GUICtrlRead($slidTrans))

Else

_WinAPI_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

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

#EndRegion - GUI SelectLoop

;############# EndExample #########

;===============================================================================

;

; Function Name: _WinAPI_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( 0x00bbggrr ), 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

;

; Link : @@MsdnLink@@ SetLayeredWindowAttributes

; Example : Yes

;===============================================================================

;

Func _WinAPI_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency = 255, $dwFlages = 0x03, $isColorRef = False)

If $dwFlages = Default Or $dwFlages = "" Or $dwFlages < 0 Then $dwFlages = 0x03

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", $dwFlages)

Select

Case @error

Return SetError(@error, 0, 0)

Case $Ret[0] = 0

Return SetError(4, _WinAPI_GetLastError(), 0)

Case Else

Return 1

EndSelect

EndFunc ;==>_WinAPI_SetLayeredWindowAttributes

;===============================================================================

;

; Function Name: _WinAPI_GetLayeredWindowAttributes

; Description:: Gets Layered Window Attributes:) See MSDN for more informaion

; Parameter(s):

; $hwnd - Handle of GUI to work on

; $i_transcolor - Returns Transparent color ( dword as 0x00bbggrr or string "0xRRGGBB")

; $Transparency - Returns Transparancy of GUI

; $isColorRef - If True, $i_transcolor will be a COLORREF( 0x00bbggrr ), else an RGB-Color

; Requirement(s): Layered Windows

; Return Value(s): Success: Usage of LWA_ALPHA and LWA_COLORKEY (use BitAnd)

; 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

; - @extended contains _WinAPI_GetLastError

; Author(s): Prog@ndy

;

; Link : @@MsdnLink@@ GetLayeredWindowAttributes

; Example : Yes

;===============================================================================

;

Func _WinAPI_GetLayeredWindowAttributes($hwnd, ByRef $i_transcolor, ByRef $Transparency,$asColorRef = False)

$i_transcolor = -1

$Transparency = -1

Local $Ret = DllCall("user32.dll", "int", "GetLayeredWindowAttributes", "hwnd", $hwnd, "long*", $i_transcolor, "byte*", $Transparency, "long*", 0)

Select

Case @error

Return SetError(@error, 0, 0)

Case $Ret[0] = 0

Return SetError(4, _WinAPI_GetLastError(), 0)

Case Else

If Not $asColorRef Then

$Ret[2] = Hex(String($Ret[2]), 6)

$Ret[2] = '0x' & StringMid($Ret[2], 5, 2) & StringMid($Ret[2], 3, 2) & StringMid($Ret[2], 1, 2)

EndIf

$i_transcolor = $Ret[2]

$Transparency = $Ret[3]

Return $Ret[4]

EndSelect

EndFunc ;==>_WinAPI_GetLayeredWindowAttributes

Will try thanks ;)
Link to comment
Share on other sites

Didint worked.... :/ This makes all window trasperent.... I nead to make one button, or some how set cords for some tekst to make it as button... :/

Link to comment
Share on other sites

slaughter

Hi. Maybe this helped you?

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

Global $Draw = False
Global $aCurPos

$hGUI = GUICreate("My GUI", 300, 200)

$pic = GUICtrlCreatePic(@WindowsDir & "\Web\Wallpaper\Windows XP.jpg", 0, 0, 300, 200)
GUICtrlSetState(-1, $GUI_DISABLE)

$button = GUICtrlCreateLabel("Test", 100, 65, 100, 25, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)

GUICtrlCreateGroup("", -99, -99, 1, 1)

GUISetState()

FrameRect1(GUICtrlGetHandle($button), 0xFFFFFF)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $button
            MsgBox(0, "Info", "Button pressed", 0, $hGUI)
    EndSwitch
    
    $aCurPos = GUIGetCursorInfo()
    If IsArray($aCurPos) Then
        If ($aCurPos[4] = $button) And ($Draw = False) Then
            $Draw = True
            GUICtrlSetFont($button, 10, 800)
            FrameRect1(GUICtrlGetHandle($button), 0x000000)
        ElseIf ($aCurPos[4] <> $button) And ($Draw = True) Then
            $Draw = False
            GUICtrlSetFont($button, Default, Default)
            FrameRect1(GUICtrlGetHandle($button), 0xFFFFFF)
        EndIf
    EndIf
WEnd

Func FrameRect1($hWnd, $sColor)
    Local $hDC = _WinAPI_GetDC($hWnd)
    Local $tRect = _WinAPI_GetClientRect($hWnd)
    Local $hBrush = _WinAPI_CreateSolidBrush($sColor)
    
    DllCall("user32.dll", "int", "FrameRect", "hwnd", $hDC, "ptr", DllStructGetPtr($tRect), "hwnd", $hBrush)
    
    _WinAPI_ReleaseDC($hWnd, $hDC)
    _WinAPI_DeleteObject($hBrush)
EndFunc
Link to comment
Share on other sites

slaughter

Hi. Maybe this helped you?

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

Global $Draw = False
Global $aCurPos

$hGUI = GUICreate("My GUI", 300, 200)

$pic = GUICtrlCreatePic(@WindowsDir & "\Web\Wallpaper\Windows XP.jpg", 0, 0, 300, 200)
GUICtrlSetState(-1, $GUI_DISABLE)

$button = GUICtrlCreateLabel("Test", 100, 65, 100, 25, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)

GUICtrlCreateGroup("", -99, -99, 1, 1)

GUISetState()

FrameRect1(GUICtrlGetHandle($button), 0xFFFFFF)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $button
            MsgBox(0, "Info", "Button pressed", 0, $hGUI)
    EndSwitch
    
    $aCurPos = GUIGetCursorInfo()
    If IsArray($aCurPos) Then
        If ($aCurPos[4] = $button) And ($Draw = False) Then
            $Draw = True
            GUICtrlSetFont($button, 10, 800)
            FrameRect1(GUICtrlGetHandle($button), 0x000000)
        ElseIf ($aCurPos[4] <> $button) And ($Draw = True) Then
            $Draw = False
            GUICtrlSetFont($button, Default, Default)
            FrameRect1(GUICtrlGetHandle($button), 0xFFFFFF)
        EndIf
    EndIf
WEnd

Func FrameRect1($hWnd, $sColor)
    Local $hDC = _WinAPI_GetDC($hWnd)
    Local $tRect = _WinAPI_GetClientRect($hWnd)
    Local $hBrush = _WinAPI_CreateSolidBrush($sColor)
    
    DllCall("user32.dll", "int", "FrameRect", "hwnd", $hDC, "ptr", DllStructGetPtr($tRect), "hwnd", $hBrush)
    
    _WinAPI_ReleaseDC($hWnd, $hDC)
    _WinAPI_DeleteObject($hBrush)
EndFunc
Thanks
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...