Jump to content

Transparent PopUp Gui [Solved]


IanN1990
 Share

Recommended Posts

Hi,

I am looking to make a transparent background for my GUI 

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

Example1()
;Example2()


GUICtrlCreateLabel("This is text on a transparent Layered GUI", 10, 10, 200, 20, -1)
 GUICtrlCreateButton("Button", 10, 40, 40)
GUISetBkColor(0xABCDEF)
_WinAPI_SetLayeredWindowAttributes($hGui, 0x010101)
_WinAPI_SetLayeredWindowAttributes($hGui, 0xABCDEF, 255)
GUISetState(@SW_SHOW)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Exit

Func Example1()
Global $hGui = GUICreate("trans", 300, 400, -1, -1, -1, $WS_EX_LAYERED)
EndFunc

Func Example2()
Global $hGui = GUICreate("trans", 300, 400, -1, -1, -1, BitOR($WS_POPUP, $WS_EX_TOPMOST, $WS_EX_LAYERED))
EndFunc

From my research here is the code i found, which works though but when i change the style to include popup the GUI is invisible?

The only other idea i can think of is keeping it as a non-popup but removing the border (it was a long time ago but isnt there a _WinAPI_ command that can crop windows? Though i could be way off the mark on the best way to deal with this problem :)

Example.jpg

Edited by IanN1990
Link to comment
Share on other sites

You've got $WS_POPUP in the wrong argument spot.

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

Global $hGui = GUICreate("trans", 300, 400, -1, -1, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_LAYERED))


GUICtrlCreateLabel("This is text on a transparent Layered GUI", 10, 10, 200, 20, -1, $GUI_WS_EX_PARENTDRAG)
GUICtrlCreateButton("Button", 10, 40, 40)

_WinAPI_SetLayeredWindowAttributes($hGui, 0xF1F1F1, 255)
GUISetState(@SW_SHOW, $hGui)

Do

Until GUIGetMsg() = $GUI_EVENT_CLOSE

Exit 0 * GUIDelete($hGui)

 

Edited by InunoTaishou
Link to comment
Share on other sites

  • 2 weeks later...
On 9/6/2016 at 8:15 PM, InunoTaishou said:

You've got $WS_POPUP in the wrong argument spot.

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

Global $hGui = GUICreate("trans", 300, 400, -1, -1, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_LAYERED))


GUICtrlCreateLabel("This is text on a transparent Layered GUI", 10, 10, 200, 20, -1, $GUI_WS_EX_PARENTDRAG)
GUICtrlCreateButton("Button", 10, 40, 40)

_WinAPI_SetLayeredWindowAttributes($hGui, 0xF1F1F1, 255)
GUISetState(@SW_SHOW, $hGui)

Do

Until GUIGetMsg() = $GUI_EVENT_CLOSE

Exit 0 * GUIDelete($hGui)

@InunoTaishou, the above code does not create a transparent GUI for me. Changing the second parameter, 0xF1F1F1, in the _WinAPI_SetLayeredWindowAttributes function to 0xABCDEF does nothing, either. (I assume the color 0xABCDEF  is "transparent" because it is used in the Example for _WinAPI_SetLayeredWindowAttributes.   What am I misunderstanding?

 

Link to comment
Share on other sites

Hi,
 

Following the responses i have updated two examples encase others need this idea.

 

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

Example1()
;Example2()

Do
Until GUIGetMsg() = $Buttton
Exit

Func Example1()
Global $hGui = GUICreate("trans", 300, 400, -1, -1, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_LAYERED))
GUICtrlCreateLabel("This is text on a transparent Layered GUI", 10, 10, 200, 20, -1)
Global $Buttton = GUICtrlCreateButton("Button", 10, 40, 40)
GUISetBkColor(0xABCDEF)
_WinAPI_SetLayeredWindowAttributes($hGui, 0xABCDEF, 255)
GUISetState(@SW_SHOW)
EndFunc

