Jump to content
Sign in to follow this  

[DEMO] Transparrent Controls on Child Windows

Recommended Posts


Someone else did something similar but for the life of me I can not find the original post. When / if I do I'll post credit here.

EDIT: Found it!! _GuiCtrlMakeTrans

The original post displayed a form with controls on it that was translucent. I wanted to do the same on a child form but his original code caused the controls to offset from their original positions. Apparently it's an issue with setting up a border less parent window. The child windows client area is not updated and it wants to stay at, using a pseudocode reference, ParentLeft + WindowFrameThickness and ParrentTop + CationBarHeight + WindowFrameThickness.

This might be an AutoIt bug or a windows bug, either way... annoying. If it is an AutoIt bug, it remained in the BETA as well as I also tried it there. /Sigh this is sounding too much like a bug report....

Anyway here is my crappy demo :)

;## Zin's Transparrent Controls on MDI Demo

    #include <GuiConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <StaticConstants.au3>

    Const $AlphaMax = 240
    Const $AlphaMin = 10
    Const $AlphaInterval = 10

    Dim $AlphaSpeed = 5


    Dim $guiParrent = GUICreate("Sample GUI", 275, 0, Default, Default)



    Dim $guiChild = GUICreate("Sample MDI", 275, 174, Default, Default, $WS_POPUP, BitOR($WS_EX_MDICHILD, $WS_EX_LAYERED), $guiParrent)
    GUICtrlCreatePic(@WindowsDir & "\winnt256.bmp", 0, 0, 275, 174, $WS_CLIPSIBLINGS)
    GUICtrlSetState(-1, $GUI_DISABLE)

    Dim $OkButton = GUICtrlCreateButton("Don't Click Me Bro", 0, 174, 275)
    Dim $hwndOkButton = _GuiCtrlMakeTrans(-1, $AlphaMax)

    Dim $Processing = GUICtrlCreateLabel("Processing ...", 0, 0, 275, 20, $SS_CENTER)
    GUICtrlSetFont(-1, 12, 400, 0, 'Arial Bold')
    Dim $hwndProcessing = _GuiCtrlMakeTrans(-1, $AlphaMax)




    Dim $FadeTimer = TimerInit()
    Dim $AlphaVal = $AlphaMax

    While 1
        If TimerDiff($FadeTimer) >= $AlphaInterval Then
            If $AlphaVal >= $AlphaMax Or $AlphaVal <= $AlphaMin Then $AlphaSpeed = -$AlphaSpeed
            If $AlphaVal > $AlphaMax Then $AlphaVal = $AlphaMax
            If $AlphaVal < $AlphaMin Then $AlphaVal = $AlphaMin
            $AlphaVal += $AlphaSpeed
            WinSetTrans($hwndOkButton, '', $AlphaVal)
            WinSetTrans($hwndProcessing, '', -$AlphaVal)
            $FadeTimer = TimerInit()
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
            Case $OkButton
                GUICtrlSetData($OkButton, "!OUCH! Stop Clicking ME!")



    Func _GuiCtrlMakeTrans($iCtrlID, $iTrans = 255)
        Local $pHwnd, $hWnd, $nHwnd, $aPos, $a
        ;## Get the Control's Handle
        $hWnd = GUICtrlGetHandle($iCtrlID)
        If $hWnd = 0 Then Return SetError(1, 1, 0)
        ;## Get the Control's Parrent Window Handle.
        $pHwnd = _WinGetParent($hWnd)
        If $pHwnd = 0 Then Return SetError(1, 2, 0)
            ;## Get the relative position of the control.
            $aPos = ControlGetPos($pHwnd,"",$hWnd)
            If @error then Return SetError(1,3,0)
        ;## Get Absolute position of the control.
        $aPos = WinGetPos($hWnd)
        If @error Then Return SetError(1, 3, 0)
        ;## Great a container GUI Window to hold the control
        $nHwnd = GUICreate("", Default, Default, Default, Default, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $pHwnd)
        If $nHwnd = 0 Then Return SetError(1, 4, 0)
        ;## Move the container window to the original position of the control.
        WinMove($nHwnd, '', $aPos[0], $aPos[1], $aPos[2], $aPos[3])
        ;## Change the parrent of the control to the new gui
        $a = DllCall("User32.dll", "hwnd", "SetParent", "hwnd", $hWnd, "hwnd", $nHwnd)
        If $a[0] = 0 Then Return SetError(1, 5, 0)
        ;## Move the control to 0,0 of the new Parrent GUI.
        If Not ControlMove($nHwnd, '', $hWnd, 0, 0) Then Return SetError(1, 6, -1)
        ;## Display the new parrent GUI
        GUISetState(@SW_SHOW, $nHwnd);show the new child gui
        ;## Set the Transparency
        WinSetTrans($nHwnd, "", $iTrans);set the transparency
        If @error Then Return SetError(1, 7, 0)
        ;## switch back to the parent Gui
        ;## Return the handle for the new Child gui
        Return $nHwnd
    EndFunc   ;==>_GuiCtrlMakeTrans

    Func _WinGetParent($Childhwnd)
        Local $Return
        $Return = DllCall("User32.dll", "hwnd", "GetParent", "hwnd", $Childhwnd)
        Return $Return[0]
    EndFunc   ;==>_WinGetParent

#EndRegion    | Functions
Edited by Zinthose

--- TTFN

Share this post

Link to post
Share on other sites
Michel Claveau


Cool & amusing.


Share this post

Link to post
Share on other sites

Haha, Do't Click Me Bro.. Too Funny

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