Jump to content



Photo

Transparent controls


  • Please log in to reply
19 replies to this topic

#1 ChrisL

ChrisL

    Mass Spanner!

  • Active Members
  • PipPipPipPipPipPip
  • 1,746 posts

Posted 08 June 2008 - 08:26 AM

I started messing around with this when someone asked about transparent controls before.
I made a function for creating transparent controls but martin below had a better way of doing it. (Thanks for the help martin!)

The syntax is $hWnd = _GuiCtrlMakeTrans($ControlID as returned by GuiCtrlCreate....,[Transparency level (Optional can be set later by the returned hWnd )])

Returns a handle to the new Child gui

There are a couple of functions which I can't get to work properly, one is UP/Down controls and the other is Radio Buttons

This is the new function

Plain Text         
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


Here is an example of the Help file Gui Example

Plain Text         
#include <GuiConstantsEx.au3> #include <AVIConstants.au3> #include <TreeViewConstants.au3> #include <WindowsConstants.au3> ; GUI GuiCreate("Sample GUI", 400, 400) GuiSetIcon(@SystemDir & "\mspaint.exe", 0) GUICtrlCreatePic(@WindowsDir & "\River Sumida.bmp",0,0,400,400,$WS_CLIPSIBLINGS) ; MENU GuiCtrlCreateMenu("Menu&One") GuiCtrlCreateMenu("Menu&Two") GuiCtrlCreateMenu("MenuTh&ree") GuiCtrlCreateMenu("Menu&Four") ; CONTEXT MENU $contextMenu = GuiCtrlCreateContextMenu() GuiCtrlCreateMenuItem("Context Menu", $contextMenu) GuiCtrlCreateMenuItem("", $contextMenu);separator GuiCtrlCreateMenuItem("&Properties", $contextMenu) ; PIC Local $sFile = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir") & "\Examples\GUI\logo4.gif" GuiCtrlCreatePic($sFile,0,20, 169,68) $pt = _GuiCtrlMakeTrans(-1); we'll set the transparecy later for this one GuiCtrlCreateLabel("Sample pic", 75, 21, 53, 15) GuiCtrlSetColor(-1,0xffffff) _GuiCtrlMakeTrans(-1,100) ; AVI Local $sFile = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir") & "\Examples\GUI\sampleAVI.avi" GuiCtrlCreateAvi($sFile,0, 180, 30, 32, 32, $ACS_AUTOPLAY) _GuiCtrlMakeTrans(-1,100) GuiCtrlCreateLabel("Sample avi", 170, 70) _GuiCtrlMakeTrans(-1,100) ; TAB GuiCtrlCreateTab(240, 20, 150, 70) _GuiCtrlMakeTrans(-1,100) GuiCtrlCreateTabItem("One") GuiCtrlCreateLabel("Sample Tab with tabItems", 250, 40) GuiCtrlCreateTabItem("Two") GuiCtrlCreateTabItem("Three") GuiCtrlCreateTabItem("") ; COMBO GuiCtrlCreatecombo("Sample Combo", 250, 100, 120, 100) _GuiCtrlMakeTrans(-1,100) ; PROGRESS GuiCtrlCreateProgress(60, 100, 150, 20) GuiCtrlSetData(-1, 60) _GuiCtrlMakeTrans(-1,100) GuiCtrlCreateLabel("Progress:", 5, 102) _GuiCtrlMakeTrans(-1,100) ; EDIT GuiCtrlCreateEdit(@CRLF & "  Sample Edit Control", 10, 130, 150, 70) _GuiCtrlMakeTrans(-1,100) ; LIST GuiCtrlCreateList("", 5, 210, 100, 90) _GuiCtrlMakeTrans(-1,100) GuiCtrlSetData(-1, "a.Sample|b.List|c.Control|d.Here", "b.List") ; ICON GuiCtrlCreateIcon("shell32.dll", 1, 175, 140) _GuiCtrlMakeTrans(-1,100) GuiCtrlCreateLabel("Icon", 180, 180, 50, 20) _GuiCtrlMakeTrans(-1,100) ; LIST VIEW $listView = GuiCtrlCreateListView("Sample|ListView|", 110, 210, 110, 80) _GuiCtrlMakeTrans(-1,100) GuiCtrlCreateListViewItem("A|One", $listView) GuiCtrlCreateListViewItem("B|Two", $listView) GuiCtrlCreateListViewItem("C|Three", $listView) ; UPDOWN GuiCtrlCreateLabel("UpDown", 350, 135) _GuiCtrlMakeTrans(-1,100) GuiCtrlCreateInput("42", 350, 140, 40, 20) GuiCtrlCreateUpDown(-1) ; GROUP WITH RADIO BUTTONS GuiCtrlCreateGroup("Sample Group", 230, 120,110,80) GuiCtrlCreateRadio("Radio One", 250, 140, 80) GuiCtrlSetState(-1, $GUI_CHECKED) GuiCtrlCreateRadio("Radio Two", 250, 165, 80) GUICtrlCreateGroup ("",-99,-99,1,1) ;close group ; LABEL GuiCtrlCreateLabel("Green" & @CRLF & "Label", 350, 185, 40, 40) GuiCtrlSetBkColor(-1, 0x00FF00) _GuiCtrlMakeTrans(-1,100) ; SLIDER GuiCtrlCreateLabel("Slider:", 235, 235) _GuiCtrlMakeTrans(-1,100) GuiCtrlCreateSlider(270, 230, 120, 30) _GuiCtrlMakeTrans(-1,100) GuiCtrlSetData(-1, 30) ; INPUT GuiCtrlCreateInput("Sample Input Box", 235, 275, 130, 20) _GuiCtrlMakeTrans(-1,100) ; DATE GuiCtrlCreateDate("", 5, 300, 200, 20) _GuiCtrlMakeTrans(-1,100) GuiCtrlCreateLabel("(Date control expands into a calendar)", 10, 325, 200, 20) _GuiCtrlMakeTrans(-1,100) ; BUTTON $Button = GuiCtrlCreateButton("Sample Button", 10, 350, 100, 30) _GuiCtrlMakeTrans(-1,100) ; CHECKBOX GuiCtrlCreateCheckbox("Checkbox", 130, 355, 80, 20) GuiCtrlSetState(-1, $GUI_CHECKED) _GuiCtrlMakeTrans(-1,100) ; TREEVIEW ONE $treeOne = GuiCtrlCreateTreeView(210, 310, 80, 80) _GuiCtrlMakeTrans(-1,100) $treeItem = GuiCtrlCreateTreeViewItem("TreeView", $treeOne) GuiCtrlCreateTreeViewItem("Item1", $treeItem) GuiCtrlCreateTreeViewItem("Item2", $treeItem) GuiCtrlCreateTreeViewItem("Foo", -1) GuiCtrlSetState($treeItem, $GUI_EXPAND) ; TREEVIEW TWO $treeTwo = GuiCtrlCreateTreeView(295, 310, 103, 80, $TVS_CHECKBOXES) _GuiCtrlMakeTrans(-1,100) GuiCtrlCreateTreeViewItem("TreeView", $treeTwo) GuiCtrlCreateTreeViewItem("With", $treeTwo) GuiCtrlCreateTreeViewItem("tvs_checkboxes", $treeTwo) GuiCtrlSetState(-1, $GUI_CHECKED) GuiCtrlCreateTreeViewItem("Style", $treeTwo) ; GUI MESSAGE LOOP GuiSetState() ;change the transparency of the picture For $i = 255 to 0 step -1     WinSetTrans($pt,"",$i)     Sleep(1) Next For $i = 0 to 100     WinSetTrans($pt,"",$i)     Sleep(1) Next While 1         Switch GuiGetMsg()         Case $GUI_EVENT_CLOSE             Exit         Case $Button             Msgbox(0,"","Button still works!")     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

