Jump to content



Photo

[Resolved] True transparency


  • Please log in to reply
8 replies to this topic

#1 xeroTechnologiesLLC

xeroTechnologiesLLC

    Prodigy

  • Active Members
  • PipPipPip
  • 158 posts

Posted 15 March 2012 - 03:29 PM

I've been looking through the forums for about 3 days now, reviewing various 'transparency' methods such as parent/child GUI manipulation, etc. None of them are really TRUE transparency methods. My problem that I ran into with the parent/child gui method was that if the user defines their font to the transparency color - the font becomes transparent...the bkg to the transparency color - the program becomes entirely transparent.

We tried a few other various methods recommended to make a Form, not the controls, just the form, true transparent.

So far I have not found a method to do this.

Unless I am searching for the wrong keywords, is there no native transparency methods in AutoIT?

The current program I am attempting to develop hinges on 2 things, transparency and scrolling items in an Arc style, which I haven't figured out how to do either, so I'm just wondering if there was a direct way to do true transparency in AutoIT.

And before someone perceives it as such :oops: , I do not mean this to be a bash against AutoIT, simply just asking a question. :bye:

Edited by xeroTechnologiesLLC, 07 April 2012 - 07:52 PM.








#2 BrewManNH

BrewManNH

    באָבקעס מיט קודוצ׳ה

  • MVPs
  • 6,877 posts

Posted 15 March 2012 - 03:52 PM

Here's one way of doing it:

#include <GUIConstants.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) Global Const $MainGUI = GUICreate("Media Player", 434, 434, -1, -1, $WS_POPUP, $WS_EX_LAYERED) GUISetBkColor(0x808080) GUISetOnEvent($GUI_EVENT_CLOSE, "CloseMG") GUICtrlCreatePic("cdrom.bmp", 0, 0, 0, 0) GUICtrlSetState(-1, $GUI_DISABLE) GUISetState() While 1     Sleep(10) WEnd Func CloseMG()     Exit EndFunc


Use this file for the background image.

How to ask questions the smart way!

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.

Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.

_FileGetProperty - Retrieve the properties of a file SciTE Toolbar - A toolbar demo for use with the SciTE editorGUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.

GUIToolTip UDF Demo - Demo script to show how to use the GUIToolTip UDF to create and use customized tooltips.

Posted Image


#3 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,387 posts

Posted 15 March 2012 - 04:01 PM

xeroTechnologiesLLC,

Here are a couple of ways to make transparent GUIs. :oops:

This one has visible controls:
AutoIt         
#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> $Main_Gui = GUICreate("", 400, 400, 20, 20, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST) $But1 = GUICtrlCreateButton(" Exit ", 100, 100, 80, 21) ; Must be within GUI window $Vol_Up_ID = GUICtrlCreateButton("Vol Up",   300, 200, 80, 30) $Vol_Dn_ID = GUICtrlCreateButton("Vol Down", 300, 230, 80, 30) GUISetControlsVisible($Main_Gui) GUISetState() While 1     If GUIGetMsg() = $But1 Then Exit WEnd Func GUISetControlsVisible($hWnd)     Local $aM_Mask, $aCtrlPos, $aMask     $aM_Mask = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", 0, "long", 0, "long", 0, "long", 0)     $aLastID = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", GUICtrlGetHandle(-1))     For $i = 3 To $aLastID[0]         $aCtrlPos = ControlGetPos($hWnd, '', $i)         If Not IsArray($aCtrlPos) Then ContinueLoop         $aMask = DllCall("gdi32.dll", "long", "CreateRectRgn", _             "long", $aCtrlPos[0], _             "long", $aCtrlPos[1], _             "long", $aCtrlPos[0] + $aCtrlPos[2], _             "long", $aCtrlPos[1] + $aCtrlPos[3])         DllCall("gdi32.dll", "long", "CombineRgn", "long", $aM_Mask[0], "long", $aMask[0], "long", $aM_Mask[0], "int", 2)     Next     DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $hWnd, "long", $aM_Mask[0], "int", 1) EndFunc

And this one has visible text:
AutoIt         
#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WINAPI.au3> #include <sendmessage.au3> ;Global Const $LWA_ALPHA = 0x2 ;Global Const $LWA_COLORKEY = 0x1 HotKeySet("ESC", "_Exit") $hGUI = GUICreate("Test", 500, 500, -1, -1, $WS_POPUP, $WS_EX_LAYERED) GUISetBkColor(0xABCDEF) GUICtrlCreateLabel("Click on the text to drag this transparent GUI" & @CRLF & "Press ESC to exit", 10, 10) _WinAPI_SetLayeredWindowAttributes($hGUI, 0xABCDEF, 250) GUISetState() While 1     Switch GUIGetMsg()         Case $GUI_EVENT_CLOSE             Exit         Case $GUI_EVENT_PRIMARYDOWN             _SendMessage($hGUI, $WM_SYSCOMMAND, 0xF012, 0)     EndSwitch WEnd Func _Exit()     Exit EndFunc

