Jump to content

Transparent Background but whole window draggable


ircdirk
 Share

Recommended Posts

I have searched forum for this but did not found sollution.

I would like to have transparent background window but that whole window would be draggable. Now when you click in transparent zone of my window the parent window get click.

Thats my code that i have tested:

#Include <WindowsConstants.au3>
#Include <WinAPI.au3>

$Form1 = GUICreate("Form1", 200, 200, 663, 317, -1, BitOR($WS_EX_LAYERED,$WS_EX_TOOLWINDOW,$WS_EX_TOPMOST))
GUISetBkColor(0x0000F4)
_WinAPI_SetLayeredWindowAttributes($Form1, 0x0000F4)

GUISetState()

Do
    Sleep(10)
Until GUIGetMsg() = -3

 

Link to comment
Share on other sites

Wow, interesting.  The only somewhat elegant dragable GUI method I am aware of doesn't behave the same way with a layered, transparent window like yours.  Tricky.

Here is a kludgy hack, however, it does not reliably prevent interaction with windows beneath it.  Not a fan.

#Include <WindowsConstants.au3>
#Include <SendMessage.au3>
#include <GuiConstants.au3>
#include <Misc.au3>
#Include <WinAPI.au3>
#Include <Array.au3>

Local $hDLL = DllOpen("user32.dll")

Global $Form1 = GUICreate("Form1", 200, 200, 663, 317, -1, BitOR($WS_EX_LAYERED,$WS_EX_TOOLWINDOW,$WS_EX_TOPMOST))
GUISetBkColor(0x0000F4)
_WinAPI_SetLayeredWindowAttributes($Form1, 0x0000F4)

GUISetState()

Do
    Sleep(10)
    If _IsPressed("01", $hDLL) Then
        Local $aMousePos = MouseGetPos()
        Local $aWindowPos = WinGetPos($Form1)
        If $aMousePos[0] >= $aWindowPos[0] And $aMousePos <= $aWindowPos[0] + $aWindowPos[2] And _
            $aMousePos[1] >= $aWindowPos[1] And $aMousePos[1] <= $aWindowPos[1] + $aWindowPos[3] Then
            WinActivate($Form1)
            _WinDrag($aWindowPos[0]- $aMousePos[0], $aWindowPos[1] - $aMousePos[1])
        EndIf
    EndIf
Until GUIGetMsg() = -3

DllClose($hDLL)

Func _WinDrag($iXOffset, $iYOffset)
    While _IsPressed("01", $hDLL)
        WinMove($Form1, "", MouseGetPos(0) + $iXOffset, MouseGetPos(1) + $iYOffset)
        Sleep(10)
    WEnd
EndFunc

 

Edited by spudw2k
Link to comment
Share on other sites

but there are more examples, like this

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

Local $hGui = 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")
Local $idLayButt = GUICtrlCreateButton("Button", 10, 40, 40)
GUISetBkColor(0xABCDEF)
_WinAPI_SetLayeredWindowAttributes($hGui, 0x010101)
GUISetState(@SW_SHOW)

Local $hGuicontrol = GUICreate("ControlGUI", 300, 400, 100, 100)
Local $idCheckTrans = GUICtrlCreateCheckbox("Transparent color 0xABCDEF (Checked) Or 0x010101", 10, 10)
Local $idCheckBorder = GUICtrlCreateCheckbox("POPUP-Style", 10, 30)
GUICtrlCreateLabel("Transparency for Layered GUI", 10, 50)
Local $idSlTrans = GUICtrlCreateSlider(10, 70, 200, 30)
GUICtrlSetLimit($idSlTrans, 255, 0)
GUICtrlSetData(-1, 255)
GUISetState(@SW_SHOW)