Edited by ChrisL, 09 June 2008 - 06:34 AM.








#2 Andreik

Andreik

    Bishop

  • Active Members
  • PipPipPipPipPipPip
  • 2,498 posts

Posted 08 June 2008 - 08:44 AM

Thanks ChrisL! Work fine for me.
When the words fail... music speaks

#3 martin

martin

    ~~\o/~~~/0\=¬''~~~

  • MVPs
  • 7,199 posts

Posted 08 June 2008 - 10:23 AM

Works well ChrisL, good idea.
The function seems a bit clunky though. Could it be done by having something like
SetTransparency($Tab1,$level)


then in your function find the size of the control using ControlGetPos, create the gui the way you do at the moment but using the dimensions from ControlGetPos, and then set the control to be a child of that window? If that works then you wouldn't need all those case statements for all the different control types, and controls could be created just as normal.
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

#4 ALG

ALG

    Wayfarer

  • Active Members
  • Pip
  • 55 posts

Posted 08 June 2008 - 08:09 PM

very nice work

_____________

I LOVE ALGERIA .... ;-)


#5 Kip

Kip

    When done learning: die

  • Active Members
  • PipPipPipPipPipPip
  • 1,685 posts

Posted 08 June 2008 - 08:43 PM

doesn't this also work with standard UDF controls. (Because those controls are also windows ($WS_POPUP))