I hope they prove useful. :bye:

M23
StringSize - Automatically size controls to fit text - ExtMsgBox - A user customisable replacement for MsgBox

Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs

Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames

GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes

ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display

RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options

GUIListViewEx - Insert, delete, move, drag and sort ListView items


#4 UEZ

UEZ

    Never say never

  • MVPs
  • 3,616 posts

Posted 15 March 2012 - 04:07 PM

Here another example with GDI+:

AutoIt         
#include <guiconstantsex.au3> #include <windowsconstants.au3> #include <gdiplus.au3> Global $hGUI, $hImage, $hGraphic, $hImage Global Const $SC_DRAGMOVE = 0xF012 _GDIPlus_Startup() ; Load PNG image $hImage = _GDIPlus_ImageLoadFromFile(StringReplace(@AutoItExe, "autoit3.exe", "ExamplesGUITorus.png")) $iWidth = _GDIPlus_ImageGetWidth($hImage) $iHeight = _GDIPlus_ImageGetHeight($hImage) ; Create GUI $hGUI = GUICreate("Show PNG", $iWidth, $iHeight, -1, -1, $WS_POPUP, $WS_EX_LAYERED + $WS_EX_TOPMOST) $hGUI_child = GUICreate("", $iWidth, $iHeight, 0, 0, $WS_POPUP, $WS_EX_LAYERED + $WS_EX_TOPMOST + $WS_EX_MDICHILD, $hGUI) $hButton = GUICtrlCreateButton("Exit", $iWidth * 2 / 3, $iHeight * 2 / 3, 40, 40) GUISetBkColor(0xFFFFFF, $hGUI_child) GUISetState(@SW_SHOW, $hGUI) GUISetState(@SW_SHOW, $hGUI_child) SetTransparentBitmap($hGUI, $hImage) _WinAPI_SetLayeredWindowAttributes($hGUI_child, 0xFFFFFF, 0xFF) $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI_child) _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2) DllCall($ghGDIPDll, "uint", "GdipSetTextRenderingHint", "handle", $hGraphic, "int", 3) _GDIPlus_GraphicsDrawString($hGraphic, "GDI+ Full Transparency", 0, $iHeight / 2 - 20, "Arial", 12) GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN") GUIRegisterMsg($WM_PAINT, "WM_PAINT") While 1     $nMsg = GUIGetMsg()     Switch $nMsg         Case $GUI_EVENT_CLOSE, $hButton             GUIRegisterMsg($WM_LBUTTONDOWN, "")             GUIRegisterMsg($WM_PAINT, "")             _GDIPlus_ImageDispose($hImage)             _GDIPlus_GraphicsDispose($hGraphic)             _GDIPlus_Shutdown()             GUIDelete($hGUI)             ExitLoop     EndSwitch WEnd Func WM_PAINT($hWnd, $msg, $wParam, $lParam)     _GDIPlus_GraphicsDrawString($hGraphic, "GDI+ Full Transparency", 0, $iHeight / 2 - 20, "Arial", 12)     Return "GUI_RUNDEFMSG" EndFunc Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)     _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0) EndFunc   ;==>_WM_LBUTTONDOWN Func SetTransparentBitmap($hGUI, $hImage, $iOpacity = 0xFF)     Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend     $hScrDC = _WinAPI_GetDC(0)     $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)     $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)     $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)     $tSize = DllStructCreate($tagSIZE)     $pSize = DllStructGetPtr($tSize)     DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth($hImage))     DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))     $tSource = DllStructCreate($tagPOINT)     $pSource = DllStructGetPtr($tSource)     $tBlend = DllStructCreate($tagBLENDFUNCTION)     $pBlend = DllStructGetPtr($tBlend)     DllStructSetData($tBlend, "Alpha", $iOpacity)     DllStructSetData($tBlend, "Format", 1)     _WinAPI_UpdateLayeredWindow($hGUI,  $hMemDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)     _WinAPI_ReleaseDC(0, $hScrDC)     _WinAPI_SelectObject($hMemDC, $hOld)     _WinAPI_DeleteObject($hBitmap)     _WinAPI_DeleteDC($hMemDC) EndFunc   ;==>SetTransparentBitmap


Tested on Win7 x64!

Br,
UEZ

Edited by UEZ, 15 March 2012 - 04:18 PM.

 
The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯


