Leaderboard
Popular Content
Showing content with the highest reputation on 12/22/2021 in all areas
-
HTML issuesI assume the error you see in the SciTE console is: $oHyperlink1 ERR When looking at the image of UIASpy, then the code should work. If the code doesn't work anyway, the default procedure is to print the entire element structure of the target window. This is the target window: Note that I have installed a Danish version of ESET Online Scanner. If you test ESET Online Scanner, you can interrupt the scan after a few hundred files and still be allowed to save the log file. If you don't interrupt the scan, it may take a very long time to complete. Element structureYou print the entire element structure of the target window this way: Right-click the target window in the TreeView. Click "Update all childs of element". Right-click the target window in the TreeView again. Click "Create element tree structure". Right-click in the ListView. Select "Copy all items". Paste the copied data into your editor: 0000 Window: ESET Online Scanner 0001 Pane: PerryShadowWnd 0002 Pane: Der blev ikke fundet nogen truslerLykkedes! Scanning er fuldført. Vi har ikke fundet nogen virus eller andre infektioner.Gem scanningslogFortsæt 0003 Pane: Der blev ikke fundet nogen truslerLykkedes! Scanning er fuldført. Vi har ikke fundet nogen virus eller andre infektioner.Gem scanningslogFortsæt 0004 Pane 0005 Pane 0006 Pane 0007 Pane 0008 Button 0009 Button 0010 Button 0011 Pane 0012 Pane: Der blev ikke fundet nogen trusler 0013 Pane 0014 Pane 0015 Pane 0016 Text: Der blev ikke fundet nogen trusler 0017 Pane: Lykkedes! Scanning er fuldført. Vi har ikke fundet nogen virus eller andre infektioner.Gem scanningslog 0018 Pane: Lykkedes! Scanning er fuldført. Vi har ikke fundet nogen virus eller andre infektioner.Gem scanningslog 0019 Pane 0020 Pane: Lykkedes! Scanning er fuldført. Vi har ikke fundet nogen virus eller andre infektioner. 0021 Pane 0022 Pane 0023 Text: Lykkedes! Scanning er fuldført. Vi har ikke fundet nogen virus eller andre infektioner. 0024 Pane 0025 Pane: Gem scanningslog 0026 Pane 0027 Pane 0028 Text 0029 Text: Gem scanningslog 0030 Pane: Fortsæt 0031 Pane 0032 Button: Fortsæt 0033 Pane 0034 Pane You see the issue in line 0029 near bottom of the output. In line 0029 it's a Text control. In UIASpy it's a Hyperlink control. It's actually not a real mistake. Both controls exist in the HTML code. The immediate reason why different control types are identified is that the Text control is identified through an $oRawViewWalker object, while the Hyperlink control is identified via the ElementFromPoint() method of a $oUIAutomation object. But the underlying reason why the control is identified differently depending on the identification method is that the provider code for the control isn't UIA code but HTML code. This issue has already been discussed several times in recent threads and posts e.g. UI Automation on W10 - Get all texts in a Chrome document and in this and the following posts. The important thing here is that when you execute your UIA code (contained in an au3 file), the code is executed in the same way as when executing code through a $oRawViewWalker object. This also means that the most accurate control is the one you see in the control structure above, i.e. the Text control. The hyperlink control in UIASpy is less accurate. It's simply not possible to identify the control. So it's the Text control that you use to click the Hyperlink. UI Automation codeUse the entire element structure to create Sample code. In UIASpy, you generate Sample code as follows: Sample code menu | Initial code | Complete code Click ESET Online Scanner window in treeview to switch to info listview Select the 3 listview items as shown in the picture Right-click one of the 3 selected listview items | Create sample code Click Gem scanningslog Text in treeview to switch to info listview Select the 2 listview items as shown in the picture Right-click one of the 2 selected listview items | Create sample code Due to the issues with uniquely identifying the control, the only option to click the control is probably to use the UIA_MouseClick() function. Sample code menu | Code snippets... | Right-click Activate (give focus to) a window | Create sample code Sample code menu | Code snippets... | Right-click Mouse click in middle of bounding rectangle | Create sample code Right click code listview | Copy all items Paste the code into your editor When the code is ready to run, it should look like this: #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "UIA_Constants.au3" ; Can be copied from UIASpy Includes folder #include "UIA_Functions.au3" ; Can be copied from UIASpy Includes folder ;#include "UIA_SafeArray.au3" ; Can be copied from UIASpy Includes folder ;#include "UIA_Variant.au3" ; Can be copied from UIASpy Includes folder Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtag_IUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement( $pDesktop ) $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition0, $pCondition1, $pAndCondition1 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "#32770", $pCondition0 ) $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_WindowControlTypeId, $pCondition1 ) $oUIAutomation.CreateAndCondition( $pCondition0, $pCondition1, $pAndCondition1 ) If Not $pAndCondition1 Then Return ConsoleWrite( "$pAndCondition1 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition1 OK" & @CRLF ) Local $pCondition2, $pAndCondition2 $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "ESET Online Scanner", $pCondition2 ) $oUIAutomation.CreateAndCondition( $pAndCondition1, $pCondition2, $pAndCondition2 ) If Not $pAndCondition2 Then Return ConsoleWrite( "$pAndCondition2 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition2 OK" & @CRLF ) Local $pWindow1, $oWindow1 $oDesktop.FindFirst( $TreeScope_Children, $pAndCondition2, $pWindow1 ) $oWindow1 = ObjCreateInterface( $pWindow1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement ) If Not IsObj( $oWindow1 ) Then Return ConsoleWrite( "$oWindow1 ERR" & @CRLF ) ConsoleWrite( "$oWindow1 OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition3, $pCondition4, $pAndCondition4 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_TextControlTypeId, $pCondition3 ) $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "Gem scanningslog", $pCondition4 ) $oUIAutomation.CreateAndCondition( $pCondition3, $pCondition4, $pAndCondition4 ) If Not $pAndCondition4 Then Return ConsoleWrite( "$pAndCondition4 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition4 OK" & @CRLF ) Local $pText1, $oText1 $oWindow1.FindFirst( $TreeScope_Descendants, $pAndCondition4, $pText1 ) $oText1 = ObjCreateInterface( $pText1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement ) If Not IsObj( $oText1 ) Then Return ConsoleWrite( "$oText1 ERR" & @CRLF ) ConsoleWrite( "$oText1 OK" & @CRLF ) ; --- Code Snippets --- ConsoleWrite( "--- Code Snippets ---" & @CRLF ) UIA_WinActivate( $oWindow1 ) ConsoleWrite( "UIA_WinActivate( $oWindow1 )" & @CRLF ) ; --- Code Snippets --- ConsoleWrite( "--- Code Snippets ---" & @CRLF ) UIA_MouseClick( $oText1 ) ConsoleWrite( "UIA_MouseClick( $oText1 )" & @CRLF ) EndFunc An execution will generate this SciTE output: $oUIAutomation OK $oDesktop OK --- Find window/control --- $pAndCondition1 OK $pAndCondition2 OK $oWindow1 OK --- Find window/control --- $pAndCondition4 OK $oText1 OK --- Code Snippets --- UIA_WinActivate( $oWindow1 ) --- Code Snippets --- UIA_MouseClick( $oText1 ) But the Hyperlink isn't clicked and the Save As dialog box doesn't open. The reason is that the mouse click is performed far outside the Hyperlink control. The UIA_MouseClick() function calculates the bounding rectangle to click a control. Consider the bounding rectangle in the following two images: w=97 for the Hyperlink control in the first image indicates the correct width to use in the UIA_MouseClick() function. The width of 97 pixels is not that important. The important thing is that the width is set small enough for the mouse click to stay within the Hyperlink control. In the erroneous code above, the width w=799 is used for the Text control in the second image resulting in a mouse click performed far outside the Hyperlink control. This is code for the UIA_MouseClick() function copied from UIA_Functions.au3: ; $fScale is the screen scaling factor ; $fScale values: 1.25, 1.50, ... 4.00 Func UIA_MouseClick( $oElement, $bRight = False, $fScale = 0 ) If Not IsObj( $oElement ) Then Return SetError(1,0,1) ; Rectangle Local $aRect ; l, t, w, h $oElement.GetCurrentPropertyValue( $UIA_BoundingRectanglePropertyId, $aRect ) If Not IsArray( $aRect ) Then Return SetError(1,0,1) If $fScale > 1.00 Then $aRect[0] = Round( $aRect[0] * $fScale ) $aRect[1] = Round( $aRect[1] * $fScale ) $aRect[2] = Round( $aRect[2] * $fScale ) $aRect[3] = Round( $aRect[3] * $fScale ) EndIf ; Click element Local $aPos = MouseGetPos() Local $sButton = Not $bRight ? "primary" : "secondary" DllCall( "user32.dll", "int", "ShowCursor", "bool", False ) MouseClick( $sButton, $aRect[0]+$aRect[2]/2, $aRect[1]+$aRect[3]/2, 1, 0 ) MouseMove( $aPos[0], $aPos[1], 0 ) DllCall( "user32.dll", "int", "ShowCursor", "bool", True ) EndFunc Modify the function this way so that it takes an additional $iBoundRectWidth parameter: ; $fScale is the screen scaling factor ; $fScale values: 1.25, 1.50, ... 4.00 Func UIA_MouseClick1( $oElement, $iBoundRectWidth, $bRight = False, $fScale = 0 ) If Not IsObj( $oElement ) Then Return SetError(1,0,1) ; Rectangle Local $aRect ; l, t, w, h $oElement.GetCurrentPropertyValue( $UIA_BoundingRectanglePropertyId, $aRect ) If Not IsArray( $aRect ) Then Return SetError(1,0,1) $aRect[2] = $iBoundRectWidth If $fScale > 1.00 Then $aRect[0] = Round( $aRect[0] * $fScale ) $aRect[1] = Round( $aRect[1] * $fScale ) $aRect[2] = Round( $aRect[2] * $fScale ) $aRect[3] = Round( $aRect[3] * $fScale ) EndIf ; Click element Local $aPos = MouseGetPos() Local $sButton = Not $bRight ? "primary" : "secondary" DllCall( "user32.dll", "int", "ShowCursor", "bool", False ) MouseClick( $sButton, $aRect[0]+$aRect[2]/2, $aRect[1]+$aRect[3]/2, 1, 0 ) MouseMove( $aPos[0], $aPos[1], 0 ) DllCall( "user32.dll", "int", "ShowCursor", "bool", True ) EndFunc Insert and use UIA_MouseClick1() in the existing code as follows: #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "UIA_Constants.au3" ; Can be copied from UIASpy Includes folder #include "UIA_Functions.au3" ; Can be copied from UIASpy Includes folder ;#include "UIA_SafeArray.au3" ; Can be copied from UIASpy Includes folder ;#include "UIA_Variant.au3" ; Can be copied from UIASpy Includes folder Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtag_IUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement( $pDesktop ) $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition0, $pCondition1, $pAndCondition1 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "#32770", $pCondition0 ) $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_WindowControlTypeId, $pCondition1 ) $oUIAutomation.CreateAndCondition( $pCondition0, $pCondition1, $pAndCondition1 ) If Not $pAndCondition1 Then Return ConsoleWrite( "$pAndCondition1 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition1 OK" & @CRLF ) Local $pCondition2, $pAndCondition2 $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "ESET Online Scanner", $pCondition2 ) $oUIAutomation.CreateAndCondition( $pAndCondition1, $pCondition2, $pAndCondition2 ) If Not $pAndCondition2 Then Return ConsoleWrite( "$pAndCondition2 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition2 OK" & @CRLF ) Local $pWindow1, $oWindow1 $oDesktop.FindFirst( $TreeScope_Children, $pAndCondition2, $pWindow1 ) $oWindow1 = ObjCreateInterface( $pWindow1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement ) If Not IsObj( $oWindow1 ) Then Return ConsoleWrite( "$oWindow1 ERR" & @CRLF ) ConsoleWrite( "$oWindow1 OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition3, $pCondition4, $pAndCondition4 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_TextControlTypeId, $pCondition3 ) $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "Gem scanningslog", $pCondition4 ) ; <<<< Edit text to your own language $oUIAutomation.CreateAndCondition( $pCondition3, $pCondition4, $pAndCondition4 ) If Not $pAndCondition4 Then Return ConsoleWrite( "$pAndCondition4 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition4 OK" & @CRLF ) Local $pText1, $oText1 $oWindow1.FindFirst( $TreeScope_Descendants, $pAndCondition4, $pText1 ) $oText1 = ObjCreateInterface( $pText1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement ) If Not IsObj( $oText1 ) Then Return ConsoleWrite( "$oText1 ERR" & @CRLF ) ConsoleWrite( "$oText1 OK" & @CRLF ) ; --- Code Snippets --- ConsoleWrite( "--- Code Snippets ---" & @CRLF ) UIA_WinActivate( $oWindow1 ) ConsoleWrite( "UIA_WinActivate( $oWindow1 )" & @CRLF ) ; --- Code Snippets --- ConsoleWrite( "--- Code Snippets ---" & @CRLF ) ;UIA_MouseClick( $oText1 ) UIA_MouseClick1( $oText1, 97 ) ;ConsoleWrite( "UIA_MouseClick( $oText1 )" & @CRLF ) ConsoleWrite( "UIA_MouseClick1( $oText1, 97 )" & @CRLF ) EndFunc ; $fScale is the screen scaling factor ; $fScale values: 1.25, 1.50, ... 4.00 Func UIA_MouseClick1( $oElement, $iBoundRectWidth, $bRight = False, $fScale = 0 ) If Not IsObj( $oElement ) Then Return SetError(1,0,1) ; Rectangle Local $aRect ; l, t, w, h $oElement.GetCurrentPropertyValue( $UIA_BoundingRectanglePropertyId, $aRect ) If Not IsArray( $aRect ) Then Return SetError(1,0,1) $aRect[2] = $iBoundRectWidth If $fScale > 1.00 Then $aRect[0] = Round( $aRect[0] * $fScale ) $aRect[1] = Round( $aRect[1] * $fScale ) $aRect[2] = Round( $aRect[2] * $fScale ) $aRect[3] = Round( $aRect[3] * $fScale ) EndIf ; Click element Local $aPos = MouseGetPos() Local $sButton = Not $bRight ? "primary" : "secondary" DllCall( "user32.dll", "int", "ShowCursor", "bool", False ) MouseClick( $sButton, $aRect[0]+$aRect[2]/2, $aRect[1]+$aRect[3]/2, 1, 0 ) MouseMove( $aPos[0], $aPos[1], 0 ) DllCall( "user32.dll", "int", "ShowCursor", "bool", True ) EndFunc An execution will generate this SciTE output: $oUIAutomation OK $oDesktop OK --- Find window/control --- $pAndCondition1 OK $pAndCondition2 OK $oWindow1 OK --- Find window/control --- $pAndCondition4 OK $oText1 OK --- Code Snippets --- UIA_WinActivate( $oWindow1 ) --- Code Snippets --- UIA_MouseClick1( $oText1, 97 ) And now the Hyperlink control is clicked and the Save As dialog box opens: 7z-fileESETOnlineScanner.7z3 points
-
Yes, it can be done with GUI/Tray Menu with icons and colors and the updates in post 289.1 point
-
You are Superman. Thank you.1 point
-
... Surfing the net my eye fell on a device called "Divoom". It reminded me of a little toy I liked to play when I went to kindergarten (more than 55 years ago... ), it was called "Chiodini colorati". So I made this little script to emulate it, ...maybe some kids will have fun playing with it. The attached zip file contains the script and also some "pixel art" files ready to be loaded. P.S. Thanks to @KaFu for it's _WinSetClientSize() function and to @InunoTaishou for it's CaptureWindow() function (references are in the script) #include <WinAPISysWin.au3> #include <File.au3> #include <WindowsConstants.au3> #include <GDIPlus.au3> #cs ----------------------------------------- "Chiodini colorati" (colored thumb tacks) a little toy for the kids 16x16 pixel art sheet Programmed by Gianni Addiego - Italy December 2021 #ce ----------------------------------------- _Chiodini() Func _Chiodini() Local $aColors[16] = [0xffffff, 0xFF0000, 0xFF00FF, 0xFFC0CB, 0x964B00, 0xCD853F, 0xFF6600, 0xFFCC00, _ 0xFFFF00, 0xCCFF00, 0x00FF00, 0x228B22, 0x0000FF, 0x00FFFF, 0x7F7F7F, 0x000000] Local $iColor = $aColors[0], $sFileName, $aAzioni, $bOkToSave Local $aColori, $aChiodini, $GUIGetMsg, $hShowActiveColor Local $hGui = GUICreate("Chiodini colorati") $aColori = _GuiControlPanel("Button", 1, 16, 50, 20, 0, 0, 5, 0, 0, 1, True, "Colors") For $i = 1 To UBound($aColori) - 1 GUICtrlSetBkColor($aColori[$i], $aColors[$i - 1]) Next $aChiodini = _GuiControlPanel("Label", 16, 16, 20, 20, ($aColori[0])[11], 0, 3, 3, 1, 1, True, "") ; Local $aBackColors[UBound($aChiodini)] For $i = 1 To UBound($aChiodini) - 1 GUICtrlSetBkColor($aChiodini[$i], $iColor) $aBackColors[$i] = $iColor Next $iColor = $aColors[1] $aAzioni = _GuiControlPanel("Button", 4, 1, 80, 50, ($aColori[0])[11] + 0, ($aChiodini[0])[12], 0, 0, 5, 1, True, "") GUICtrlSetData($aAzioni[1], "Clear with color") GUICtrlSetData($aAzioni[2], "Load txt File") GUICtrlSetData($aAzioni[3], "Save txt File") GUICtrlSetData($aAzioni[4], "Save JPG") $hShowActiveColor = _GuiControlPanel('Label', 1, 1, 45, 30, 8, ($aColori[0])[12], 0, 0, 0, 0, True, "Active") GUICtrlSetBkColor($hShowActiveColor[1], $iColor) _WinSetClientSize($hGui, ($aChiodini[0])[11] + ($aColori[0])[11], ($aChiodini[0])[12] + ($aAzioni[0])[12]) ; GUISetState() ; --------- ; Main loop ; --------- While True $GUIGetMsg = GUIGetMsg() ; -------------------------------------------- ; scan all buttons to check if one was pressed ; -------------------------------------------- For $i = 1 To UBound($aColori) - 1 If $GUIGetMsg = $aColori[$i] Then $iColor = $aColors[$i - 1] GUICtrlSetBkColor($hShowActiveColor[1], $iColor) ContinueLoop 2 EndIf Next For $i = 1 To UBound($aChiodini) - 1 If $GUIGetMsg = $aChiodini[$i] Then GUICtrlSetBkColor($aChiodini[$i], $iColor) $aBackColors[$i] = $iColor ContinueLoop 2 EndIf Next Switch $GUIGetMsg Case $aAzioni[1] ; ----- Clear with color For $i = 1 To UBound($aChiodini) - 1 GUICtrlSetBkColor($aChiodini[$i], $iColor) $aBackColors[$i] = $iColor Next Case $aAzioni[2] ; ----- File Load $sFileName = FileOpenDialog("File to load", @ScriptDir, "Text files (*.txt)") If FileExists($sFileName) Then _FileReadToArray($sFileName, $aBackColors, $FRTA_NOCOUNT) For $i = 1 To UBound($aBackColors) - 1 GUICtrlSetBkColor($aChiodini[$i], $aBackColors[$i]) Next Else MsgBox(64, "Info", "File not found") EndIf Case $aAzioni[3] ; ----- File Save $sFileName = FileSaveDialog("File to save", @ScriptDir, "Text files (*.txt)") $bOkToSave = True If FileExists($sFileName) Then $bOkToSave = 6 = MsgBox(4 + 48, "warning", "File already exists, do you want overwrite it?") EndIf If $bOkToSave Then _FileWriteFromArray($sFileName, $aBackColors) EndIf Case $aAzioni[4] ; ----- Save image $sFileName = FileSaveDialog("Image name to save", @ScriptDir, "Image jpg (*.jpg)") $bOkToSave = True If FileExists($sFileName) Then $bOkToSave = 6 = MsgBox(4 + 48, "warning", "File already exists, do you want overwrite it?") EndIf If $bOkToSave Then CaptureWindow($sFileName, ($aChiodini[0])[13], ($aChiodini[0])[14], ($aChiodini[0])[15], ($aChiodini[0])[16], $hGui) EndIf EndSwitch If $GUIGetMsg = -3 Then Exit ; If 6 = MsgBox(4 + 32, "?", "Do you really want to quit?") Then Exit EndIf WEnd EndFunc ;==>_Chiodini ; #FUNCTION# ==================================================================================================================== ; Name...........: _GuiControlPanel v1.1 2021/12 ; Description ...: Creates a rectangular panel with adequate size to contain the required amount of controls ; and then fills it with the same controls by placing them according to the parameters ; Syntax.........: _GuiControlPanel( $ControlType, $nrPerLine, $nrOfLines, $ctrlWidth, $ctrlHeight, $xPos = 0, $yPos = 0, $xBorder, $yBorder, $xSpace = 1, $ySpace = 1) ; Parameters ....: $ControlType - Type of controls to be generated ("Button"; "Text"; ..... ; $nrPerLine - Nr. of controls per line in the matrix ; $nrOfLines - Nr. of lines in the matrix ; $ctrlWidth - Width of each control ; $ctrlHeight - Height of each control ; $xPanelPos - x Position of panel in GUI ; $yPanelPos - y Position of panel in GUI ; $xBorder - distance from lateral panel's borders to the matrix (width of left and right margin) default = 0 ; $yBorder - distance from upper and lower panel's borders to the matrix (width of upper and lower margin) default = 0 ; $xSpace - horizontal distance between the controls ; $ySpace - vertical distance between the controls ; $Group - if you want to group the controls (true or false) ; $sGrpTitle - title of the group (ignored if above is false) ; Return values .: an 1 based 1d array containing references to each control ; element [0] contains an 1d array containing various parameters about the panel ; Author ........: Gianni Addiego (Chimp) ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _GuiControlPanel($ControlType, $nrPerLine, $nrOfLines, $ctrlWidth, $ctrlHeight, $xPanelPos = 0, $yPanelPos = 0, $xBorder = 0, $yBorder = 0, $xSpace = 1, $ySpace = 1, $Group = False, $sGrpTitle = "") Local Static $sAllowedControls = "|Label|Input|Edit|Button|CheckBox|Radio|List|Combo|Pic|Icon|Graphic|" If Not StringInStr($sAllowedControls, '|' & $ControlType & '|') Then Return SetError(1, 0, "Unkown control") Local $col, $row, $left, $top, $text Local $PanelWidth = (($ctrlWidth + $xSpace) * $nrPerLine) - $xSpace + ($xBorder * 2) Local $PanelHeight = (($ctrlHeight + $ySpace) * $nrOfLines) - $ySpace + ($yBorder * 2) Local $InnerXPos = $xPanelPos, $InnerYPos = $yPanelPos, $InnerWidth = $PanelWidth, $InnerHeight = $PanelHeight If $Group Then $PanelWidth += 2 $InnerXPos += 1 If $sGrpTitle = "" Then $InnerYPos += 7 $PanelHeight += 8 GUICtrlCreateGroup("", $xPanelPos, $yPanelPos, $PanelWidth, $PanelHeight) Else $InnerYPos += 15 $PanelHeight += 18 GUICtrlCreateGroup($sGrpTitle, $xPanelPos, $yPanelPos, $PanelWidth + 2, $PanelHeight) ; + 18) EndIf EndIf ; create the controls Local $aGuiGridCtrls[$nrPerLine * $nrOfLines + 1] Local $aPanelParams[17] = [ _ $ControlType, $nrPerLine, $nrOfLines, $ctrlWidth, $ctrlHeight, _ $xPanelPos, $yPanelPos, $xBorder, $yBorder, $xSpace, $ySpace, $PanelWidth, $PanelHeight, $InnerXPos, $InnerYPos, $InnerWidth, $InnerHeight] For $i = 0 To $nrPerLine * $nrOfLines - 1 ; coordinates 1 based $col = Mod($i, $nrPerLine) + 1 ; Vertical position within the grid (row) $iVtab $row = Int($i / $nrPerLine) + 1 ; Horizontal position within the grid (column) $iHtab $left = $InnerXPos + ((($ctrlWidth + $xSpace) * $col) - $xSpace) - $ctrlWidth + $xBorder $top = $InnerYPos + ((($ctrlHeight + $ySpace) * $row) - $ySpace) - $ctrlHeight + $yBorder $text = '' ; $i + 1 ; "*" ; "." ; "(*)" $aGuiGridCtrls[$i + 1] = Execute("GUICtrlCreate" & $ControlType & "($text, $left, $top, $ctrlWidth, $ctrlHeight)") Next If $Group Then GUICtrlCreateGroup("", -99, -99, 1, 1) ; close group $aGuiGridCtrls[0] = $aPanelParams Return $aGuiGridCtrls EndFunc ;==>_GuiControlPanel ; By kafu ; https://www.autoitscript.com/forum/topic/201524-guicreate-and-wingetclientsize-mismatch/?do=findComment&comment=1446141 Func _WinSetClientSize($hWnd, $iW, $iH) Local $aWinPos = WinGetPos($hWnd) Local $sRect = DllStructCreate("int;int;int;int;") DllStructSetData($sRect, 3, $iW) DllStructSetData($sRect, 4, $iH) _WinAPI_AdjustWindowRectEx($sRect, _WinAPI_GetWindowLong($hWnd, $GWL_STYLE), _WinAPI_GetWindowLong($hWnd, $GWL_EXSTYLE)) WinMove($hWnd, "", $aWinPos[0], $aWinPos[1], _ $aWinPos[2] + (DllStructGetData($sRect, 3) - $aWinPos[2]) - DllStructGetData($sRect, 1), _ $aWinPos[3] + (DllStructGetData($sRect, 4) - $aWinPos[3]) - DllStructGetData($sRect, 2)) EndFunc ;==>_WinSetClientSize ; By InunoTaishou ; https://www.autoitscript.com/forum/topic/181655-redraw-your-desktop-with-gdi/?tab=comments#comment-1304386 Func CaptureWindow($sFileName = "", $iLeft = -1, $iTop = -1, $iWidth = -1, $iHeight = -1, $hWnd = WinGetHandle("[Active]"), $bClientArea = True) If (Not IsHWnd($hWnd)) Then $hWnd = WinGetHandle($hWnd) If (@error) Then Return SetError(1, 0, False) If (BitAND(WinGetState($hWnd), 16) = 16) Then Return SetError(2, 0, False) Local $iSrcWidth = 0 Local $iSrcHeight = 0 Local $tRectWindow = _WinAPI_GetWindowRect($hWnd) ; Get the absolute width, using Abs on all of the memembers because the [1] index of the struct may be negative, supports multiple monitors Local $iAbsWidth = Abs(Abs(DllStructGetData($tRectWindow, 3)) - Abs(DllStructGetData($tRectWindow, 1))) ; Get the absolute height, using Abs on all of the memembers because the [1] index of the struct may be negative, supports multiple monitors ; Subtracts the caption bar if $bClientArea only Local $iAbsHeight = Abs(Abs(DllStructGetData($tRectWindow, 4)) - Abs(DllStructGetData($tRectWindow, 2))) - ($bClientArea ? _WinAPI_GetSystemMetrics($SM_CYCAPTION) : 0) If ($iWidth = -1 Or $iWidth = 0 Or $iWidth = Default Or $iWidth > $iAbsWidth) Then $iWidth = $iAbsWidth If ($iHeight = -1 Or $iHeight = 0 Or $iHeight = Default Or $iHeight > $iAbsHeight) Then $iHeight = $iAbsHeight $iSrcWidth = $iAbsWidth $iSrcHeight = $iAbsHeight If ($iLeft = -1 Or $iLeft = Default) Then $iLeft = 0 If ($iTop = -1 Or $iTop = Default) Then $iTop = 0 Local $hDC = _WinAPI_GetWindowDC($hWnd) Local $hDestDC = _WinAPI_CreateCompatibleDC($hDC) Local $hDestBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iWidth, $iHeight) Local $hDestSv = _WinAPI_SelectObject($hDestDC, $hDestBitmap) Local $hSrcDC = _WinAPI_CreateCompatibleDC($hDC) Local $hBmp = _WinAPI_CreateCompatibleBitmap($hDC, $iSrcWidth, $iSrcHeight) Local $hSrcSv = _WinAPI_SelectObject($hSrcDC, $hBmp) _WinAPI_PrintWindow($hWnd, $hSrcDC, True) _WinAPI_BitBlt($hDestDC, 0, 0, $iWidth, $iHeight, $hSrcDC, $iLeft, $iTop, $MERGECOPY) _WinAPI_SelectObject($hDestDC, $hDestSv) _WinAPI_SelectObject($hSrcDC, $hSrcSv) _WinAPI_ReleaseDC($hWnd, $hDC) _WinAPI_DeleteDC($hDestDC) _WinAPI_DeleteDC($hSrcDC) _WinAPI_DeleteObject($hBmp) $tPoint = 0 $tRectWindow = 0 $tDesktop = 0 If ($sFileName) Then _GDIPlus_Startup() Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hDestBitmap) _GDIPlus_ImageSaveToFile($hBitmap, $sFileName) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_Shutdown() EndIf ; Return $hDestBitmap EndFunc ;==>CaptureWindow Chiodini.zip1 point
-
Does it work if you eliminate the 2nd parameter, ie: GUISetBkColor(0x414141)1 point
-
Latest update just released. See below for change log.1 point
-
Thanks to @water on the Wiki we have new page: https://www.autoitscript.com/wiki/WebDriver_Capabilities1 point
-
Hello and thanks everyone for your help i need to convert this part of the code. But I'm blocking. -snip-0 points