Jump to content

Make Group Control Transparency


Go to solution Solved by Luke94,

Recommended Posts

Hi,

currently, I'm stucking on something. I would like to do a group control transparancy by using the following function:

Func _GuiCtrlMakeTrans($iCtrlID,$iTrans=255)

    Local $pHwnd, $nHwnd, $aPos, $a

    $hWnd = GUICtrlGetHandle($iCtrlID);Get the control handle
    If $hWnd = 0 then Return SetError(1,1,0)
    $pHwnd = DllCall("User32.dll", "hwnd", "GetParent", "hwnd", $hWnd);Get the parent Gui Handle
    If $pHwnd[0] = 0 then Return SetError(1,2,0)
    $aPos = ControlGetPos($pHwnd[0],"",$hWnd);Get the current pos of the control
    If @error then Return SetError(1,3,0)
    $nHwnd = GUICreate("", $aPos[2], $aPos[3], $aPos[0], $aPos[1], 0x80000000, 0x00080000 + 0x00000040, $pHwnd[0]);greate a gui in the position of the control
    If $nHwnd = 0 then Return SetError(1,4,0)
    $a = DllCall("User32.dll", "hwnd", "SetParent", "hwnd", $hWnd, "hwnd", $nHwnd);change the parent of the control to the new gui
    If $a[0] = 0 then Return SetError(1,5,0)
    If NOT ControlMove($nHwnd,'',$hWnd,0,0) then Return SetError(1,6,-1);Move the control to 0,0 of the newly created child gui
    GUISetState(@SW_Show,$nHwnd);show the new child gui
    GUICtrlSetState($nHwnd, $GUI_DISABLE)
    WinSetTrans($nHwnd,"",$iTrans);set the transparency
    If @error then Return SetError(1,7,0)
    GUISwitch($pHwnd[0]);switch back to the parent Gui

    Return $nHwnd;Return the handle for the new Child gui

 EndFunc

I also would like to add buttons into the group control with transparency = 50% for example.

When I am using this function, I cannot click the button within the group control. When I remove the function then I can click the button.

Does anyone have an idea how to solve the problem? Here is my code example:

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

$TestBG = GUICreate("TestBG",609,435,-1,-1,-1,-1)
$Group1 = GUICtrlCreateGroup("My Text",30,29,200,150,-1,-1)
 _GuiCtrlMakeTrans($Group1, 50)
GUICtrlSetState($Group1, $GUI_DISABLE)
GUICtrlCreateButton("My Text",60,60,100,30,-1,-1)
GUICtrlCreateCheckbox("My Text",70,110,74,20,-1,-1)
GUISetState(@SW_SHOW,$TestBG)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _GuiCtrlMakeTrans($iCtrlID,$iTrans=255)
    
    Local $pHwnd, $nHwnd, $aPos, $a
    
    $hWnd = GUICtrlGetHandle($iCtrlID);Get the control handle
    If $hWnd = 0 then Return SetError(1,1,0) 
    $pHwnd = DllCall("User32.dll", "hwnd", "GetParent", "hwnd", $hWnd);Get the parent Gui Handle
    If $pHwnd[0] = 0 then Return SetError(1,2,0)
    $aPos = ControlGetPos($pHwnd[0],"",$hWnd);Get the current pos of the control
    If @error then Return SetError(1,3,0)
    $nHwnd = GUICreate("", $aPos[2], $aPos[3], $aPos[0], $aPos[1], 0x80000000, 0x00080000 + 0x00000040, $pHwnd[0]);greate a gui in the position of the control
    If $nHwnd = 0 then Return SetError(1,4,0)
    $a = DllCall("User32.dll", "hwnd", "SetParent", "hwnd", $hWnd, "hwnd", $nHwnd);change the parent of the control to the new gui
    If $a[0] = 0 then Return SetError(1,5,0)
    If NOT ControlMove($nHwnd,'',$hWnd,0,0) then Return SetError(1,6,-1);Move the control to 0,0 of the newly created child gui
    GUISetState(@SW_Show,$nHwnd);show the new child gui
    WinSetTrans($nHwnd,"",$iTrans);set the transparency
    If @error then Return SetError(1,7,0)
    GUISwitch($pHwnd[0]);switch back to the parent Gui
    
    Return $nHwnd;Return the handle for the new Child gui
    
EndFunc

I would appreciate any help! Thanks.

Link to comment
Share on other sites

  • Solution

Hi Misuranai,

The GUI created in the _GuiCtrlMakeTrans function needs the $WS_EX_TRANSPARENT extended style adding.

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