#5 xeroTechnologiesLLC

xeroTechnologiesLLC

    Prodigy

  • Active Members
  • PipPipPip
  • 158 posts

Posted 15 March 2012 - 04:20 PM

/sigh/ I have so far to learn... lol

So taking Melba's example:
Plain Text         
#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> $Main_Gui = GUICreate("", 400, 400, 20, 20, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST) $But1 = GUICtrlCreateButton(" Exit ", 100, 100, 80, 21) ; Must be within GUI window $Vol_Up_ID = GUICtrlCreateButton("Vol Up",   300, 200, 80, 30) $Vol_Dn_ID = GUICtrlCreateButton("Vol Down", 300, 230, 80, 30) GUISetControlsVisible($Main_Gui) GUISetState() While 1     If GUIGetMsg() = $But1 Then Exit WEnd Func GUISetControlsVisible($hWnd)     Local $aM_Mask, $aCtrlPos, $aMask     $aM_Mask = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", 0, "long", 0, "long", 0, "long", 0)     $aLastID = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", GUICtrlGetHandle(-1))     For $i = 3 To $aLastID[0]         $aCtrlPos = ControlGetPos($hWnd, '', $i)         If Not IsArray($aCtrlPos) Then ContinueLoop         $aMask = DllCall("gdi32.dll", "long", "CreateRectRgn", _             "long", $aCtrlPos[0], _             "long", $aCtrlPos[1], _             "long", $aCtrlPos[0] + $aCtrlPos[2], _             "long", $aCtrlPos[1] + $aCtrlPos[3])         DllCall("gdi32.dll", "long", "CombineRgn", "long", $aM_Mask[0], "long", $aMask[0], "long", $aM_Mask[0], "int", 2)     Next     DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $hWnd, "long", $aM_Mask[0], "int", 1) EndFunc


..am I understanding it correctly that it's basically creating a mask over the form?

I don't really get DLLCalls I guess. My math is... horrible at best so I'm not really getting the usage in it, but I will continue to research that further down the line. But if I understand this correctly... GUISetControlsVisible function will mask the form no matter the size/layout so... .. in theory if I had to use this same function on say 3 or 4 gui's in 1 program the $hWnd would go back to when i called the function and hide the appropriate form that i note in the function call...right?

GUISetControlsVisible($Main_Gui) GUISetControlsVisible($Main_Gui1) GUISetControlsVisible($Main_Gui2) etc...


#6 xeroTechnologiesLLC

xeroTechnologiesLLC

    Prodigy

  • Active Members
  • PipPipPip
  • 158 posts

Posted 15 March 2012 - 04:23 PM

Oh, and thank you both very much for the input - saving the examples in my code archive.

#7 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,387 posts

Posted 15 March 2012 - 04:33 PM

xeroTechnologiesLLC,

That script is only a very rough example of how to mask the GUI that i found on the forum a long time ago - it would need a fair bit of work to get it up to a reasonable standard - a lot of the code could be much better written usine the current version of Autoit. We could probably even hide the DLL calls just for you! :oops:

Using this for several GUIs in the same script woudl nto be simple - it is pretty much hardwired to a single GUI as it stands. Again it would take a fair amount of work to develop - putting controls into arrays would probably be a good place to start. :bye:

But do not let me put you off - go ahead and try! You know where we are if you run into difficulties. :doh:

M23
StringSize - Automatically size controls to fit text - ExtMsgBox - A user customisable replacement for MsgBox

Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs

Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames

GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes

ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display

RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options

GUIListViewEx - Insert, delete, move, drag and sort ListView items


#8 xeroTechnologiesLLC

xeroTechnologiesLLC

    Prodigy

  • Active Members
  • PipPipPip
  • 158 posts

Posted 15 March 2012 - 04:55 PM

Melba,

We could probably even hide the DLL calls just for you! :bye:

:oops:

- putting controls into arrays would probably be a good place to start.


The other main developer and I had been discussing this for some time and before I go too much further on this project we will most assuredly have to.

Now for the other hard part... scrolling items in an arc.

http://www.autoitscript.com/forum/topic/138438-gui-design-advisement-for-a-scrolling-arc-style-hud/page__fromsearch__1 ... is the thread I started seeking help on that and I'll manage that topic there.

Thank you again for all the help!

#9 Belini

Belini

    Polymath

  • Active Members
  • PipPipPipPip
  • 242 posts

Posted 16 March 2012 - 11:54 AM

Melba23 and UEZ congratulations for codes posted, will be very helpful to me.
Posted ImageAutoit Forum Brazil: http://autoitbrasil.com/ >> Autoit and arcades: http://www.arcadebr.com/forumMy Codes:




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users