Cybernetic Posted June 22, 2013 Posted June 22, 2013 Hello everyone, Ive searched the forums for this to no avail, everything i find is way over the top complicated. All i need is a code that makes an image control be able to be set to a transparent value. IE: 50. Is this possible without 1000 lines of complex code? thank you
BrewManNH Posted June 22, 2013 Posted June 22, 2013 Not that I have a way of doing this, but what's wrong with 1000 lines of code if it accomplishes what you want? It's usually nothing more than copying it into your script and calling the function, usually hardly any typing needed. BTW, it's hardly ever more than 50 lines of code to accomplish most tasks like that. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. 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 editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
Cybernetic Posted June 22, 2013 Author Posted June 22, 2013 Thanks for the reply. If its only 50 lines of code or so, can i please have an example? Would be much appreciated!
PhoenixXL Posted June 22, 2013 Posted June 22, 2013 (edited) Have a look expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> $hGUI = GUICreate("My GUI edit") ; will create a dialog box that when displayed is centered $iPic = GUICtrlCreatePic(StringReplace(@AutoItExe, "Autoit3.exe", "Examples\GUI\msoobe.jpg"), 2, 2, 394, 268) _GuiCtrlMakeTrans($iPic, 100) GUISetState() While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _GuiCtrlMakeTrans($iCtrlID, $iTrans = 255) Global $pHwnd, $nHwnd, $aPos, $a $hWnd = GUICtrlGetHandle($iCtrlID);Get the control handle $pHwnd = _WinAPI_GetParent($hWnd);Get the parent Gui Handle $aPos = ControlGetPos($pHwnd, "", $hWnd);Get the current pos of the control $nHwnd = GUICreate("", $aPos[2], $aPos[3], $aPos[0], $aPos[1], 0x80000000, 0x00080000 + 0x00000040, $pHwnd);greate a gui in the position of the control _WinAPI_SetParent($hWnd, $nHwnd);change the parent of the control to the new gui ControlMove($nHwnd, '', $hWnd, 0, 0);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 GUISwitch($pHwnd);switch back to the parent Gui Return $nHwnd;Return the handle for the new Child gui EndFunc ;==>_GuiCtrlMakeTrans >Reference Less than 30lines of code if you remove blank lines - Regards Edited June 22, 2013 by PhoenixXL My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.
Cybernetic Posted June 22, 2013 Author Posted June 22, 2013 (edited) Hi Phoenix, that works great, however, if i want to switch transparency values on the control, the control manages to move out of place and get all wierd? check the code that i modified. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> local $action $hGUI = GUICreate("My GUI edit") ; will create a dialog box that when displayed is centered $iPic = GUICtrlCreatePic(StringReplace(@AutoItExe, "Autoit3.exe", "Examples\GUI\msoobe.jpg"), 2, 2, 100, 100) _GuiCtrlMakeTrans($iPic, 100) GUISetState() hotkeyset("{1}", "test1") hotkeyset("{2}", "test2") While $action <> $GUI_EVENT_CLOSE $action = GUIGetMsg() WEnd func test1() _GuiCtrlMakeTrans($iPic, 155) endfunc func test2() _GuiCtrlMakeTrans($iPic, 100) endfunc Func _GuiCtrlMakeTrans($iCtrlID, $iTrans = 255) Global $pHwnd, $nHwnd, $aPos, $a $hWnd = GUICtrlGetHandle($iCtrlID);Get the control handle $pHwnd = _WinAPI_GetParent($hWnd);Get the parent Gui Handle $aPos = ControlGetPos($pHwnd, "", $hWnd);Get the current pos of the control $nHwnd = GUICreate("", $aPos[2], $aPos[3], $aPos[0], $aPos[1], 0x80000000, 0x00080000 + 0x00000040, $pHwnd);greate a gui in the position of the control _WinAPI_SetParent($hWnd, $nHwnd);change the parent of the control to the new gui ControlMove($nHwnd, '', $hWnd, 0, 0);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 GUISwitch($pHwnd);switch back to the parent Gui Return $nHwnd;Return the handle for the new Child gui EndFunc ;==>_GuiCtrlMakeTrans Hitting the 1 and 2 key will change the transparency of the control, but doing so will screw it up aswell. Edited June 22, 2013 by Cybernetic
PhoenixXL Posted June 23, 2013 Posted June 23, 2013 (edited) You need to understand the concept. You can't create a transparent pic control through direct control creation therefore a child window was created that perfectly contained the control and transparency of the child window rather than the control was set to the desired value. Now if you want to change the transparency of the window you have to change it explicitly, otherwise calling the function again would create another Child GUI. Have a look at the following, expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> Local $action $hGUI = GUICreate("My GUI edit") ; will create a dialog box that when displayed is centered GUICtrlCreatePic(StringReplace(@AutoItExe, "Autoit3.exe", "Examples\GUI\msoobe.jpg"), 2, 2, 100, 100) Global $hTransparentPic = _GuiCtrlMakeTrans(-1, 100) GUISetState() HotKeySet("{1}", "test1") HotKeySet("{2}", "test2") While $action <> $GUI_EVENT_CLOSE $action = GUIGetMsg() WEnd Func test1() _ChangeTransparency($hTransparentPic, 155) EndFunc ;==>test1 Func test2() _ChangeTransparency($hTransparentPic, 100) EndFunc ;==>test2 Func _GuiCtrlMakeTrans($iCtrlID, $iTrans = 255) Global $pHwnd, $nHwnd, $aPos, $a $hWnd = GUICtrlGetHandle($iCtrlID);Get the control handle $pHwnd = _WinAPI_GetParent($hWnd);Get the parent Gui Handle $aPos = ControlGetPos($pHwnd, "", $hWnd);Get the current pos of the control $nHwnd = GUICreate("", $aPos[2], $aPos[3], $aPos[0], $aPos[1], 0x80000000, 0x00080000 + 0x00000040, $pHwnd);greate a gui in the position of the control _WinAPI_SetParent($hWnd, $nHwnd);change the parent of the control to the new gui ControlMove($nHwnd, '', $hWnd, 0, 0);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 GUISwitch($pHwnd);switch back to the parent Gui Return $nHwnd;Return the handle for the new Child gui EndFunc ;==>_GuiCtrlMakeTrans Func _ChangeTransparency($hCtrl, $iTrans) WinSetTrans($hCtrl, "",$iTrans) ;change the transparency of the window. EndFunc Try to learn and understand the code. Regards Edited June 23, 2013 by PhoenixXL My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.
Cybernetic Posted June 23, 2013 Author Posted June 23, 2013 Phoenix, i do understand the concept, i was only wondering if there was a work around to avoid the GUI screwing up due to rapid change of the transparency. Seems like you provided a solution and so i thank you! thank you for the help, much appreciated!
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