Func Example2()
Global $hGui = GUICreate("trans", 300, 400, -1, -1, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_LAYERED))
GUICtrlCreateLabel("This is text on a transparent Layered GUI", 10, 10, 200, 20, -1)
Global $Buttton = GUICtrlCreateButton("Button", 10, 40, 40)
GUISetBkColor(0xF1F1F1)
_WinAPI_SetLayeredWindowAttributes($hGui, 0xF1F1F1, 255)
GUISetState(@SW_SHOW)
EndFunc

 

Example 1 uses " transparent" Style which gives some sort of black-glow

Example2 uses Timmy style, which gives a much cleaner finish. I did some testing though and you can use any colour to get the same cleaner finish (ie 0xffffff)

See screenshot below (The grey colour is not the Gui, but SciTE Lite as its transparent and sees though it) :)

 

Untitled.jpg

Edited by IanN1990
Link to comment
Share on other sites

Thank you @AutoBert for the helpful reply.  

@IanN1990, I appreciate the additional effort but I couldn't get your latest script to display anything, even after correcting the spelling of $Button and declaring it as a Global variable prior to its use. Were you able to run the script as typed?

Edited by timmy2
Link to comment
Share on other sites

Playing around with this example (rainy day), if you can click on the moving text, you can then drag the screen-size transparent GUI.  The label controls always move on, and relative to, the transparent GUI's position on the screen.  
Even though you can't see the transparent GUI, you can imagine where it is - in theory.

; https://www.autoitscript.com/forum/topic/184448-transparent-popup-gui-solved/?do=findComment&comment=1325725

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

HotKeySet("{ESC}", "Terminate") ; Even if this program's GUI does not have focus, this hotkey, "Esc", will end the script immediately.

Local $hGui = GUICreate("trans", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_LAYERED, $WS_EX_COMPOSITED))
GUISetBkColor(0xF1F1F1, $hGui)
;GUISetFont(24, 600)

Local $idCtrlLabel = GUICtrlCreateLabel("This is text on a transparent Layered GUI", 0, 0, 800, 100, -1, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetColor(-1, 0xFF0000) ; Set Text colour.
GUICtrlSetFont(-1, 24, 600)

Local $idCtrlLabel2 = GUICtrlCreateLabel("This text is on a different label on the same transparent layered GUI", 0, 0, 700, 80, -1, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetColor(-1, 0x0000FF) ; Set Text colour.
GUICtrlSetFont(-1, 18, 600)

Local $aPosLabel = WinGetPos(GUICtrlGetHandle($idCtrlLabel)), $xDir = 1, $yDir = 1, $iSpeed = 5

_WinAPI_SetLayeredWindowAttributes($hGui, 0xF1F1F1, 250)
GUISetState(@SW_SHOW, $hGui)

Do
    ; A moving Label control on GUI.
    $aPosLabel[0] = ($xDir ? $aPosLabel[0] + $iSpeed : $aPosLabel[0] - $iSpeed)                   ; 'X' coordinate of Label.
    $aPosLabel[1] = ($yDir ? $aPosLabel[1] + $iSpeed : $aPosLabel[1] - $iSpeed)                   ; 'Y' coordinate of Label.
    $xDir = ($xDir ? ($aPosLabel[0] > @DesktopWidth - 700 ? 0 : 1) : ($aPosLabel[0] < 0 ? 1 : 0)) ; Change horiz. direction 700 from right side of screen, and, left side of screen.
    $yDir = ($yDir ? ($aPosLabel[1] > @DesktopHeight - 40 ? 0 : 1) : ($aPosLabel[1] < 0 ? 1 : 0)) ; Change vert. direction 40 up from bottom of screen, and, top of screen.
    GUICtrlSetPos($idCtrlLabel, $aPosLabel[0], $aPosLabel[1])                                     ; Reposition Label control.
    GUICtrlSetPos($idCtrlLabel2, $aPosLabel[0], @DesktopHeight - $aPosLabel[1] - 50)              ; Reposition Label2 control.
    Sleep(10)
Until GUIGetMsg() = $GUI_EVENT_CLOSE


Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

 

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