Edited by Kip, 09 June 2008 - 02:04 PM.

There's a big chance this post has been edited.Posted Image

#6 ChrisL

ChrisL

    Mass Spanner!

  • Active Members
  • PipPipPipPipPipPip
  • 1,746 posts

Posted 08 June 2008 - 10:50 PM

Updated.. thanks Martin!

#7 WeMartiansAreFriendly

WeMartiansAreFriendly

    Where's the kaboom?

  • Active Members
  • PipPipPipPipPipPip
  • 1,245 posts

Posted 09 June 2008 - 03:06 AM

Good looking on the script ChrisL.
Posted ImageDon't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()

#8 CoePSX

CoePSX

    Polymath

  • Active Members
  • PipPipPipPip
  • 237 posts

Posted 09 June 2008 - 11:36 AM

Nice work! This is great!

You seem to have a habit of putting things in the wrong place. I feel sorry for any female you attempt to have sex with.


#9 ChuckS

ChuckS

    Seeker

  • Active Members
  • 26 posts

Posted 09 June 2008 - 11:41 AM

Excellent job!

#10 martin

martin

    ~~\o/~~~/0\=¬''~~~

  • MVPs
  • 7,199 posts

Posted 09 June 2008 - 09:21 PM

Updated.. thanks Martin!

That's ok. It's even better now ChrisL.

The main gui caption is drawn as inactive, presumably because the focus is on one of the child windows. One way to make it look active is like this.
$gui1 = Guicreate("Sample Gui",....; as before but have a handle reference . .  GuiRegisterMsg($WM_NCACTIVATE,"SetDrawnActive") . . . Func SetDrawnActive($hWnd, $iMsg,$Wparam)   If $hWnd = $Gui1 then    If Not $Wparam then return 1   EndIf EndFunc


But this doesn't affect another problem. If the gui is partly covered by another window you need to click on a child window to bring it back to the front. Clicking on the caption bar or the main gui has no effect.
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

#11 ChrisL

ChrisL

    Mass Spanner!

  • Active Members
  • PipPipPipPipPipPip
  • 1,746 posts

Posted 09 June 2008 - 10:57 PM

That's ok. It's even better now ChrisL.

The main gui caption is drawn as inactive, presumably because the focus is on one of the child windows. One way to make it look active is like this.

$gui1 = Guicreate("Sample Gui",....; as before but have a handle reference . .  GuiRegisterMsg($WM_NCACTIVATE,"SetDrawnActive") . . . Func SetDrawnActive($hWnd, $iMsg,$Wparam)   If $hWnd = $Gui1 then    If Not $Wparam then return 1   EndIf EndFunc


But this doesn't affect another problem. If the gui is partly covered by another window you need to click on a child window to bring it back to the front. Clicking on the caption bar or the main gui has no effect.

Really :) I don't think I'm seeing that on my laptop (the overlap bit I mean)

Edited by ChrisL, 09 June 2008 - 10:59 PM.


#12 martin

martin

    ~~\o/~~~/0\=¬''~~~

  • MVPs
  • 7,199 posts

Posted 09 June 2008 - 11:29 PM

Really :) I don't think I'm seeing that on my laptop (the overlap bit I mean)

No, you won't. Apologies, I had completely forgotten that I'd set the extended style of the main Gui to $WS_EX_NOACTIVATE as an experiment.
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

#13 JustinMeyer

JustinMeyer

    Wayfarer

  • Active Members
  • Pip
  • 67 posts

Posted 19 June 2008 - 02:12 AM

I am using wondering if anyone else is having the problem of the control(s) set transparent with this function
taking all the focus? Every time I try to click another button in my gui the focus goes directly to my transparent
input box.
Posted Image

#14 Kiti

Kiti

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 301 posts

Posted 21 June 2008 - 01:43 PM

I want to make a transparent label that respond to clicks, but what I get is a gray box (the Form), and under it the actual transparent button. I don't want that form to be visible. Do you know how to make it invisible, or how to change that decalation, so I'll put the form off the screen, with a negative coordinate, and increase the decalation between it and the actual transparent button, so it will be on the screen? :)

Edit: I forgot my script :P
#include <GUIConstants.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) $Form1 = GUICreate("Form1", 36, 17, 284, 0, BitOR($WS_POPUP, $WS_SYSMENU)) _GuiCtrlMakeTrans(-1, 1) $Label1 = GUICtrlCreateLabel("Label1", 0, 0, 36, 17) GUICtrlSetOnEvent(-1, "Label1Click") _GuiCtrlMakeTrans(-1, 1) GUISetState(@SW_SHOW) While 1     Sleep(100) WEnd Func Label1Click()     MsgBox(48, "", "Yeay!!") EndFunc   ;==>Label1Click

