TwoCanoe Posted July 12 Posted July 12 (edited) Hello To further explain what I mean: Here’s an example of the This keyword in javascript: https://www.w3schools.com/js/js_this.asp And an example of the This keyword in C#: https://www.geeksforgeeks.org/c-sharp/c-sharp-this-keyword/ I haven’t encountered this type of inheritance so far, using AutoIt scripting. Here is an example script: expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> HotKeySet("{Esc}", "Terminate") Local $gShowChild = False Local $gForm1, $gButton1, $gButton2, $gButton3, $gButton4, $gButton5, $gButton6, $gButton7, $gButton8, $gButton9 StartGUI() ; Main GUI Func StartGUI() Local $GuiW = 260 Local $GuiH = 260 Local $GuiX = @DesktopWidth/2 - $GuiW/2 Local $GuiY = @DesktopHeight/2 - $GuiH/2 $gForm1 = GUICreate("Transparent Test", $GuiW, $GuiH, $GuiX, $GuiY) $gButton1 = GUICtrlCreateButton("1", 20, 20, 60, 60) $gButton2 = GUICtrlCreateButton("2", 100, 20, 60, 60) $gButton3 = GUICtrlCreateButton("3", 180, 20, 60, 60) $gButton4 = GUICtrlCreateButton("4", 20, 100, 60, 60) $gButton5 = GUICtrlCreateButton("5", 100, 100, 60, 60) $gButton6 = GUICtrlCreateButton("6", 180, 100, 60, 60) $gButton7 = GUICtrlCreateButton("7", 20, 180, 60, 60) $gButton8 = GUICtrlCreateButton("8", 100, 180, 60, 60) $gButton9 = GUICtrlCreateButton("9", 180, 180, 60, 60) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $gButton1 ShowInfo($gButton1) ; is ShowInfo(This) possible? Case $gButton2 ShowInfo($gButton2) ; is ShowInfo(This) possible? Case $gButton3 ShowInfo($gButton3) ; is ShowInfo(This) possible? Case $gButton4 ShowInfo($gButton4) ; is ShowInfo(This) possible? Case $gButton5 ShowInfo($gButton5) ; is ShowInfo(This) possible? Case $gButton6 ShowInfo($gButton6) ; is ShowInfo(This) possible? Case $gButton7 ShowInfo($gButton7) ; is ShowInfo(This) possible? Case $gButton8 ShowInfo($gButton8) ; is ShowInfo(This) possible? Case $gButton9 ShowInfo($gButton9) ; is ShowInfo(This) possible? Case $GUI_EVENT_MINIMIZE, $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete($gForm1) EndFunc ; Child GUI Func ShowInfo($control) $gShowChild = True Local $Pos = ControlGetPos($gForm1, "", $control) ; Get position of button pressed Local $GuiX = $Pos[0] Local $GuiY = $Pos[1] Local $GuiW = 235 Local $GuiH = 125 Local $info = GUICtrlRead($control) $gForm2 = GUICreate("Show Info: " & $info, $GuiW, $GuiH, $GuiX, $GuiY, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $gForm1) GUISetBkColor(0xABCDEF); $gBordersLabel = GUICtrlCreateLabel("", 0, 0, $GuiW, $GuiH) GUICtrlSetBkColor(-1, 0x44BB00) GUICtrlSetState(-1, $GUI_DISABLE) $gTransLabel1 = GUICtrlCreateLabel("", 60, 0, 180, 55) ; Upper right transparency GUICtrlSetBkColor(-1, 0xABCDEF) $gTransLabel2 = GUICtrlCreateLabel("", 0, 60, 55, 140) ; Lower left transparency GUICtrlSetBkColor(-1, 0xABCDEF) $gTransLabel3 = GUICtrlCreateLabel("", 5, 5, 50, 50) ; Target button transparency GUICtrlSetBkColor(-1, 0xABCDEF) GUICtrlSetState(-1, $GUI_DISABLE) $gBackground = GUICtrlCreateLabel("", 60, 60, 170, 60) GUICtrlSetBkColor(-1, 0x444444) GUICtrlSetState(-1, $GUI_DISABLE) $gLabelInfo = GUICtrlCreateLabel("Button Pressed: " & $info, 70, 70, 100, 40, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetBkColor(-1, 0x444444) GUICtrlSetColor(-1, 0x88FF00) $gLabelOK = GUICtrlCreateLabel("OK", 180, 70, 40, 40, BitOR($SS_CENTER, $SS_CENTERIMAGE)) ; Using a label, a button causes transparency issues GUICtrlSetBkColor(-1, 0xDDDDDD) _WinAPI_SetLayeredWindowAttributes($gForm2, 0xABCDEF, 255) GUISetState(@SW_SHOW) While $gShowChild If Not WinActive($gForm2) Then ExitLoop ; 1. Allows click on other main GUI buttons, 2. Deletes the child window if main GUI is not active Switch GUIGetMsg() Case $gLabelOK ExitLoop EndSwitch Wend $gShowChild = False GUIDelete($gForm2) EndFunc Func Terminate() If $gShowChild = True Then $gShowChild = False Else Exit EndIf EndFunc If ShowInfo(This) isn’t possible, is there another way? Edited July 12 by TwoCanoe Tidy up!
Nine Posted July 12 Posted July 12 Not directly, but this : expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> StartGUI() ; Main GUI Func StartGUI() Local $gForm1, $gButton1, $gButton2, $gButton3, $gButton4, $gButton5, $gButton6, $gButton7, $gButton8, $gButton9 Local $GuiW = 260 Local $GuiH = 260 Local $GuiX = @DesktopWidth / 2 - $GuiW / 2 Local $GuiY = @DesktopHeight / 2 - $GuiH / 2 $gForm1 = GUICreate("Transparent Test", $GuiW, $GuiH, $GuiX, $GuiY) $gButton1 = GUICtrlCreateButton("1", 20, 20, 60, 60) $gButton2 = GUICtrlCreateButton("2", 100, 20, 60, 60) $gButton3 = GUICtrlCreateButton("3", 180, 20, 60, 60) $gButton4 = GUICtrlCreateButton("4", 20, 100, 60, 60) $gButton5 = GUICtrlCreateButton("5", 100, 100, 60, 60) $gButton6 = GUICtrlCreateButton("6", 180, 100, 60, 60) $gButton7 = GUICtrlCreateButton("7", 20, 180, 60, 60) $gButton8 = GUICtrlCreateButton("8", 100, 180, 60, 60) $gButton9 = GUICtrlCreateButton("9", 180, 180, 60, 60) GUISetState(@SW_SHOW) While True $iMsg = GUIGetMsg() Switch $iMsg Case $gButton1 To $gButton9 ShowInfo($iMsg) ; is ShowInfo(This) possible? Case $GUI_EVENT_MINIMIZE, $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete($gForm1) EndFunc ;==>StartGUI ; Child GUI Func ShowInfo($control) ConsoleWrite($control & @CRLF) EndFunc ;==>ShowInfo “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
TwoCanoe Posted July 12 Author Posted July 12 Thanks for the reply Nine. You might be on the right track. Your example returns a number for each button. I guess it is a GUI id number. Though the numbers are consistent so maybe usable. Possibly using Eval() in the child script (?): expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> HotKeySet("{Esc}", "Terminate") Local $gShowChild = False Local $gForm1, $gButton1, $gButton2, $gButton3, $gButton4, $gButton5, $gButton6, $gButton7, $gButton8, $gButton9 StartGUI() ; Main GUI Func StartGUI() Local $GuiW = 260 Local $GuiH = 260 Local $GuiX = @DesktopWidth/2 - $GuiW/2 Local $GuiY = @DesktopHeight/2 - $GuiH/2 $gForm1 = GUICreate("Transparent Test", $GuiW, $GuiH, $GuiX, $GuiY) $gButton1 = GUICtrlCreateButton("1", 20, 20, 60, 60) $gButton2 = GUICtrlCreateButton("2", 100, 20, 60, 60) $gButton3 = GUICtrlCreateButton("3", 180, 20, 60, 60) $gButton4 = GUICtrlCreateButton("4", 20, 100, 60, 60) $gButton5 = GUICtrlCreateButton("5", 100, 100, 60, 60) $gButton6 = GUICtrlCreateButton("6", 180, 100, 60, 60) $gButton7 = GUICtrlCreateButton("7", 20, 180, 60, 60) $gButton8 = GUICtrlCreateButton("8", 100, 180, 60, 60) $gButton9 = GUICtrlCreateButton("9", 180, 180, 60, 60) GUISetState(@SW_SHOW) While 1 $iMsg = GUIGetMsg() ; CHANGED HERE Switch $iMsg ; CHANGED HERE Case $gButton1 To $gButton9 ; CHANGED HERE ShowInfo("$gButton" & string($iMsg -2)) ; CHANGED HERE Case $GUI_EVENT_MINIMIZE, $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete($gForm1) EndFunc ; Child GUI Func ShowInfo($control) Local $evalControl = Eval($control) $gShowChild = True Local $Pos = ControlGetPos($gForm1, "", $evalControl) ; CHANGED HERE - Works Local $GuiX = $Pos[0] Local $GuiY = $Pos[1] Local $GuiW = 235 Local $GuiH = 125 Local $info = GUICtrlRead($evalControl) ; CHANGED HERE - Does not work! $gForm2 = GUICreate("Show Info: " & $info, $GuiW, $GuiH, $GuiX, $GuiY, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $gForm1) GUISetBkColor(0xABCDEF); $gBordersLabel = GUICtrlCreateLabel("", 0, 0, $GuiW, $GuiH) GUICtrlSetBkColor(-1, 0x44BB00) GUICtrlSetState(-1, $GUI_DISABLE) $gTransLabel1 = GUICtrlCreateLabel("", 60, 0, 180, 55) ; Upper right transparency GUICtrlSetBkColor(-1, 0xABCDEF) $gTransLabel2 = GUICtrlCreateLabel("", 0, 60, 55, 140) ; Lower left transparency GUICtrlSetBkColor(-1, 0xABCDEF) $gTransLabel3 = GUICtrlCreateLabel("", 5, 5, 50, 50) ; Target button transparency GUICtrlSetBkColor(-1, 0xABCDEF) GUICtrlSetState(-1, $GUI_DISABLE) $gBackground = GUICtrlCreateLabel("", 60, 60, 170, 60) GUICtrlSetBkColor(-1, 0x444444) GUICtrlSetState(-1, $GUI_DISABLE) $gLabelInfo = GUICtrlCreateLabel("Button Pressed: " & $info, 70, 70, 100, 40, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetBkColor(-1, 0x444444) GUICtrlSetColor(-1, 0x88FF00) $gLabelOK = GUICtrlCreateLabel("OK", 180, 70, 40, 40, BitOR($SS_CENTER, $SS_CENTERIMAGE)) ; Using a label, a button causes transparency issues GUICtrlSetBkColor(-1, 0xDDDDDD) _WinAPI_SetLayeredWindowAttributes($gForm2, 0xABCDEF, 255) GUISetState(@SW_SHOW) While $gShowChild If Not WinActive($gForm2) Then ExitLoop ; 1. Allows click on other main GUI buttons, 2. Deletes the child window if main GUI is not active Switch GUIGetMsg() Case $gLabelOK ExitLoop EndSwitch Wend $gShowChild = False GUIDelete($gForm2) EndFunc Func Terminate() If $gShowChild = True Then $gShowChild = False Else Exit EndIf EndFunc Line 56 works, but line 62 does not. I'll keep playing and see what happens. Will post any improvements.
Nine Posted July 12 Posted July 12 Don't use that eval approach, there is absolutely no reason for doing so. Just use the control id, and you will be fine. By using the eval you are returning a string which will not work with GUICtrlRead (or any GUICtrl* functions). Control* functions will work perfectly well with the ID. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
TwoCanoe Posted July 12 Author Posted July 12 You are absolutely right Nine. I didn't realize that the control ID could be used like that. Thanks again Nine. Amended, working example: expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> HotKeySet("{Esc}", "Terminate") Local $gShowChild = False Local $gForm1, $gButton1, $gButton2, $gButton3, $gButton4, $gButton5, $gButton6, $gButton7, $gButton8, $gButton9 StartGUI() ; Main GUI Func StartGUI() Local $GuiW = 260 Local $GuiH = 260 Local $GuiX = @DesktopWidth/2 - $GuiW/2 Local $GuiY = @DesktopHeight/2 - $GuiH/2 $gForm1 = GUICreate("Transparent Test", $GuiW, $GuiH, $GuiX, $GuiY) $gButton1 = GUICtrlCreateButton("1", 20, 20, 60, 60) $gButton2 = GUICtrlCreateButton("2", 100, 20, 60, 60) $gButton3 = GUICtrlCreateButton("3", 180, 20, 60, 60) $gButton4 = GUICtrlCreateButton("4", 20, 100, 60, 60) $gButton5 = GUICtrlCreateButton("5", 100, 100, 60, 60) $gButton6 = GUICtrlCreateButton("6", 180, 100, 60, 60) $gButton7 = GUICtrlCreateButton("7", 20, 180, 60, 60) $gButton8 = GUICtrlCreateButton("8", 100, 180, 60, 60) $gButton9 = GUICtrlCreateButton("9", 180, 180, 60, 60) GUISetState(@SW_SHOW) While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $gButton1 To $gButton9 ShowInfo($iMsg) ; CHANGED HERE Case $GUI_EVENT_MINIMIZE, $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete($gForm1) EndFunc ; Child GUI Func ShowInfo($controlID) $gShowChild = True Local $Pos = ControlGetPos($gForm1, "", $controlID) Local $GuiX = $Pos[0] Local $GuiY = $Pos[1] Local $GuiW = 235 Local $GuiH = 125 Local $info = GUICtrlRead($controlID) $gForm2 = GUICreate("Show Info: " & $info, $GuiW, $GuiH, $GuiX, $GuiY, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $gForm1) GUISetBkColor(0xABCDEF); $gBordersLabel = GUICtrlCreateLabel("", 0, 0, $GuiW, $GuiH) GUICtrlSetBkColor(-1, 0x44BB00) GUICtrlSetState(-1, $GUI_DISABLE) $gTransLabel1 = GUICtrlCreateLabel("", 60, 0, 180, 55) ; Upper right transparency GUICtrlSetBkColor(-1, 0xABCDEF) $gTransLabel2 = GUICtrlCreateLabel("", 0, 60, 55, 140) ; Lower left transparency GUICtrlSetBkColor(-1, 0xABCDEF) $gTransLabel3 = GUICtrlCreateLabel("", 5, 5, 50, 50) ; Target button transparency GUICtrlSetBkColor(-1, 0xABCDEF) GUICtrlSetState(-1, $GUI_DISABLE) $gBackground = GUICtrlCreateLabel("", 60, 60, 170, 60) GUICtrlSetBkColor(-1, 0x444444) GUICtrlSetState(-1, $GUI_DISABLE) $gLabelInfo = GUICtrlCreateLabel("Button Pressed: " & $info, 70, 70, 100, 40, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetBkColor(-1, 0x444444) GUICtrlSetColor(-1, 0x88FF00) $gLabelOK = GUICtrlCreateLabel("OK", 180, 70, 40, 40, BitOR($SS_CENTER, $SS_CENTERIMAGE)) ; Using a label, a button causes transparency issues GUICtrlSetBkColor(-1, 0xDDDDDD) _WinAPI_SetLayeredWindowAttributes($gForm2, 0xABCDEF, 255) GUISetState(@SW_SHOW) While $gShowChild If Not WinActive($gForm2) Then ExitLoop ; 1. Allows click on other main GUI buttons, 2. Deletes the child window if main GUI is not active Switch GUIGetMsg() Case $gLabelOK ExitLoop EndSwitch Wend $gShowChild = False GUIDelete($gForm2) EndFunc Func Terminate() If $gShowChild = True Then $gShowChild = False Else Exit EndIf EndFunc
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