Jump to content

Set a semi transparent background on second/child window


siva1612
 Share

Recommended Posts

I would like to create a window like the one shown below. The requirements are as below

1. The title bar should be opaque.

2. The parent window/Main screen will be below the side menu/child window

3. The left side of the side menu window should be opaque.

4. The right side should be semi-transparent. 

com.bookmark.money-screenshot-12.jpg

 

Any idea to help?

Link to comment
Share on other sites

  • Moderators

@siva1612 a simple search of the forum for "gui transparency" turns up a large number of threads on the subject. What have you tried on your own?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

@JLogan3o13 I have tried the following.

All the threads I searched were talking either about setting the background as completely transparent or setting the transparency of the entire window including the controls and all. None of these worked.

Though as I'm writing this reply i think can achieve this effect by using two GUIs. One on the left with an opaque background and one on the right without any controls and with its transparency level set. Will try that!

Link to comment
Share on other sites

maybe some of this code could help.

Of course a few things should change and i would suggest replacing extended GUI style with WS_EX_LAYERED like so:

$hGUI = GUICreate("", $iWidth, $iHeight, -1, -1, 0, 0x00080000)

 

Edited by genius257
Link to comment
Share on other sites

Here is an alternative approach. Click the button to show the overlay.

It uses a semi-transparent GUI with no controls as the 'background'.
The front GUI has the controls with a background that is completely transparent.

 

#include <GUIConstants.au3>
#include <WinAPI.au3>
#include <FontConstants.au3>
#include <AutoItConstants.au3>

Opt("GUIOnEventMode", 1)

Global $hgui, $hguiovl, $hguiovlbk
Global $showOverlay

;run main function
_main()

Func _main()
    Local $iGuiWidth = 500
    Local $iGuiHeight = 400
    Local $bkColor = 0x555555
    Local $alpha=200 ;0-255
    Local $iOverlayX = 150

    ;create the main GUI
    $hgui = GUICreate("main gui", $iGuiWidth, $iGuiHeight, -1, -1, -1, BITOR($WS_EX_COMPOSITED,$WS_EX_LAYERED))
    GUISetBkColor( 0x99FF99 )
    GUISetOnEvent($GUI_EVENT_CLOSE, "_onExit")

    GUICtrlCreateLabel("This is some text on bottom", 300, 150, 200)
    GUICtrlSetColor(-1, 0x000000)
    GUICtrlCreateLabel("show/hide overlay", 10, 30, 200)
    GUICtrlSetColor(-1, 0x000000)
    GUICtrlCreateButton("Show", 10, 50, 50, 25)
    GUICtrlSetOnEvent(-1, "_showoverlay")

    ;create the overlay background GUI
    $hguiovlbk = GUICreate("transparency test bk", $iGuiWidth-$iOverlayX, $iGuiHeight, $iOverlayX, 0, $WS_POPUP, BITOR($WS_EX_COMPOSITED,$WS_EX_LAYERED, $WS_EX_MDICHILD), $hgui)
    GUISetBkColor( $bkColor )
    WinSetTrans($hguiovlbk,"", $alpha) ;make window semi-transparent
    GUISetOnEvent($GUI_EVENT_CLOSE, "_onExit")

    ;create the overlay controls GUI
    $hguiovl = GUICreate("transparency test", $iGuiWidth-$iOverlayX, $iGuiHeight, $iOverlayX, 0, $WS_POPUP, BITOR($WS_EX_COMPOSITED,$WS_EX_LAYERED, $WS_EX_MDICHILD), $hgui)
    GUISetBkColor( $bkColor )
    _WinAPI_SetLayeredWindowAttributes($hguiovl, $bkColor, 255) ;make background fully transparent
    GUISetOnEvent($GUI_EVENT_CLOSE, "_onExit")
    GUISetFont(Default, Default, Default, "Arial", $hguiovl, 3 ) ;disable aliasing for fuzzy fonts

    GUICtrlCreateLabel("This is some text on top", 10, 10, 200)
    GUICtrlSetColor(-1, 0xFFFFFF)
    GUICtrlSetFont(-1, 12)

    GUICtrlCreateLabel("This is some more text on top", 10, 50, 200)
    GUICtrlSetColor(-1, 0xFFFFFF)
    GUICtrlSetFont(-1, 12)

    GUISetState(@SW_SHOW, $hgui)

    While 1
        Sleep(100)
    WEnd
EndFunc

Func _showOverlay()
    If $showOverlay Then
        GUISetState(@SW_HIDE, $hguiovlbk)
        GUISetState(@SW_HIDE, $hguiovl)
        $showOverlay = 0
    Else
        GUISetState(@SW_SHOW, $hguiovlbk)
        GUISetState(@SW_SHOW, $hguiovl)
        $showOverlay = 1
    EndIf
EndFunc

Func _onExit()
    Exit
EndFunc

 

Link to comment
Share on other sites

  • 1 year later...

This script is just what I was looking for to make my form semitransparent, thanks @kurtykurtyboy !

But, when I use this in my code all of the labels on my GUI are also transparent:

$layoutGUI = GUICreate("Layout", 1395, 570, -1, -1, 0x80000000)
Local $bkColor = 0xcccccc
Local $alpha=150 ;0-255
GUISetBkColor($bkColor)
WinSetTrans($layoutGUI,"", $alpha) ;make window semi-transparent

I've tried the following code after my label, but I can't get the label to be opaque:

GUICtrlCreateLabel("Some Text", 10, 10, 60, 60, 0x1001)
GUICtrlSetColor(-1, 0x000000)
GUICtrlSetFont(-1, 16)
GUICtrlSetBkColor(-1, 0xffffff)
WinSetTrans(-1,"", 0)

How can I set all of my labels to be opaque?

Thanks!!

Edited by WoodGrain
remove incorrect information about code
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

×
×
  • Create New...