$TestBG = GUICreate("TestBG",609,435,-1,-1,-1,-1)
$Group1 = GUICtrlCreateGroup("My Text",30,29,200,150,-1,-1)
 _GuiCtrlMakeTrans($Group1, 50)
GUICtrlSetState($Group1, $GUI_DISABLE)
GUICtrlCreateButton("My Text",60,60,100,30,-1,-1)
GUICtrlCreateCheckbox("My Text",70,110,74,20,-1,-1)
GUISetState(@SW_SHOW,$TestBG)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _GuiCtrlMakeTrans($iCtrlID,$iTrans=255)

    Local $pHwnd, $nHwnd, $aPos, $a

    $hWnd = GUICtrlGetHandle($iCtrlID);Get the control handle
    If $hWnd = 0 then Return SetError(1,1,0)
    $pHwnd = DllCall("User32.dll", "hwnd", "GetParent", "hwnd", $hWnd);Get the parent Gui Handle
    If $pHwnd[0] = 0 then Return SetError(1,2,0)
    $aPos = ControlGetPos($pHwnd[0],"",$hWnd);Get the current pos of the control
    If @error then Return SetError(1,3,0)
    $nHwnd = GUICreate("", $aPos[2], $aPos[3], $aPos[0], $aPos[1], 0x80000000, 0x00080000 + 0x00000040 + $WS_EX_TRANSPARENT, $pHwnd[0]);greate a gui in the position of the control
    If $nHwnd = 0 then Return SetError(1,4,0)
    $a = DllCall("User32.dll", "hwnd", "SetParent", "hwnd", $hWnd, "hwnd", $nHwnd);change the parent of the control to the new gui
    If $a[0] = 0 then Return SetError(1,5,0)
    If NOT ControlMove($nHwnd,'',$hWnd,0,0) then Return SetError(1,6,-1);Move the control to 0,0 of the newly created child gui
    GUISetState(@SW_Show,$nHwnd);show the new child gui
    WinSetTrans($nHwnd,"",$iTrans);set the transparency
    If @error then Return SetError(1,7,0)
    GUISwitch($pHwnd[0]);switch back to the parent Gui

    Return $nHwnd;Return the handle for the new Child gui

EndFunc

 

Link to comment
Share on other sites

On 12/8/2021 at 5:35 PM, Luke94 said:

Hi Misuranai,

The GUI created in the _GuiCtrlMakeTrans function needs the $WS_EX_TRANSPARENT extended style adding.

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

$TestBG = GUICreate("TestBG",609,435,-1,-1,-1,-1)
$Group1 = GUICtrlCreateGroup("My Text",30,29,200,150,-1,-1)
 _GuiCtrlMakeTrans($Group1, 50)
GUICtrlSetState($Group1, $GUI_DISABLE)
GUICtrlCreateButton("My Text",60,60,100,30,-1,-1)
GUICtrlCreateCheckbox("My Text",70,110,74,20,-1,-1)
GUISetState(@SW_SHOW,$TestBG)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _GuiCtrlMakeTrans($iCtrlID,$iTrans=255)

    Local $pHwnd, $nHwnd, $aPos, $a

    $hWnd = GUICtrlGetHandle($iCtrlID);Get the control handle
    If $hWnd = 0 then Return SetError(1,1,0)
    $pHwnd = DllCall("User32.dll", "hwnd", "GetParent", "hwnd", $hWnd);Get the parent Gui Handle
    If $pHwnd[0] = 0 then Return SetError(1,2,0)
    $aPos = ControlGetPos($pHwnd[0],"",$hWnd);Get the current pos of the control
    If @error then Return SetError(1,3,0)
    $nHwnd = GUICreate("", $aPos[2], $aPos[3], $aPos[0], $aPos[1], 0x80000000, 0x00080000 + 0x00000040 + $WS_EX_TRANSPARENT, $pHwnd[0]);greate a gui in the position of the control
    If $nHwnd = 0 then Return SetError(1,4,0)
    $a = DllCall("User32.dll", "hwnd", "SetParent", "hwnd", $hWnd, "hwnd", $nHwnd);change the parent of the control to the new gui
    If $a[0] = 0 then Return SetError(1,5,0)
    If NOT ControlMove($nHwnd,'',$hWnd,0,0) then Return SetError(1,6,-1);Move the control to 0,0 of the newly created child gui
    GUISetState(@SW_Show,$nHwnd);show the new child gui
    WinSetTrans($nHwnd,"",$iTrans);set the transparency
    If @error then Return SetError(1,7,0)
    GUISwitch($pHwnd[0]);switch back to the parent Gui

    Return $nHwnd;Return the handle for the new Child gui

EndFunc

 

Thank you so much! It works fine for me. That was a simple solution. :P

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