Edit2: Ok, I've got it, I also have to make the label with negative coords. So... the GUI itself cannot be made transparent, right? :P

Edited by Kiti, 21 June 2008 - 02:11 PM.


#15 ludocus

ludocus

    Possibly inventive crap going on right here

  • Active Members
  • PipPipPipPipPipPip
  • 664 posts

Posted 27 June 2008 - 06:03 PM

I would change the name in: _GUICtrlSetTrans

#16 TheMna

TheMna

    Seeker

  • Active Members
  • 8 posts

Posted 16 July 2008 - 07:21 PM

Currently, I have a background picture on my GUI and I'd like to have the labels background translucent to highlight them a bit. If I wanted to get a white translucent background label onto a GUI with opaque font, how should I go about it? I tried using the function to create a translucent white label with no text, and then putting another label in the same position with the text (also tried guictrlsetstate with $ontop), but the text remains faded. Really neat little function you got there btw :muttley:

#17 ChrisL

ChrisL

    Mass Spanner!

  • Active Members
  • PipPipPipPipPipPip
  • 1,746 posts

Posted 17 July 2008 - 07:54 AM

Currently, I have a background picture on my GUI and I'd like to have the labels background translucent to highlight them a bit. If I wanted to get a white translucent background label onto a GUI with opaque font, how should I go about it? I tried using the function to create a translucent white label with no text, and then putting another label in the same position with the text (also tried guictrlsetstate with $ontop), but the text remains faded. Really neat little function you got there btw :muttley:


Then it's not my script you need, just create a standard label and use GuiCtrlSetBkColor($label,$GUI_BKCOLOR_TRANSPARENT)

#18 TheMna

TheMna

    Seeker

  • Active Members
  • 8 posts

Posted 17 July 2008 - 08:20 PM

Then it's not my script you need, just create a standard label and use GuiCtrlSetBkColor($label,$GUI_BKCOLOR_TRANSPARENT)


Thats what I've been using, but I wanted to have it translucent, not transparent.

#19 martin

martin

    ~~\o/~~~/0\=¬''~~~

  • MVPs
  • 7,199 posts

Posted 17 July 2008 - 10:00 PM

@ChrisL
In your example in the first post there is a 20 pixel offset due to the vertical height of the Menu. This means that a control created without the _GuiCtrlMakeTrans function will not be at the same vertical height as a control which does use the _GuiCtrlMakeTRans function but which uses the same x,y coordinates.
So I thought perhaps the function aught to have a way to find the vertical offset so that people wouldn't have to work out the 20 pixel size or whatever.
Maybe this would do it
Func GetVertOffset($hgui) ;Const $SM_CYCAPTION = 4     Const $SM_CXFIXEDFRAME = 7     Local $wtitle, $wclient, $wsize,$wside,$ans     $wclient = WinGetClientSize($hgui)     $wsize = WinGetPos($hgui)     $wtitle = DllCall('user32.dll', 'int', 'GetSystemMetrics', 'int', $SM_CYCAPTION)     $wside = DllCall('user32.dll', 'int', 'GetSystemMetrics', 'int', $SM_CXFIXEDFRAME)     $ans = $wsize[3] - $wclient[1] - $wtitle[0] - 2 * $wside[0]     Return $ans EndFunc  ;==>GetVertOffset

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

#20 JustinMeyer

JustinMeyer

    Wayfarer

  • Active Members
  • Pip
  • 67 posts

Posted 18 July 2008 - 03:36 AM

Func GetVertOffset($hgui) ;Const $SM_CYCAPTION = 4     Const $SM_CXFIXEDFRAME = 7     Local $wtitle, $wclient, $wsize,$wside,$ans     $wclient = WinGetClientSize($hgui)     $wsize = WinGetPos($hgui)     $wtitle = DllCall('user32.dll', 'int', 'GetSystemMetrics', 'int', $SM_CYCAPTION)     $wside = DllCall('user32.dll', 'int', 'GetSystemMetrics', 'int', $SM_CXFIXEDFRAME)     $ans = $wsize[3] - $wclient[1] - $wtitle[0] - 2 * $wside[0]     Return $ans EndFunc ;==>GetVertOffset

Thank You, Thank You, Thank You! Man this is cool Martin. I have no idea how to use DLLs (yet) being a noob and all but this is great. You helped me solve one of my
problems with a gui I am working on using lod3ns PNG GUI. You can take a look here.
Posted Image




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users