While 1
    Local $aExtMsg = GUIGetMsg(1)
    Local $iMsg = $aExtMsg[0]
    Switch $aExtMsg[1]
        Case $hGuicontrol
            Select
                Case $iMsg = $GUI_EVENT_CLOSE
                    Exit
                Case $iMsg = $idCheckTrans Or $iMsg = $idSlTrans

                    ; Change Attributes of Trans-Color and Window Transparency

                    If BitAND(GUICtrlRead($idCheckTrans), $GUI_CHECKED) = $GUI_CHECKED Then
                        _WinAPI_SetLayeredWindowAttributes($hGui, 0xABCDEF, GUICtrlRead($idSlTrans))
                    Else
                        _WinAPI_SetLayeredWindowAttributes($hGui, 0x010101, GUICtrlRead($idSlTrans))
                    EndIf

                Case $iMsg = $idCheckBorder
                    If BitAND(GUICtrlRead($idCheckBorder), $GUI_CHECKED) = $GUI_CHECKED Then
                        GUISetStyle($WS_POPUP, -1, $hGui)
                    Else
                        GUISetStyle($GUI_SS_DEFAULT_GUI, -1, $hGui)
                    EndIf
            EndSelect
        Case $hGui
            Select
                Case $iMsg = $idLayButt
                    Local $iTransColor, $iAlpha
                    Local $iInfo = _WinAPI_GetLayeredWindowAttributes($hGui, $iTransColor, $iAlpha)
                    MsgBox($MB_SYSTEMMODAL, 'Layered GUI', "Button on layered Window Clicked" & @CRLF & "Information about this window: " & @CRLF & _
                            "Transparent Color: " & $iTransColor & @CRLF & _
                            "Alpha Value: " & $iAlpha & @CRLF & _
                            "LWA_COLORKEY: " & (BitAND($iInfo, $LWA_COLORKEY) = $LWA_COLORKEY) & @CRLF & _
                            "LWA_ALPHA: " & (BitAND($iInfo, $LWA_ALPHA) = $LWA_ALPHA))
                Case $iMsg = $GUI_EVENT_CLOSE
                    Exit MsgBox($MB_SYSTEMMODAL, '', "Close from Layered GUI")
            EndSelect
    EndSwitch
WEnd

 

another one

 

#include <GUIConstants.au3>
#include <windowsconstants.au3>

#region - GUI Create
Global $Topx = 300,$Topy = 400,$extMsg
Global $Plusx = 15, $Plusy = 70
Global $gui1 = GUICreate("Parent GUI", 300, 300, $Topx, $Topy)
GUISetFont(6)
GUICtrlCreatePic(@SystemDir & "\oobe\images\mslogo.jpg", 0, 0, 300, 300)

GUISetState()
;create layered window so we can have a transparent colour which will be applied to edit background as well as the window
Global $gui2 = GUICreate("child", 200, 250, $Topx + 15,$Topy + 70, $WS_POPUP, BitOR(0x2000000, $WS_EX_LAYERED));$WS_EX_COMPOSITED = 0x2000000
GUICtrlCreateEdit("", 0, 0, 200, 250)
GUICtrlSetFont(-1,16)
GUICtrlSetBkColor(-1, 0xABCDEF);set background to a special colour
$text = FileRead(@ScriptFullPath)
GUICtrlSetData(-1, $text)
_API_SetLayeredWindowAttributes($gui2,0xABCDEF,250);set special colour fully transparent
GUISetState()
winsetontop($gui2,'',1)
GUIRegisterMsg($WM_MOVE,"Follow")
#endregion
WinSetTrans($gui1,"",120)

#region - GUI SelectLoop
While 1
    $extMsg = GUIGetMsg(1)
    $msg = $extMsg[0]
    Switch $extMsg[1]
        Case $gui1
            Select
                Case $msg = $GUI_EVENT_CLOSE
                    Exit

            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

Func Follow($hWnd)
    Local $wp = WinGetPos($gui1)
    If $hWnd = $gui1 then WinMove($gui2,"",$wp[0] + $Plusx, $wp[1] + $Plusy)

EndFunc

and one more, this one i like it too :)

you need _WinAPI_DwmEnableBlurBehindWindow10.au3

#include <GUIConstants.au3>

#include "_WinAPI_DwmEnableBlurBehindWindow10.au3"

$hGUI = GUICreate("Windows 10 Blur", 300, 300)
GUISetBkColor(0x000000)

GUICtrlCreateButton("Hello, Windows 10!", 70, 135, 160, 30)
GUICtrlSetBkColor(-1, 0x000000)
GUICtrlSetColor(-1, 0xFFFFFF)

GUISetState()

_WinAPI_DwmEnableBlurBehindWindow10($hGUI)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

 

Link to comment
Share on other sites

I'm not sure if those meet the OP's requirements.  I think he wanted to be able to drag the window from anywhere in the GUI, not just the title bar.  I guess he can chime in with his input; but I appreciate more examples for him to look at.

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...