ChrisL Posted June 8, 2008 Share Posted June 8, 2008 (edited) 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 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 expandcollapse popup#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 June 9, 2008 by ChrisL kklee69 1 [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
Andreik Posted June 8, 2008 Share Posted June 8, 2008 Thanks ChrisL! Work fine for me. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
martin Posted June 8, 2008 Share Posted June 8, 2008 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. Link to comment Share on other sites More sharing options...
GHOSTSKIKDA Posted June 8, 2008 Share Posted June 8, 2008 very nice work _____________ [center]I LOVE ALGERIA .... ;-)[/center] Link to comment Share on other sites More sharing options...
Kip Posted June 8, 2008 Share Posted June 8, 2008 (edited) doesn't this also work with standard UDF controls. (Because those controls are also windows ($WS_POPUP)) Edited June 9, 2008 by Kip MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API. Link to comment Share on other sites More sharing options...
ChrisL Posted June 8, 2008 Author Share Posted June 8, 2008 Updated.. thanks Martin! [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
WeMartiansAreFriendly Posted June 9, 2008 Share Posted June 9, 2008 Good looking on the script ChrisL. Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet() Link to comment Share on other sites More sharing options...
CoePSX Posted June 9, 2008 Share Posted June 9, 2008 Nice work! This is great! [quote name='Valik' post='301213' date='Jan 31 2007, 10:36 PM']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.[/quote][font="Lucida Sans Unicode"]╔══════════════════════════════╗║░░██░░░░░░░░██░░███░░░████░░░█║║░█░░█░░██░░█░░█░█░░█░█░░░░█░█░║║░█░░░░█░░█░████░███░░░██░░░█░░║║░█░░█░█░░█░█░░░░█░░░░░░░█░█░█░║║░░██░░░██░░░██░░█░░░░███░█░░░█║╚══════════════════════════════╝[/font] Link to comment Share on other sites More sharing options...
ChuckS Posted June 9, 2008 Share Posted June 9, 2008 Excellent job! Link to comment Share on other sites More sharing options...
martin Posted June 9, 2008 Share Posted June 9, 2008 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. Link to comment Share on other sites More sharing options...
ChrisL Posted June 9, 2008 Author Share Posted June 9, 2008 (edited) 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 June 9, 2008 by ChrisL [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
martin Posted June 9, 2008 Share Posted June 9, 2008 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. Link to comment Share on other sites More sharing options...
JustinMeyer Posted June 19, 2008 Share Posted June 19, 2008 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. Link to comment Share on other sites More sharing options...
Kiti Posted June 21, 2008 Share Posted June 21, 2008 (edited) 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 #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 ;==>Label1ClickEdit2: Ok, I've got it, I also have to make the label with negative coords. So... the GUI itself cannot be made transparent, right? Edited June 21, 2008 by Kiti Think outside the box.My Cool Lego Technic Website -- see walking bipeds and much more!My YouTube account -- see cool physics experimentsMy scripts:Minesweeper bot: Solves advanced level in 1 second (no registry edit), very improved GUI, 4 solving stylesCan't go to the toilet because of your kids closing your unsaved important work? - Make a specific window uncloseableCock Shooter Bot -- 30 headshots out of 30 Link to comment Share on other sites More sharing options...
ludocus Posted June 27, 2008 Share Posted June 27, 2008 I would change the name in: _GUICtrlSetTrans Link to comment Share on other sites More sharing options...
TheMna Posted July 16, 2008 Share Posted July 16, 2008 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 Link to comment Share on other sites More sharing options...
ChrisL Posted July 17, 2008 Author Share Posted July 17, 2008 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 muttleyThen it's not my script you need, just create a standard label and use GuiCtrlSetBkColor($label,$GUI_BKCOLOR_TRANSPARENT) [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
TheMna Posted July 17, 2008 Share Posted July 17, 2008 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. Link to comment Share on other sites More sharing options...
martin Posted July 17, 2008 Share Posted July 17, 2008 @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. Link to comment Share on other sites More sharing options...
JustinMeyer Posted July 18, 2008 Share Posted July 18, 2008 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now