Leaderboard
Popular Content
Showing content with the highest reputation on 11/19/2020 in all areas
-
@Nine I was just about to post a very similar solution, which I translated from here. 😄 Here's what I came up with -- Func _StringTrimMid($sInput, $iStartCut, $iEndCut) Local $lFind = "^(.{" & $iStartCut - 1 & "}).{" & ($iEndCut - $iStartCut + 1) & "}" Local $lResult = StringRegExpReplace($sInput, $lFind, "\1") Return $lResult EndFunc ;==>_StringTrimMid2 points
-
Button Deck
marcgforce and one other reacted to Danny35d for a topic
Hi Chimp, Nine and Marcforce very nice script. Below are the changes I made on the script. Instead of Auto-hide after 5 secs now hide when GUI loose focus Removed Tray management of the deck Improve drag and drop Updated _RestartProgram() function to handle file with .a3x extension Added _GetVirtualScreen() function the handle better multi monitors and undocking laptop Added GUI animation and startup script when login Instead of saving shortcut and config into an ini file, now save to SQLite database Added way to export and import Lauchpad configurations Added About GUI Added and improve to Add, Remove buttons and change icon Improve how to get icons and execute files from extension .lnk Added a way open the database for modification using 3rd party application called DB browser ; =============================================================================================================================== ; Title .........: LaunchPad ; Description ...: button deck to be used as an applications launcher (and not only) ; Author(s) .....: Chimp (Gianni Addiego) ; credits to @KaFu, @Danyfirex, @mikell (see comments for references) ; Modification ..: Marcgforce (drag and drop add, passing ini to links) ; Danny35d Replace passing ini for a SQLite DB, improve drag and drop, improve func called _RestartProgram ; to be able to execute file with the extension .a3x, added func called _GetVirtualScreen to better ; handle Multi monitors and undocking laptop, added GUI animation and Choice to startup when you login. ; URL ...........: https://www.autoitscript.com/forum/topic/202048-button-deck/ ; =============================================================================================================================== #NoTrayIcon #include <Misc.au3> #include <Array.au3> #include <Crypt.au3> #include <String.au3> #include <SQLite.au3> #include <WinAPI.au3> #include <SQLite.dll.au3> #include <GUIConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> If _Singleton("LaunchPadApps", 2) = 0 Then MsgBox($MB_SYSTEMMODAL, "Warning", "An occurrence of LaunchPad is already running.") Exit EndIf ;Turn off redirection for a 32-bit script on 64-bit system. If @OSArch = "X64" And Not @AutoItX64 Then _WinAPI_Wow64EnableWow64FsRedirection(False) OnAutoItExitRegister('_Exit') ; https://docs.microsoft.com/en-us/windows/win32/winmsg/wm-sizing Global Const $WMSZ_LEFT = 1 Global Const $WMSZ_RIGHT = 2 Global Const $WMSZ_TOP = 3 Global Const $WMSZ_TOPLEFT = 4 Global Const $WMSZ_TOPRIGHT = 5 Global Const $WMSZ_BOTTOM = 6 Global Const $WMSZ_BOTTOMLEFT = 7 Global Const $WMSZ_BOTTOMRIGHT = 8 Global Enum $vButton_Tip = 0, $vButton_IconPath, $vButton_IconNumber, $vButton_Command, $vButton_UniqueID Global Const $AW_FADE_IN = 0x00080000 ;fade-in Global Const $AW_FADE_OUT = 0x00090000 ;fade-out Global Const $AW_SLIDE_IN_LEFT = 0x00040001 ;slide in from left Global Const $AW_SLIDE_OUT_LEFT = 0x00050002 ;slide out to left Global Const $AW_SLIDE_IN_RIGHT = 0x00040002 ;slide in from right Global Const $AW_SLIDE_OUT_RIGHT = 0x00050001 ;slide out to right Global Const $AW_SLIDE_IN_TOP = 0x00040004 ;slide-in from top Global Const $AW_SLIDE_OUT_TOP = 0x00050008 ;slide-out to top Global Const $AW_SLIDE_IN_BOTTOM = 0x00040008 ;slide-in from bottom Global Const $AW_SLIDE_OUT_BOTTOM = 0x00050004 ;slide-out to bottom Global Const $AW_DIAG_SLIDE_IN_TOP_LEFT = 0x00040005 ;diag slide-in from Top-left Global Const $AW_DIAG_SLIDE_OUT_TOP_LEFT = 0x0005000a ;diag slide-out to Top-left Global Const $AW_DIAG_SLIDE_IN_TOP_RIGHT = 0x00040006 ;diag slide-in from Top-Right Global Const $AW_DIAG_SLIDE_OUT_TOP_RIGHT = 0x00050009 ;diag slide-out to Top-Right Global Const $AW_DIAG_SLIDE_IN_BOTTOM_LEFT = 0x00040009 ;diag slide-in from Bottom-left Global Const $AW_DIAG_SLIDE_OUT_BOTTOM_LEFT = 0x00050006 ;diag slide-out to Bottom-left Global Const $AW_DIAG_SLIDE_IN_BOTTOM_RIGHT = 0x0004000a ;diag slide-in from Bottom-right Global Const $AW_DIAG_SLIDE_OUT_BOTTOM_RIGHT = 0x00050005 ;diag slide-out to Bottom-right Global Const $AW_EXPLODE = 0x00040010 ;explode Global Const $AW_IMPLODE = 0x00050010 ;implode Local Const $AppDataUser = @LocalAppDataDir & '\LaunchPad' Local Const $dll_icons = $AppDataUser & '\Bin\iconset.dll' Local $aAnimation = StringSplit('Explode|Fade In|Slide In Left|Slide In Right|Slide In Top|Slide In Bottom|Diag Slide In Top Left|Diag Slide In Top Right|Diag Slide In Bottom Left|Diag Slide In Bottom Right', '|', 2) If Not FileExists($AppDataUser) Then DirCreate($AppDataUser) If Not FileExists($AppDataUser & '\Bin') Then DirCreate($AppDataUser & '\Bin') If Not FileExists($AppDataUser & '\Icons') Then DirCreate($AppDataUser & '\Icons') If Not FileExists($AppDataUser & "\BackupDB") Then DirCreate($AppDataUser & "\BackupDB") If Not FileExists($AppDataUser & '\Bin\iconset.dll') Then FileInstall('.\Include\iconset.dll', $AppDataUser & '\Bin\') If Not FileExists($AppDataUser & '\Bin\sqlite3.exe') Then FileInstall('.\Include\sqlite3.exe', $AppDataUser & '\Bin\') If Not FileExists($AppDataUser & '\Bin\sqlite3.dll') Then FileInstall('.\Include\sqlite3.dll', $AppDataUser & '\Bin\') If Not FileExists($AppDataUser & '\Bin\sqlite3_x64.dll') Then FileInstall('.\Include\sqlite3_x64.dll', $AppDataUser & '\Bin\') #cs The following 2D array contains the settings that determine the behavior of each "Button" namely 4 parameters for each row (for each button); [n][0] the tooltip of the button [n][1] path of an icon or a file containing icons [n][2] the number of the icon (if the previous parameter is a collection) [n][3] AutoIt command(s) to be executed directly on button click (or also the name of a function) #ce Global $aTools[][] = [ _ ['Administrative Tools', 'SHELL32.dll', 177, 'run("explorer.exe shell:::{D20EA4E1-3957-11d2-A40B-0C5020524153}")', ''], _ ['Windows version', 'winver.exe', 1, 'run("explorer.exe shell:::{BB06C0E4-D293-4f75-8A90-CB05B6477EEE}")', ''], _ ; or "Run('winver.exe')" ['This computer', 'netcenter.dll', 6, 'run("explorer.exe shell:::{20D04FE0-3AEA-1069-A2D8-08002B30309D}")', ''], _ ['Devices and Printers', 'SHELL32.dll', 272, 'run("explorer.exe shell:::{A8A91A66-3A7D-4424-8D24-04E180695C7A}")', ''], _ ['Folder options', 'SHELL32.dll', 210, 'run("explorer.exe shell:::{6DFD7C5C-2451-11d3-A299-00C04F8EF6AF}")', ''], _ ['Command Prompt', @ComSpec, 1, 'Run(@ComSpec)', ''], _ ['Internet Explorer', @ProgramFilesDir & '\Internet Explorer\iexplore.exe', 1, "Run(@ProgramFilesDir & '\Internet Explorer\iexplore.exe')", ''], _ ['Media Player', @ProgramFilesDir & '\Windows media player\wmplayer.exe', 1, "Run(@ProgramFilesDir & '\Windows media player\wmplayer.exe')", ''], _ ['File browser', @WindowsDir & '\explorer.exe', 1, "Run(@WindowsDir & '\explorer.exe')", ''], _ ['Notepad', @SystemDir & '\notepad.exe', 1, "Run(@SystemDir & '\notepad.exe')", ''], _ ['Wordpad', @SystemDir & '\write.exe', 1, "Run(@SystemDir & '\write.exe')", ''], _ ['Registry editor', @SystemDir & '\regedit.exe', 1, "ShellExecute('regedit.exe')", ''], _ ['Connect to', 'netcenter.dll', 19, 'run("explorer.exe shell:::{38A98528-6CBF-4CA9-8DC0-B1E1D10F7B1B}")', ''], _ ['Calculator', @SystemDir & '\Calc.exe', 1, "Run(@SystemDir & '\calc.exe')", ''], _ ['Control panel', 'control.exe', 1, 'run("explorer.exe shell:::{5399E694-6CE5-4D6C-8FCE-1D8870FDCBA0}")', ''], _ ['Users manager', @SystemDir & '\Netplwiz.exe', 1, "ShellExecute('Netplwiz.exe')", ''], _ ; {7A9D77BD-5403-11d2-8785-2E0420524153} ['Run', 'SHELL32.dll', 25, 'Run("explorer.exe Shell:::{2559a1f3-21d7-11d4-bdaf-00c04f60b9f0}")', ''], _ ['Search files', 'SHELL32.dll', 135, 'run("explorer.exe shell:::{9343812e-1c37-4a49-a12e-4b2d810d956b}")', ''], _ ['On screen Magnifier', @SystemDir & '\Magnify.exe', 1, "ShellExecute('Magnify.exe')", ''], _ ['Paint', @SystemDir & '\mspaint.exe', 1, "Run(@SystemDir & '\mspaint.exe')", ''], _ ['Remote desktop', @SystemDir & '\mstsc.exe', 1, " Run('mstsc.exe')", ''], _ ['Resource monitoring', @SystemDir & '\resmon.exe', 1, "Run('resmon.exe')", ''], _ ['Device manager', 'SHELL32.dll', 13, 'Run("explorer.exe Shell:::{74246bfc-4c96-11d0-abef-0020af6b0b7a}")', ''], _ ['Audio', 'SndVol.exe', 1, 'Run("explorer.exe Shell:::{F2DDFC82-8F12-4CDD-B7DC-D4FE1425AA4D}")', ''], _ ; or 'run(@SystemDir & "\SndVol.exe")'] ['Task view', 'SHELL32.dll', 133, 'Run("explorer.exe shell:::{3080F90E-D7AD-11D9-BD98-0000947B0257}")', ''], _ ['Task Manager', @SystemDir & '\taskmgr.exe', 1, 'Send("^+{ESC}")', ''], _ ; "Run(@SystemDir & '\taskmgr.exe')"], _ ['On Screen Keyboard', 'osk.exe', 1, 'ProcessExists("osc.exe") ? False : ShellExecute("osk.exe")', ''], _ ; <-- ternary example ['... if Notepad is running Send F5 to it', 'SHELL32.dll', 167, ' WinExists("[CLASS:Notepad]") ? ControlSend("[CLASS:Notepad]", "", "", "{F5}") : MsgBox(16, ":(", "Notepad not found", 2)', ''] _ ; Check if Notepad is currently running ] ; Show desktop {3080F90D-D7AD-11D9-BD98-0000947B0257} ; Desktop Background {ED834ED6-4B5A-4bfe-8F11-A626DCB6A921} ; IE internet option {A3DD4F92-658A-410F-84FD-6FBBBEF2FFFE} ; ['Notes', 'StikyNot.exe', 1, "ShellExecute('StikyNot')"], _ Global $GUI, $hSQLiteDB, $tmpVirtualScreen Global $bSaveSettings = True, $bShowGUI = True Global $SQLiteDB = $AppDataUser & '\Launchpad.sqlite' Local $sqlRow, $sqlColumn Local $SQLiteDBExists = FileExists($SQLiteDB) Global $sSQliteDll = _SQLite_Startup($AppDataUser & '\Bin\sqlite3.dll', False, 1) If @error Then MsgBox($MB_SYSTEMMODAL, "SQLite Error", "SQLite3.dll Can't be Loaded!" & @CRLF & @CRLF & _ "Not FOUND in " & $AppDataUser & '\Bin\') $bSaveSettings = False Exit -1 Else $hSQLiteDB = _SQLite_Open($SQLiteDB) If @error Then MsgBox($MB_SYSTEMMODAL, "SQLite Error", "Can't open or create a permanent Database!" & @CRLF & @CRLF & $SQLiteDB) $bSaveSettings = False Exit -1 EndIf EndIf _SQLite_LaunchPad($hSQLiteDB, "CREATE TABLE IF NOT EXISTS Buttons(Name TEXT, Icon TEXT, IconNum INTEGER, Execute TEXT, Button_ID INTEGER PRIMARY KEY);") _SQLite_LaunchPad($hSQLiteDB, "CREATE TABLE IF NOT EXISTS Settings(LeftPos INTEGER, TopPos INTEGER, ButtonSize INTEGER, xColumns INTEGER, GUIin TEXT, GUIout TEXT, Freeze TEXT, StartUp TEXT);") If Not $SQLiteDBExists Then _SQLite_LaunchPad($hSQLiteDB, "INSERT INTO Settings VALUES(10, 10, 40, " & Ceiling(UBound($aTools) / 2) & ",'AW_EXPLODE', 'AW_IMPLODE', 'False', 'False');") For $x = 0 To UBound($aTools) - 1 $aTools[$x][$vButton_Command] = StringReplace($aTools[$x][$vButton_Command], "'", '"') _SQLite_LaunchPad($hSQLiteDB, "INSERT INTO Buttons (Name, Icon, IconNum, Execute) VALUES ('" & $aTools[$x][$vButton_Tip] & "','" & $aTools[$x][$vButton_IconPath] & "'," & $aTools[$x][$vButton_IconNumber] & ",'" & $aTools[$x][$vButton_Command] & "');") Next EndIf _SQLite_GetTable2d($hSQLiteDB, "SELECT * FROM Buttons;", $aTools, $sqlRow, $sqlColumn) _ArrayDelete($aTools, 0) _SQLite_QuerySingleRow($hSQLiteDB, "SELECT LeftPos FROM Settings;", $sqlRow) Global $iLeftPos = $sqlRow[0] _SQLite_QuerySingleRow($hSQLiteDB, "SELECT TopPos FROM Settings;", $sqlRow) Global $iTopPos = $sqlRow[0] _SQLite_QuerySingleRow($hSQLiteDB, "SELECT ButtonSize FROM Settings;", $sqlRow) Global $iStep = $sqlRow[0] _SQLite_QuerySingleRow($hSQLiteDB, "SELECT xColumns FROM Settings;", $sqlRow) Global $iNrPerLine = $sqlRow[0] _SQLite_QuerySingleRow($hSQLiteDB, "SELECT GUIin FROM Settings;", $sqlRow) Global $GUI_IN = $sqlRow[0] _SQLite_QuerySingleRow($hSQLiteDB, "SELECT GUIout FROM Settings;", $sqlRow) Global $GUI_OUT = $sqlRow[0] _SQLite_QuerySingleRow($hSQLiteDB, "SELECT Freeze FROM Settings;", $sqlRow) Global $bFreezeWindow = $sqlRow[0] _SQLite_QuerySingleRow($hSQLiteDB, "SELECT StartUp FROM Settings;", $sqlRow) Global $bStartUp = $sqlRow[0] If Not IsBool($bFreezeWindow) And $bFreezeWindow = 'True' Then $bFreezeWindow = True ElseIf Not IsBool($bFreezeWindow) And $bFreezeWindow = 'False' Then $bFreezeWindow = False EndIf If Not IsBool($bStartUp) And $bStartUp = 'True' Then $bStartUp = True ElseIf Not IsBool($bStartUp) And $bStartUp = 'False' Then $bStartUp = False EndIf Global $idAddIcon[1], $idRemoveIcon[1], $idChangeIcon[1] Global $iNrOfLines = Ceiling(UBound($aTools) / $iNrPerLine) Global $dllUser32 = DllOpen("user32.dll") $GUI = GUICreate('Launch Pad', 10, 10, $iLeftPos, $iTopPos, BitOR($WS_THICKFRAME, 0), BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_ACCEPTFILES)) Global $GuiContextMenu = GUICtrlCreateContextMenu() Global $idFreezeWindow = GUICtrlCreateMenuItem("Freeze", $GuiContextMenu) Global $idSettings = GUICtrlCreateMenu("Settings", $GuiContextMenu, 1) Global $idDatabase = GUICtrlCreateMenu("Database", $idSettings) Global $idOpenDB = GUICtrlCreateMenuItem("Open DB", $idDatabase) Global $idExportDB = GUICtrlCreateMenuItem("Export DB", $idDatabase) Global $idImportDB = GUICtrlCreateMenuItem("Import DB", $idDatabase) Global $idStartUp = GUICtrlCreateMenuItem("StartUp", $idSettings) Global $idAnimation = GUICtrlCreateMenu("Animate", $GuiContextMenu, 1) GUICtrlCreateMenuItem("", $GuiContextMenu) Global $idAbout = GUICtrlCreateMenuItem("About", $GuiContextMenu) $aMyMatrix = _GuiControlPanel("Button", $iNrPerLine, $iNrOfLines, $iStep, $iStep, BitOR(0x40, 0x1000), -1, 0, 0, 0, 0, 0, 0, False, "") Global $iPreviousX = ($aMyMatrix[0])[1], $iPreviousY = ($aMyMatrix[0])[2] ReDim $idAddIcon[UBound($aMyMatrix)] ReDim $idRemoveIcon[UBound($aMyMatrix)] ReDim $idChangeIcon[UBound($aMyMatrix)] ReDim $aTools[UBound($aMyMatrix)][5] ; Be sure none of the array elements are NULL, otherwise _ArraySearch failed For $i = 0 To UBound($aMyMatrix) - 1 If $idAddIcon[$i] = '' Then $idAddIcon[$i] = 9999 If $idRemoveIcon[$i] = '' Then $idRemoveIcon[$i] = 9999 If $idChangeIcon[$i] = '' Then $idChangeIcon[$i] = 9999 Next For $i = 0 To UBound($aAnimation) - 1 $aAnimation[$i] = GUICtrlCreateMenuItem($aAnimation[$i], $idAnimation) Next For $i = 1 To UBound($aMyMatrix) - 1 GUICtrlSetResizing($aMyMatrix[$i], $GUI_DOCKALL) ; (2+32+256+512) so the control will not move during resizing If $i <= UBound($aTools) Then GUICtrlSetImage($aMyMatrix[$i], $aTools[$i - 1][$vButton_IconPath], $aTools[$i - 1][$vButton_IconNumber]) GUICtrlSetTip($aMyMatrix[$i], $aTools[$i - 1][$vButton_Tip]) EndIf Next _WinSetClientSize($GUI, ($aMyMatrix[0])[11], ($aMyMatrix[0])[12]) ; thanks to KaFu If $bFreezeWindow Then GUICtrlSetState($idFreezeWindow, $GUI_CHECKED) If $bStartUp Then GUICtrlSetState($idStartUp, $GUI_CHECKED) GUISetState() ; https://devblogs.microsoft.com/oldnewthing/20110218-00/?p=11453 GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST") GUIRegisterMsg($WM_SIZING, "WM_SIZING") _MainLoop() _Exit() Func _MainLoop() Local $iDeltaX, $iDeltaY, $row, $col, $left, $top, $awPos, $iAnswer, $sTemp Local $hTimer, $sFileDialog, $sBackupName While 1 Sleep(10) $xyVirtualScreen = _GetVirtualScreen() If Not WinActive($GUI) And Not $bFreezeWindow And $bShowGUI Then _ToggleGuiShowHide($GUI, False) $aPos = MouseGetPos() $hTimer = TimerInit() While ($aPos[0] = $xyVirtualScreen[0] Or $aPos[1] = $xyVirtualScreen[2] Or $aPos[0] = $xyVirtualScreen[1] Or $aPos[1] = $xyVirtualScreen[3]) And Not $bFreezeWindow $aPos = MouseGetPos() If TimerDiff($hTimer) > 1000 Then _ToggleGuiShowHide($GUI, True) Sleep(10) WEnd $Msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_DROPPED Local $iAnswer = $IDNO Local $ProposeLink = StringSplit(@GUI_DragFile, '\') $ProposeLink = StringRegExpReplace($ProposeLink[UBound($ProposeLink) - 1], '(.*)\..*', "$1") $i = _ArrayBinarySearch($aMyMatrix, @GUI_DropId) If $i <> -1 Then If $aTools[$i - 1][$vButton_Command] <> '' Then $iAnswer = MsgBox($MB_YESNO, "LauchPad Drag & Drop", "Are you sure you want to overwrite " & $aTools[$i - 1][$vButton_Tip] & " shortcut?", 0, $GUI) Else $iAnswer = $IDYES EndIf If $iAnswer = $IDYES Then $sTemp = '' Local $sReponse = InputBox("Icon name", "Give the shortcut a title", $ProposeLink) If @error <> 1 Or $sReponse <> '' Then $aTools[$i - 1][$vButton_Tip] = $sReponse $aTools[$i - 1][$vButton_IconNumber] = 1 $aTools[$i - 1][$vButton_IconPath] = $dll_icons $aTools[$i - 1][$vButton_Command] = @GUI_DragFile $sExt = StringRegExpReplace($aTools[$i - 1][$vButton_Command], "^.*\.", "") ; extraction of its extension Switch $sExt Case "doc", "docx", "odt" $aTools[$i - 1][$vButton_IconNumber] = 436 Case "xls", "xlsx", "ods" $aTools[$i - 1][$vButton_IconNumber] = 441 Case "pdf" $aTools[$i - 1][$vButton_IconNumber] = 400 Case "ppt", "pptx", "odp" $aTools[$i - 1][$vButton_IconNumber] = 431 Case "txt", "rtf" $aTools[$i - 1][$vButton_IconNumber] = 406 Case "msg" $aTools[$i - 1][$vButton_IconNumber] = 426 Case Else If $sExt = 'lnk' Then $aDetails = FileGetShortcut($aTools[$i - 1][$vButton_Command]) If IsArray($aDetails) Then $sTemp = $aTools[$i - 1][$vButton_Command] If $aDetails[4] <> '' Then $aTools[$i - 1][$vButton_Command] = $aDetails[4] Else $aTools[$i - 1][$vButton_Command] = $aDetails[0] EndIf EndIf EndIf If _WinAPI_ExtractIconEx($aTools[$i - 1][$vButton_Command], -1, 0, 0, 0) > 0 Then ; allows you to test if the file has one or more icon (s) Local $aIcon[3] = [64, 32, 16] For $a = 0 To UBound($aIcon) - 1 $aIcon[$a] = _WinAPI_Create32BitHICON(_WinAPI_ShellExtractIcon($aTools[$i - 1][$vButton_Command], 0, $aIcon[$a], $aIcon[$a]), 1) Next $aTools[$i - 1][$vButton_IconPath] = $AppDataUser & '\Icons\' & $aTools[$i - 1][$vButton_Tip] & '.ico' _WinAPI_SaveHICONToFile($aTools[$i - 1][$vButton_IconPath], $aIcon) For $a = 0 To UBound($aIcon) - 1 _WinAPI_DestroyIcon($aIcon[$a]) Next Else $aRet = _PickIconDlg($dll_icons) If Not @error Then If GUICtrlSetImage(@GUI_DropId, $aRet[0], $aRet[1]) Then $aTools[$i - 1][$vButton_IconPath] = $aRet[0] $aTools[$i - 1][$vButton_IconNumber] = $aRet[1] EndIf EndIf EndIf EndSwitch EndIf If $sTemp <> '' Then $aTools[$i - 1][$vButton_Command] = $sTemp If $aTools[$i - 1][$vButton_UniqueID] <> '' And $iAnswer = $IDYES Then _SQLite_LaunchPad($hSQLiteDB, "UPDATE Buttons SET Name = '" & $aTools[$i - 1][$vButton_Tip] & "' WHERE Button_ID = " & $aTools[$i - 1][$vButton_UniqueID] & ";") _SQLite_LaunchPad($hSQLiteDB, "UPDATE Buttons SET Execute = '" & $aTools[$i - 1][$vButton_Command] & "' WHERE Button_ID = " & $aTools[$i - 1][$vButton_UniqueID] & ";") _SQLite_LaunchPad($hSQLiteDB, "UPDATE Buttons SET Icon = '" & $aTools[$i - 1][$vButton_IconPath] & "' WHERE Button_ID = " & $aTools[$i - 1][$vButton_UniqueID] & ";") _SQLite_LaunchPad($hSQLiteDB, "UPDATE Buttons SET IconNum = '" & $aTools[$i - 1][$vButton_IconNumber] & "' WHERE Button_ID = " & $aTools[$i - 1][$vButton_UniqueID] & ";") Else _SQLite_LaunchPad($hSQLiteDB, "INSERT INTO Buttons (Name, Icon, IconNum, Execute) VALUES ('" & $aTools[$i - 1][$vButton_Tip] & "', '" & $aTools[$i - 1][$vButton_IconPath] & "', " & $aTools[$i - 1][$vButton_IconNumber] & ", '" & $aTools[$i - 1][$vButton_Command] & "');") _SQLite_GetTable2d($hSQLiteDB, "SELECT * FROM Buttons;", $aTools, $sqlRow, $sqlColumn) _ArrayDelete($aTools, 0) ReDim $aTools[UBound($aMyMatrix)][5] EndIf If $iAnswer = $IDYES Then GUICtrlSetTip(@GUI_DropId, $aTools[$i - 1][$vButton_Tip]) GUICtrlSetImage(@GUI_DropId, $aTools[$i - 1][$vButton_IconPath], $aTools[$i - 1][$vButton_IconNumber]) EndIf EndIf EndIf Case $idFreezeWindow If BitAND(GUICtrlRead($idFreezeWindow), $GUI_UNCHECKED) = $GUI_UNCHECKED Then $bFreezeWindow = True GUICtrlSetState($idFreezeWindow, $GUI_CHECKED) Else $bFreezeWindow = False GUICtrlSetState($idFreezeWindow, $GUI_UNCHECKED) EndIf Case $idStartUp If BitAND(GUICtrlRead($idStartUp), $GUI_UNCHECKED) = $GUI_UNCHECKED Then $bStartUp = True _StartUpProgram($bStartUp) GUICtrlSetState($idStartUp, $GUI_CHECKED) Else $bStartUp = False _StartUpProgram($bStartUp) GUICtrlSetState($idStartUp, $GUI_UNCHECKED) EndIf Case $idOpenDB If Not FileExists($AppDataUser & '\SQLiteDatabaseBrowserPortable') Then If MsgBox($MB_YESNO, "LauchPad DB Browser", "DB Browser for SQLite Portable is needed to change settings or buttons." & @CRLF & _StringRepeat(' ', 30) & "Do you want to download DB Browser?", 0, $GUI) = $IDYES Then ShellExecute('https://portableapps.com/apps/development/sqlite_database_browser_portable') MsgBox($MB_OK, "LauchPad DB Browser", "Installing DB Browser for SQLite Portable" & @CRLF & @CRLF & _ '1) Press green button to download DB Browser' & @CRLF & @CRLF & '2) Execute the downloaded file' & @CRLF & @CRLF & _ '3) Press Next and Destination Folder is ' & $AppDataUser & @CRLF & @CRLF & '4) Press Install and then Finish', 0, $GUI) EndIf Else $dHash = _Crypt_HashFile($SQLiteDB, $CALG_MD5) ShellExecuteWait($AppDataUser & '\SQLiteDatabaseBrowserPortable\SQLiteDatabaseBrowserPortable.exe', $SQLiteDB) If $dHash <> _Crypt_HashFile($SQLiteDB, $CALG_MD5) Then $bSaveSettings = False _RestartProgram() EndIf EndIf Case $idExportDB $sBackupName = 'LaunchPad-' & @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & '.sql' $sFileDialog = FileSaveDialog('Export DB - LaunchPad', $AppDataUser & "\BackupDB\", "SQLite (*.sql)", BitOR($FD_PATHMUSTEXIST, $FD_PROMPTOVERWRITE), $sBackupName, $GUI) If Not @error Then $sTemp = '.open ' & StringReplace($SQLiteDB, '\', '/') & @CRLF $sTemp &= '.once "' & StringReplace($sFileDialog, '\', '/') & '"' & @CRLF $sTemp &= '.dump' & @CRLF & '.exit' & @CRLF _SQLite_SQLiteExe($SQLiteDB, $sTemp, $row, $AppDataUser & '\Bin\sqlite3.exe') EndIf Case $idImportDB $sFileDialog = FileOpenDialog('Import DB - LaunchPad', $AppDataUser & "\BackupDB\", "SQLite (*.sql)|All (*.*)", BitOR($FD_FILEMUSTEXIST, $FD_PATHMUSTEXIST), '', $GUI) If Not @error Then $bSaveSettings = False $sTemp = '.open ' & StringReplace($SQLiteDB, '\', '/') & @CRLF $sTemp &= 'DROP TABLE IF EXISTS Buttons;' & @CRLF $sTemp &= 'DROP TABLE IF EXISTS Settings;' & @CRLF $sTemp &= '.read "' & StringReplace($sFileDialog, '\', '/') & '"' & @CRLF $sTemp &= '.exit' & @CRLF _SQLite_SQLiteExe($SQLiteDB, $sTemp, $row, $AppDataUser & '\Bin\sqlite3.exe') _RestartProgram() EndIf Case $idAbout _About() Case Else $i = _ArraySearch($aMyMatrix, $Msg) If $i <> -1 Then If $aTools[$i - 1][$vButton_Command] <> '' Then $dummy = Execute($aTools[$i - 1][$vButton_Command]) If @error Then ShellExecute($aTools[$i - 1][$vButton_Command]) ElseIf $aTools[$i - 1][$vButton_Command] = '' Then MsgBox($MB_OK, "LauchPad Execute Shortcut", "This shortcut doesn't have an Application associated.", 0, $GUI) EndIf EndIf $i = _ArraySearch($aAnimation, $Msg) If $i <> -1 Then If GUICtrlRead($Msg, 1) = 'Explode' Then $GUI_IN = 'AW_EXPLODE' $GUI_OUT = 'AW_IMPLODE' Else $GUI_IN = 'AW_' & StringReplace(GUICtrlRead($Msg, 1), ' ', '_') $GUI_OUT = StringReplace($GUI_IN, '_In', '_Out') EndIf _SQLite_LaunchPad($hSQLiteDB, "UPDATE Settings SET GUIin = '" & $GUI_IN & "';") _SQLite_LaunchPad($hSQLiteDB, "UPDATE Settings SET GUIout = '" & $GUI_OUT & "';") ; Need to add focus EndIf $i = _ArraySearch($idAddIcon, $Msg) If $i <> -1 Then _SQLite_LaunchPad($hSQLiteDB, "INSERT INTO Buttons (Name, Icon, IconNum, Execute) VALUES ('', '', '', '');") _RestartProgram() EndIf $i = _ArraySearch($idRemoveIcon, $Msg) If $i <> -1 Then If MsgBox($MB_YESNO, "LauchPad Removing Icon", "Are you sure you want to delete " & $aTools[$i][$vButton_Tip] & " shortcut?", 0, $GUI) = $IDYES Then _SQLite_LaunchPad($hSQLiteDB, 'DELETE FROM Buttons WHERE Button_ID = ' & $aTools[$i][$vButton_UniqueID] & ';') If StringInStr($aTools[$i][$vButton_IconPath], $AppDataUser & '\Icons') Then FileDelete($aTools[$i][$vButton_IconPath]) _RestartProgram() EndIf EndIf $i = _ArraySearch($idChangeIcon, $Msg) If $i <> -1 Then $aRet = _PickIconDlg($dll_icons) If Not @error Then If GUICtrlSetImage($aMyMatrix[$i + 1], $aRet[0], $aRet[1]) Then $aTools[$i][$vButton_IconPath] = $aRet[0] $aTools[$i][$vButton_IconNumber] = $aRet[1] If $aTools[$i][$vButton_UniqueID] <> '' Then _SQLite_LaunchPad($hSQLiteDB, "UPDATE Buttons SET Icon = '" & $aTools[$i][$vButton_IconPath] & "' WHERE Button_ID = " & $aTools[$i][$vButton_UniqueID] & ";") _SQLite_LaunchPad($hSQLiteDB, "UPDATE Buttons SET IconNum = '" & $aTools[$i][$vButton_IconNumber] & "' WHERE Button_ID = " & $aTools[$i][$vButton_UniqueID] & ";") Else _SQLite_LaunchPad($hSQLiteDB, "INSERT INTO Buttons (Name, Icon, IconNum, Execute) VALUES ('', '" & $aTools[$i][$vButton_IconPath] & "', " & $aTools[$i][$vButton_IconNumber] & ", '');") _SQLite_GetTable2d($hSQLiteDB, "SELECT * FROM Buttons;", $aTools, $sqlRow, $sqlColumn) _ArrayDelete($aTools, 0) ReDim $aTools[UBound($aMyMatrix)][5] EndIf EndIf EndIf EndIf EndSwitch ; check if any size has changed If $iPreviousX <> ($aMyMatrix[0])[1] Or $iPreviousY <> ($aMyMatrix[0])[2] Then ; calculate the variations $iDeltaX = Abs($iPreviousX - ($aMyMatrix[0])[1]) $iDeltaY = Abs($iPreviousY - ($aMyMatrix[0])[2]) ; if both dimensions changed at the same time, the largest variation prevails over the other If $iDeltaX >= $iDeltaY Then ; keep the new number of columns ; calculate and set the correct number of lines accordingly _SubArraySet($aMyMatrix[0], 2, Ceiling((UBound($aMyMatrix) - 1) / ($aMyMatrix[0])[1])) Else ; otherwise keep the new number of rows ; calculate and set the correct number of columns accordingly _SubArraySet($aMyMatrix[0], 1, Ceiling((UBound($aMyMatrix) - 1) / ($aMyMatrix[0])[2])) EndIf ; set client area new sizes _WinSetClientSize($GUI, ($aMyMatrix[0])[1] * $iStep, ($aMyMatrix[0])[2] * $iStep) ; remember the new panel settings $iPreviousX = ($aMyMatrix[0])[1] $iPreviousY = ($aMyMatrix[0])[2] ; rearrange the controls inside the panel For $i = 0 To UBound($aMyMatrix) - 2 ; coordinates 1 based $col = Mod($i, $iPreviousX) + 1 ; Horizontal position within the grid (column) $row = Int($i / $iPreviousX) + 1 ; Vertical position within the grid (row number) $left = ($aMyMatrix[0])[5] + (((($aMyMatrix[0])[3] + ($aMyMatrix[0])[9]) * $col) - ($aMyMatrix[0])[9]) - ($aMyMatrix[0])[3] + ($aMyMatrix[0])[7] $top = ($aMyMatrix[0])[6] + (((($aMyMatrix[0])[4] + ($aMyMatrix[0])[10]) * $row) - ($aMyMatrix[0])[10]) - ($aMyMatrix[0])[4] + ($aMyMatrix[0])[8] GUICtrlSetPos($aMyMatrix[$i + 1], $left, $top) Next EndIf WEnd EndFunc ;==>_MainLoop ; Allow/Disallow specific borders resizing ; thanks to Danyfirex ; --------- ; https://www.autoitscript.com/forum/topic/201464-partially-resizable-window-how-solved-by-danyfirex-%F0%9F%91%8D/?do=findComment&comment=1445748 Func WM_NCHITTEST($hwnd, $iMsg, $iwParam, $ilParam) If $hwnd = $GUI Then Local $iRet = _WinAPI_DefWindowProc($hwnd, $iMsg, $iwParam, $ilParam) ; https://docs.microsoft.com/en-us/windows/win32/inputdev/wm-nchittest If $iRet = $HTBOTTOM Or $iRet = $HTRIGHT Or $iRet = $HTBOTTOMRIGHT Then ; allowed resizing Return $iRet ; default process of border resizing Else ; resizing not allowed Return $HTCLIENT ; do like if cursor is in the client area EndIf EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_NCHITTEST ; controls and process resizing operations in real time ; thanks to mikell ; ------ ; https://www.autoitscript.com/forum/topic/201464-partially-resizable-window-how-solved-by-danyfirex-%F0%9F%91%8D/?do=findComment&comment=1445754 Func WM_SIZING($hwnd, $iMsg, $wparam, $lparam) ; https://docs.microsoft.com/en-us/windows/win32/winmsg/wm-sizing Local $iCols = ($aMyMatrix[0])[1] Local $iRows = ($aMyMatrix[0])[2] Local $xClientSizeNew, $yClientSizeNew #cs $wparam The edge of the window that is being sized. $lparam A pointer to a RECT structure with the screen coordinates of the drag rectangle. To change the size or position of the drag rectangle, an application must change the members of this structure. Return value Type: LRESULT #ce $wparam $aPos = WinGetPos($GUI) #cs Success : a 4 - element array containing the following information : $aArray[0] = X position $aArray[1] = Y position $aArray[2] = Width #ce Success : a 4 - element array containing the following information : $aPos2 = WinGetClientSize($GUI) #cs Success: a 2-element array containing the following information: $aArray[0] = Width of window's client area #ce Success: a 2-element array containing the following information: ; https://docs.microsoft.com/en-us/previous-versions//dd162897(v=vs.85) Local $sRect = DllStructCreate("Int[4]", $lparam) ; outer dimensions (includes borders) Local $left = DllStructGetData($sRect, 1, 1) Local $top = DllStructGetData($sRect, 1, 2) Local $Right = DllStructGetData($sRect, 1, 3) Local $bottom = DllStructGetData($sRect, 1, 4) ; border width Local $iEdgeWidth = ($aPos[2] - $aPos2[0]) / 2 Local $iHeadHeigth = $aPos[3] - $aPos2[1] - $iEdgeWidth * 2 Local $aEdges[2] $aEdges[0] = $aPos[2] - $aPos2[0] ; x $aEdges[1] = $aPos[3] - $aPos2[1] ; y $xClientSizeNew = $Right - $left - $aEdges[0] $xClientSizeNew = Round($xClientSizeNew / $iStep) * $iStep $yClientSizeNew = $bottom - $top - $aEdges[1] $yClientSizeNew = Round($yClientSizeNew / $iStep) * $iStep Switch $wparam Case $WMSZ_RIGHT ; calculate the new position of the right border DllStructSetData($sRect, 1, $left + $xClientSizeNew + $aEdges[0], 3) Case $WMSZ_BOTTOM ; calculate the new position of the bottom border DllStructSetData($sRect, 1, $top + $yClientSizeNew + $aEdges[1], 4) Case $WMSZ_BOTTOMRIGHT ; calculate the new position of both borders DllStructSetData($sRect, 1, $left + $xClientSizeNew + $aEdges[0], 3) DllStructSetData($sRect, 1, $top + $yClientSizeNew + $aEdges[1], 4) EndSwitch #cs If DllStructGetData($sRect, 1, 3) > @DesktopWidth Then ; $Right DllStructSetData($sRect, 1, DllStructGetData($sRect, 1, 3) - $iStep, 3) $xClientSizeNew -= $iStep EndIf If DllStructGetData($sRect, 1, 4) > @DesktopHeight Then ; $bottom DllStructSetData($sRect, 1, DllStructGetData($sRect, 1, 4), 4) $yClientSizeNew -= $iStep #ce If DllStructGetData($sRect, 1, 3) > @DesktopWidth Then ; $Right ; check if number of rows has changed If $iRows <> $yClientSizeNew / $iStep Then _SubArraySet($aMyMatrix[0], 2, $yClientSizeNew / $iStep) EndIf ; check if number of columns has changed If $iCols <> $xClientSizeNew / $iStep Then _SubArraySet($aMyMatrix[0], 1, $xClientSizeNew / $iStep) EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_SIZING ; set client area new sizes ; thanks to 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 ; ; #FUNCTION# ==================================================================================================================== ; Name...........: _GuiControlPanel ; 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, $style, $exStyle, $xPos = 0, $yPos = 0, $xBorder, $yBorder, $xSpace = 1, $ySpace = 1, $Group = false, , $sGrpTitle = "") ; 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 ; $Style - Defines the style of the control ; $exStyle - Defines the extended style of the 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, $style = -1, $exStyle = -1, $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 $PanelWidth = (($ctrlWidth + $xSpace) * $nrPerLine) - $xSpace + ($xBorder * 2) Local $PanelHeight = (($ctrlHeight + $ySpace) * $nrOfLines) - $ySpace + ($yBorder * 2) Local $hGroup If $Group Then If $sGrpTitle = "" Then $xPanelPos += 1 $yPanelPos += 1 $hGroup = GUICtrlCreateGroup("", $xPanelPos - 1, $yPanelPos - 7, $PanelWidth + 2, $PanelHeight + 8) Else $xPanelPos += 1 $yPanelPos += 15 $hGroup = GUICtrlCreateGroup($sGrpTitle, $xPanelPos - 1, $yPanelPos - 15, $PanelWidth + 2, $PanelHeight + 16) EndIf EndIf ; create the controls Local $aGuiGridCtrls[$nrPerLine * $nrOfLines + 1] Local $aPanelParams[14] = [ _ $ControlType, $nrPerLine, $nrOfLines, $ctrlWidth, $ctrlHeight, _ $xPanelPos, $yPanelPos, $xBorder, $yBorder, $xSpace, $ySpace, $PanelWidth, $PanelHeight, $hGroup] ReDim $idAddIcon[UBound($aGuiGridCtrls)] ReDim $idRemoveIcon[UBound($aGuiGridCtrls)] ReDim $idChangeIcon[UBound($aGuiGridCtrls)] For $i = 0 To $nrPerLine * $nrOfLines - 1 ; coordinates 1 based $col = Mod($i, $nrPerLine) + 1 ; Horizontal position within the grid (column) $row = Int($i / $nrPerLine) + 1 ; Vertical position within the grid (row) $left = $xPanelPos + ((($ctrlWidth + $xSpace) * $col) - $xSpace) - $ctrlWidth + $xBorder $top = $yPanelPos + ((($ctrlHeight + $ySpace) * $row) - $ySpace) - $ctrlHeight + $yBorder $text = $i + 1 ; "*" ; "." ; "(*)" ; create the control(s) $aGuiGridCtrls[$i + 1] = Execute("GUICtrlCreate" & $ControlType & "($text, $left, $top, $ctrlWidth, $ctrlHeight, $style, $exStyle)") If BitAND($exStyle, $WS_EX_ACCEPTFILES) = $WS_EX_ACCEPTFILES Then GUICtrlSetState($aGuiGridCtrls[$i + 1], $GUI_DROPACCEPTED) $idContextmenu = GUICtrlCreateContextMenu($aGuiGridCtrls[$i + 1]) $idAddIcon[$i] = GUICtrlCreateMenuItem("Add Icon", $idContextmenu) $idRemoveIcon[$i] = GUICtrlCreateMenuItem("Remove Icon", $idContextmenu) $idChangeIcon[$i] = GUICtrlCreateMenuItem("Change icon", $idContextmenu) Next If $Group Then GUICtrlCreateGroup("", -99, -99, 1, 1) ; close group $aGuiGridCtrls[0] = $aPanelParams Return $aGuiGridCtrls EndFunc ;==>_GuiControlPanel ; writes a value to an element of an array embedded in another array Func _SubArraySet(ByRef $aSubArray, $iElement, $vValue) $aSubArray[$iElement] = $vValue EndFunc ;==>_SubArraySet Func _ToggleGuiShowHide($hwnd, $bToggleGUI) If $bToggleGUI Then $bShowGUI = True DllCall($dllUser32, "int", "AnimateWindow", "hwnd", $hwnd, "int", 200, "long", Eval($GUI_IN)) ; show panel WinActivate($hwnd) Else $bShowGUI = False If Not $bFreezeWindow Then DllCall($dllUser32, "int", "AnimateWindow", "hwnd", $hwnd, "int", 200, "long", Eval($GUI_OUT)) ; hide panel EndIf EndFunc ;==>_ToggleGuiShowHide Func _Exit() Local $awPos If $bSaveSettings Then $awPos = WinGetPos($GUI) If $awPos[0] < 0 Then $awPos[0] = 0 If $awPos[1] < 0 Then $awPos[1] = 0 _SQLite_LaunchPad($hSQLiteDB, "UPDATE Settings SET LeftPos = " & $awPos[0] & ";") _SQLite_LaunchPad($hSQLiteDB, "UPDATE Settings SET TopPos = " & $awPos[1] & ";") _SQLite_LaunchPad($hSQLiteDB, "UPDATE Settings SET ButtonSize = " & $iStep & ";") _SQLite_LaunchPad($hSQLiteDB, "UPDATE Settings SET xColumns = " & ($aMyMatrix[0])[1] & ";") _SQLite_LaunchPad($hSQLiteDB, "UPDATE Settings SET GUIin = '" & $GUI_IN & "';") _SQLite_LaunchPad($hSQLiteDB, "UPDATE Settings SET GUIout = '" & $GUI_OUT & "';") _SQLite_LaunchPad($hSQLiteDB, "UPDATE Settings SET Freeze = '" & $bFreezeWindow & "';") _SQLite_LaunchPad($hSQLiteDB, "UPDATE Settings SET StartUp = '" & $bStartUp & "';") EndIf _SQLite_Close($hSQLiteDB) _SQLite_Shutdown() EndFunc ;==>_Exit #Region --- Restart Program --- Func _RestartProgram() If @Compiled And StringRegExpReplace(FileGetShortName(@ScriptFullPath), "^.*\.", "") <> 'a3x' Then Run(FileGetShortName(@ScriptFullPath)) Else Run(FileGetShortName(@AutoItExe) & " " & FileGetShortName(@ScriptFullPath)) EndIf Exit EndFunc ;==>_RestartProgram #EndRegion --- Restart Program --- Func _StartUpProgram($iStartup = True) If $iStartup And @Compiled And StringRegExpReplace(@ScriptFullPath, "^.*\.", "") <> 'a3x' Then FileCreateShortcut(@ScriptFullPath, @StartupDir & '\LaunchPad.lnk', $AppDataUser) ElseIf $iStartup Then FileCreateShortcut(@AutoItExe, @StartupDir & '\LaunchPad.lnk', $AppDataUser, FileGetShortName(@ScriptFullPath)) EndIf If Not $iStartup Then FileDelete(@StartupDir & '\LaunchPad.lnk') EndFunc ;==>_StartUpProgram Func _PickIconDlg($sFileName, $nIconIndex = 0, $hwnd = 0) Local $nRet, $aRetArr[2] $nRet = DllCall("shell32.dll", "int", "PickIconDlg", _ "hwnd", $hwnd, _ "wstr", $sFileName, "int", 1000, "int*", $nIconIndex) If Not $nRet[0] Then Return SetError(1, 0, -1) $aRetArr[0] = $nRet[2] $aRetArr[1] = $nRet[4] + 1 Return $aRetArr EndFunc ;==>_PickIconDlg Func _SQLite_LaunchPad($hwnd, $sqlCMD, $sqlExit = False) If Not _SQLite_Exec($hSQLiteDB, $sqlCMD) = $SQLITE_OK Then _ MsgBox($MB_SYSTEMMODAL, "SQLite Error", _SQLite_ErrMsg() & @CRLF & @CRLF & $sqlCMD, 0, $GUI) If $sqlExit Then Exit -1 EndFunc ;==>_SQLite_LaunchPad ; Return an array which xMin[0], xMax[1], yMin[2], yMax[3] Func _GetVirtualScreen() ;~ 'Virtual Desktop sizes Local $SM_XVIRTUALSCREEN = 76 ; 'Virtual Left Local $SM_YVIRTUALSCREEN = 77 ; 'Virtual Top Local $SM_CXVIRTUALSCREEN = 78 ; 'Virtual Width Local $SM_CYVIRTUALSCREEN = 79 ; 'Virtual Height Dim $xyScreen[4] Local $posWin = WinGetPos($GUI) Dim $VirtualScreen[4] = [$SM_XVIRTUALSCREEN, $SM_CXVIRTUALSCREEN, $SM_YVIRTUALSCREEN, $SM_CYVIRTUALSCREEN] For $x = 0 To 3 $xTemp = DllCall("user32.dll", "int", "GetSystemMetrics", "int", $VirtualScreen[$x]) If $x = 1 Then ;~ Note: $SM_CXVIRTUALSCREEN + $SM_XVIRTUALSCREEN = $RightSideScreen $xyScreen[$x] = ($xTemp[0] + $xyScreen[$x - 1]) - 1 Else $xyScreen[$x] = $xTemp[0] If $x = 3 Then $xyScreen[$x] -= 1 EndIf Next ;~ Note: The if statement below is to deal with multi monitors and undocked laptop move LaunchPad If (IsArray($posWin) And IsArray($xyScreen)) And ($posWin[0] > $xyScreen[1] Or $posWin[1] > $xyScreen[3]) Then $bSaveSettings = False WinMove($GUI, '', 0, 0) EndIf Return ($xyScreen) EndFunc ;==>_GetVirtualScreen Func _About() Local $sAboutText = 'LaunchPad you can easily create panels with buttons for starting applications on a Windows System.' $sAboutText &= @CRLF & @CRLF & 'Author: Chimp' & @CRLF $sAboutText &= 'Modify: Marcgforce, Danny35d' & @CRLF $sAboutText &= 'Credits: @KaFu, @Danyfirex, @mikell' GUISetState(@SW_DISABLE, $GUI) Local $AboutGUI = GuiCreate(' About LaunchPad' , 280, 160, Default, Default, $WS_CAPTION, Default, $GUI) GUISetBkColor (0xf8c848) GuiCtrlCreateLabel($sAboutText, 5, 10, 280, 100) GuiCtrlCreateLabel('____________________________________________', 10, 90, 260, 15, $SS_CENTER) ; separator $WebsiteLink = GuiCtrlCreateLabel('www.autoitscript.com/forum/topic/202048-button-deck/', 5, 105, 270, 20, $SS_CENTER) ; he he! GUICtrlSetCursor($WebsiteLink, 0) GUICtrlSetColor($WebsiteLink, 0x0000ff) Local $ok = GUICtrlCreateButton('OK', 10, 130, 70, 22, $BS_DEFPUSHBUTTON) GUISetState() While 1 $aboutMsg = GUIGetMsg() Select Case $aboutMsg = $GUI_EVENT_CLOSE ExitLoop Case $aboutMsg = $ok ExitLoop Case $aboutMsg = $WebsiteLink ShellExecute ('https://www.autoitscript.com/forum/topic/202048-button-deck/') EndSelect WEnd GUISetState(@SW_ENABLE, $GUI) GUIDelete($AboutGUI) Return EndFunc ;==>About Func Test() MsgBox(0, 0, ":)", 1) EndFunc ;==>Test2 points -
I was looking for a UDF using which I could Add and Update Pivot tables and Pivot Charts in Excel easily and could not find one that I could use. So I build this UDF. It has the following functions : _ExcelPivot_CreateCache ; Easily Create a pivot table data cache from a Sheet _ExcelPivot_CreateTable ; Create a table from a cache at a specified location on the sheet _ExcelPivot_RefreshTable ; Refresh the datatable data with a new cache _ExcelPivot_AddField ; Add a Field and Aggregate function to the Datatable _ExcelPivot_AddFilter ; Adds in the Filter to a specific field _ExcelPivot_ClearFilter ; Removes the filter for a field or all the filters in the table _ExcelPivot_GetRange ; Get specific areas of a Pivot as a Range Object _ExcelPivot_AddChart ; Add a Pivot Chart linked to a specific Pivot table Attached the UDF to this post. Please do let me know if I can improve or add additional functions to it. A detailed example on the usage is below. The excel file and the example can be downloaded from the Example.zip file attached. #include "ExcelPivot.au3" $oExcel = _Excel_Open() $oBook = _Excel_BookOpen($oExcel, @ScriptDir & "\TestPivot.xlsx") ;Create a Sheet to put the pivot into $pSheet = _Excel_SheetAdd($oBook, -1, False, 1) $pSheet.Name = "Pivot" ;Get the cache for the pivot table $pCache = _ExcelPivot_CreateCache($oBook, "Data") ;Add in the Pivot Table from the Cache _ExcelPivot_CreateTable($pCache, $pSheet, "A1", "FruitsPivot") ;Add in the Fields into the Pivot _ExcelPivot_AddField($pSheet, "FruitsPivot", "Category", "Filter") _ExcelPivot_AddField($pSheet, "FruitsPivot", "Product", "Row") _ExcelPivot_AddField($pSheet, "FruitsPivot", "Amount", "Value", "Sum", 1) ;Add in a Running total to the Pivot _ExcelPivot_AddField($pSheet, "FruitsPivot", "Amount", "Value", "Sum", 2, "PercentageRunningTotal", "Product") ;Filter only the fruits _ExcelPivot_Filter($pSheet, "FruitsPivot", "Category", "Fruit") ;Draw a Paretto Chart $chart = _ExcelPivot_AddChart($oBook, $pSheet, "FruitsPivot", "ColumnClustered", "Paretto", "E2", 570) $chart.Chart.FullSeriesCollection(1).ApplyDataLabels $chart.Chart.FullSeriesCollection(2).ChartType = 4 ;Change the percentage to a line graph $chart.Chart.FullSeriesCollection(2).AxisGroup = 2 ;Move it to secondary axis $chart.Chart.Axes(2, 2).MaximumScale = 1 ;Adjust to scale to 100% max ExcelPivot.au3 Example.zip1 point
-
1 point
-
How to fill website
noellarkin reacted to Danp2 for a topic
Here's one way to do it -- #include <IE.au3> Local $Url = "https://www.myhermes.de/versenden/paketschein-erstellen/" Local $oIE = _IECreate($Url, 1, 1, 1, 1) Local $oDocument = _IEDocGetObj($oIE) Local $oWindow = $oDocument.ParentWindow $oWindow.setTimeout("document.body.JSeval = eval; ", 0) ; a reference to the eval method Sleep(2000) ; give a little time to the browser to create above variables within the javascript environment. Local $JSeval = $oIE.Document.body.JSeval ; a reference to the eval javascript method from within AutoIt $JSeval('var myinput = jQuery("#senderAddressLastname")[0];') $JSeval('var nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value").set;') $JSeval('nativeInputValueSetter.call(myinput, "NewLastName");') $JSeval('var ev2 = document.createEvent("Event");') $JSeval('ev2.initEvent("input", true, true);') $JSeval('myinput.dispatchEvent(ev2);') $JSeval('myinput.blur();') Exit Note that this is just a Q&D example to demostrate that this is possible to do with Autoit1 point -
You might avoid the backreference by the use of \K - it's nothing but a detail Local $lFind = "(*UCP)(?s)" & "^.{" & $iStartCut - 1 & "}\K.{" & $iEndCut - $iStartCut + 1 & "}" Local $lResult = StringRegExpReplace($sInput, $lFind, "")1 point
-
nice enough, thanks @Deye, but that's another movie.....1 point
-
_StringWordTrimMid #include <Array.au3> Global $sString = "Today " & @CRLF & @CRLF & "I do not feel good i won't quit!" MsgBox(0, '', _StringWordTrimMid($sString, 2, 6)) ; Returns the string trimmed by words from $iStartCut to $iEndCut. Func _StringWordTrimMid($sInput, $iStartCut, $iEndCut) Local $a = StringRegExp($sInput, '[\H]+', 3) _ArrayDelete($a, $iStartCut & "-" & $iEndCut) Return _ArrayToString($a, " ") EndFunc1 point
-
Paul, you're welcome I just tried a little context menu inside _ArrayDisplay to choose the way of sorting, it seems to give good results. Lets have a look at the results first, then the personal modifications made to ArrayDisplayInternals.au3 code. Test script : #include <Array.au3> Global $aSortTest[12][1] = [["0x0B"], ["0x020"], ["0x0C"], ["0x03"], ["0x01"], ["0x0A"], _ ["0x0FF"], ["0x030"], ["0x04"], ["0x0E"], ["0x0D"], ["0x02"]] _ArrayDisplay($aSortTest) The pic above is your case : you need to choose the Numeric sort to be able to sort correctly a column of handles, pointers or any hex number starting with 0x In the pic above, we see it's very different if we want to sort the "Row" column. It needs a Natural sort to be correctly sorted because it is composed of letters ("Row ") and numbers. I suppose this is the main reason why Dev's forced the Natural sort in ArrayDisplay (when the default way of sorting in GuiListView.au3 is a Numeric sort +++) . Maybe if this Row column had only been composed of numeric elements (like the Excel column numerotation) then Dev's would have kept the original default Numeric sort found in GuiListView.au3... maybe Here is the code change in _ArrayDisplay, it's certainly optimizable but it may give ideas to users who want to tweak their own version of ArrayDisplayInternals.au3 1) Creation of a context menu associated to the listview (lines to be inserted after the listview has been created) ; Create ListView context menu (so user can choose the kind of sort he wants) Local $idContext_Menu = GUICtrlCreateContextMenu($idListView) Local $idContext_0 = GUICtrlCreateMenuItem("String sort", $idContext_Menu) Local $idContext_1 = GUICtrlCreateMenuItem("Numeric sort", $idContext_Menu) Local $idContext_2 = GUICtrlCreateMenuItem("Natural sort <<<", $idContext_Menu) ; default (keeps compatibility with old scripts) Local $iSort_Desired = 2, $iSort_Actual = -1 ; 0 = String sort, 1 = Numeric Sort, 2 = Natural sort 2) Inside the While... Wend loop, 3 Case added (Case $idContext_0 ... Case $idContext_1 ... Case $idContext_2) Case $idContext_0 ; String sort (chosen by user in context menu) $iSort_Desired = 0 GUICtrlSetData($idContext_0, "String sort <<<") GUICtrlSetData($idContext_1, "Numeric sort") GUICtrlSetData($idContext_2, "Natural sort") Case $idContext_1 ; Numeric sort (chosen by user in context menu) $iSort_Desired = 1 GUICtrlSetData($idContext_0, "String sort") GUICtrlSetData($idContext_1, "Numeric sort <<<") GUICtrlSetData($idContext_2, "Natural sort") Case $idContext_2 ; Natural sort (chosen by user in context menu) $iSort_Desired = 2 GUICtrlSetData($idContext_0, "String sort") GUICtrlSetData($idContext_1, "Numeric sort") GUICtrlSetData($idContext_2, "Natural sort <<<") 3) Inside the While... Wend loop, modifications made in Case $idListView code : Case $idListView ; left click on listview column header => sort If $iSort_Desired <> $iSort_Actual Then ; note that $iSort_Actual = -1 at 1st passage DllCallbackFree($__g_aArrayDisplay_SortInfo[2]) __ArrayDisplay_RegisterSortCallBack($idListView, $iSort_Desired, True, "__ArrayDisplay_SortCallBack") $iSort_Actual = $iSort_Desired EndIf ; Kick off the sort callback __ArrayDisplay_SortItems($idListView, GUICtrlGetState($idListView)) 4) Original line #448 to be deleted because it was placed outside the While... Wend loop (eventual sorts are now registered / unregistered within the While... Wend loop, inside the Case $idListView as shown just above) #448 __ArrayDisplay_RegisterSortCallBack($idListView, 2, True, "__ArrayDisplay_SortCallBack") 5) Original lines #598 et #599 amended to convert strings to numbers when "0x" is found at the beginning of the string. These 2 lines are originally already included inside a test where the user choosed voluntarily a Numeric sort. In case you're afraid that a string starting with "0x" is not a valid hex number, then you can use guinness _IsHex() function, found in this link, where he checks the string with a Regex expression '^0x[[:xdigit:]]+$' If StringIsInt($sVal1) Or StringIsFloat($sVal1) Or StringLeft($sVal1, 2) = "0x" Then $sVal1 = Number($sVal1) If StringIsInt($sVal2) Or StringIsFloat($sVal2) Or StringLeft($sVal2, 2) = "0x" Then $sVal2 = Number($sVal2) 6) As discussed in this link , original line #560 has to be moved "just below" the 2 lines below it. This will make the sort arrow visible when you click on a column header in ArrayDisplay It will also correct the value found in the variable $hHeader and in the array element $__g_aArrayDisplay_SortInfo[10] This is fixed in trac ticket #3791 ;~ Local Const $LVM_GETHEADER = (0x1000 + 31) ; 0x101F Local $hHeader = HWnd(GUICtrlSendMsg($hWnd, 0x101F, 0, 0)) If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) 7) Finally, DllCallbackFree should be added before both GuiDelete($hGUI) as discussed in this link : DllCallbackFree($__g_aArrayDisplay_SortInfo[2]) GUIDelete($hGUI) Hope I didn't miss something important. If Mods think it's better to upload (or not) the complete amended ArrayDisplayInternals.au3 somewhere (for test or whatever) I'll do it. I just thought it could be a bit dangerous to share it fully here, because all these tweaks are very new. Dinner time Edit : 11/21/2020 Parts 1) and 2) in the code above can be scripted differently, to get a shorter code based on menu radioitems. 1) Creation of a context menu associated to the listview (lines to be inserted after the listview has been created) ; Create ListView context menu (so user can choose the kind of sort he wants) Local $idContext_Menu = GUICtrlCreateContextMenu($idListView) Local $idContext_0 = GUICtrlCreateMenuItem("String sort", $idContext_Menu, -1, 1) ; menuradioitem Local $idContext_1 = GUICtrlCreateMenuItem("Numeric sort", $idContext_Menu, -1, 1) ; menuradioitem Local $idContext_2 = GUICtrlCreateMenuItem("Natural sort", $idContext_Menu, -1, 1) ; menuradioitem GUICtrlSetState(-1, 1) ; $GUI_CHECKED = 1 (Natural sort is the default, to keep compatibility) Local $iSort_Desired = 2, $iSort_Actual = -1 ; 0 = String sort, 1 = Numeric Sort, 2 = Natural sort 2) Inside the While... Wend loop, 3 Case added (Case $idContext_0 ... Case $idContext_1 ... Case $idContext_2) Case $idContext_0 ; String sort (chosen by user in context menu) $iSort_Desired = 0 Case $idContext_1 ; Numeric sort (chosen by user in context menu) $iSort_Desired = 1 Case $idContext_2 ; Natural sort (chosen by user in context menu) $iSort_Desired = 2 This will display a context menu based on menu radio items : Thanks to lemony & Malkey in this post from 2008 (I discovered it right now !)1 point
-
By default . (dot) matches eveything except newlines. By prepending (?s) to the pattern, subsequent . will match newlines as well. TABs are matched by . in all cases. To be completely generic you may even want to add (*UCP) at the very start of the pattern: this way, extra Unicode newline sequences are matched as well when using (?s).1 point
-
This ? Func _StringTrimMid2($sInput, $iStartCut, $iEndCut) Return StringRegExpReplace ($sInput, "(.{" & $iStartCut-1 & "})(.{" & $iEndCut-$iStartCut+1 & "})(.{" & StringLen($sInput)-$iEndCut-1 & "})","$1$3") EndFunc1 point
-
1 point
-
convert tabs to spaces
Professor_Bernd reacted to Gianni for a topic
Hi @Professor_Bernd, the following function (_StringSpacesToTab) should work for that case. Here too, as already said, the TabLen parameter is important to obtain the correct result relative to the TabLens of the environment in which the resulting string will be used. Also, if the input string already contains some @tabs, this function fails, so it would be better to pass the string to the TabsToSpace function first in order to convert any @tabs to spaces before submitting it to this SpacesToTabs function (I hope there are no errors ) Here we go... #include <string.au3> _Example() Func _Example() Local $sMyString = "1 2 3 4" ; <--- random string that contains spaces ConsoleWrite($sMyString & @CRLF) ; we use 8 as second parametre because the AutoIt console has a Tablen of 8 as well ConsoleWrite(_StringSpacesToTabs($sMyString, 8) & @CRLF) ; <- contains @tabs (and residual spaces) ; - NOTE - ; ------------------------------------------------------------------------------------------------- ; If input strings contains some @tab, the _StringSpacesToTabs() function fails ; so you should call it like this: _StringSpacesToTabs(_StringTabsToSpaces($sMyString)) so to ensure ; that no @tabs are contained in the input string. ; ------------------------------------------------------------------------------------------------- ; example ConsoleWrite(@CRLF & @CRLF & "... if input string contains also some @tabs ..." & @CRLF) $sMyString = @TAB & "Hello " & @TAB & "Good " & @TAB & "Morning <" ; <--- contains spaces and @tab ConsoleWrite($sMyString & @CRLF) ; first convert @tabs to spaces (if any), then convert spaces to @tabs ConsoleWrite(_StringSpacesToTabs(_StringTabsToSpaces($sMyString, 8), 8) & @CRLF) EndFunc ;==>_Example Func _StringSpacesToTabs($sInput, $iTabLen = 8) Local Static $iTab = @TAB, $sSpc = ' ' Local $i1 = StringLen($sInput) ; start from the last char of the string While $i1 ; Check if there is a space before a TabStop position While (StringMid($sInput, $i1, 1) == $sSpc) And (Mod($i1, $iTabLen) = 0) $iStartSpaces = $i1 ; if so then remember this 'start' position ... ; ... and search for any additional spaces (only up to tablen) While (StringMid($sInput, $i1 - 1, 1) == $sSpc) And (Mod($i1 - 1, $iTabLen)) $i1 -= 1 WEnd ; remove found spaces from the string and replace with a @tab $sInput = StringLeft($sInput, $i1 - 1) & $iTab & StringMid($sInput, $iStartSpaces + 1) WEnd ; go to check next char (backwards) $i1 -= 1 WEnd Return $sInput EndFunc ;==>_StringSpacesToTabs Func _StringTabsToSpaces($sString, $iTabLen = 8) Local Static $iTab = @TAB, $sSpc = ' ' Local $iMod, $iSpaceLeft Local $iTabPos = StringInStr($sString, $iTab, 1) While $iTabPos $iMod = Mod($iTabPos, $iTabLen) $iSpaceLeft = $iMod ? $iTabLen - $iMod : 0 $sString = StringReplace($sString, $iTab, _StringRepeat($sSpc, $iSpaceLeft + 1), 1, 1) $iTabPos = StringInStr($sString, $iTab, 1) WEnd Return $sString EndFunc ;==>_StringTabsToSpaces1 point -
You could check that the input has lost focus then run a function. #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.14.2 Author: Skysnake Script Function: Problem traversing GUI controls (input), populated from another and firing without changing first The GUI does not have buttons instead the INPUT controls trigger the various CASE statements However, the INPUT requires a touch before it fires. Is there a way to work around the "touch requirment"? #ce ---------------------------------------------------------------------------- #include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <guiconstants.au3> Local $hGUI = GUICreate("No Button GUI", 600, 400) Local $input1 = GUICtrlCreateInput("1", 8, 8, -1, -1, BitOR($ES_RIGHT, $ES_NUMBER)) Local $input2 = GUICtrlCreateInput("1", 8, 32, -1, -1, BitOR($ES_RIGHT, $ES_NUMBER)) Local $input3 = GUICtrlCreateInput("0", 8, 56, -1, -1, BitOR($ES_RIGHT, $ES_NUMBER)) GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND") ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) ; Display the child GUI. GUISetState(@SW_SHOW) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete($hGUI) ExitLoop Case $input2 RunInput2() EndSwitch WEnd Func RunInput2() GUICtrlSetData($input3, GUICtrlRead($input1) + GUICtrlRead($input2)) EndFunc Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam) Local $nNotifyCode = BitShift($wParam, 16) Local $nID = BitAND($wParam, 0xFFFF) Local $hCtrl = $lParam Switch $nID Case $input2 Switch $nNotifyCode Case $EN_KILLFOCUS RunInput2() EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>MY_WM_COMMAND1 point
-
Sort arrow in _ArrayDisplay ?
Musashi reacted to pixelsearch for a topic
That's right, and also because line #565 is useless in ArrayDisplayInternals.au3, where the array $__g_aArrayDisplay_SortInfo[] is a 1D array : $__g_aArrayDisplay_SortInfo[1] = $hWnd ; Handle of listview The corresponding "original" line of code is important in GuiListView.au3, where the array $__g_aListViewSortInfo[][] is a 2D array : $__g_aListViewSortInfo[$iIndex][1] = $hWnd When a sort is registered in GuiListView.au3, using _GUICtrlListView_RegisterSortCallBack(), then a row is added to the 2D array, with the listview handle acting like an "index" to process the correct row later in different functions, i.e. __GUICtrlListView_Sort() and _GUICtrlListView_SortItems() and _GUICtrlListView_UnRegisterSortCallBack(), this last function removing a row from the 2D array, after having correctly de-allocated the resource with the instruction DllCallbackFree Which leads to another possible issue : why isn't the resource de-allocated in _ArrayDisplay ? Please have a look at this script : #include <Array.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Example() Func Example() Local $aSortTest[2][3] = [["1a", "1b", "1c"], ["2a", "2b", "2c"]] Local $hGUI = GUICreate("Test", 200, 100, -1, 80, -1, $WS_EX_TOPMOST) Local $idButton = GUICtrlCreateButton("Click me", 60, 40, 80, 30) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idButton GUISetState(@SW_DISABLE, $hGUI) ; _ArrayDisplay($aSortTest) _ArrayDisplay($__g_aArrayDisplay_SortInfo) ; global array in ArrayDisplayInternals.au3 GUISetState(@SW_ENABLE, $hGUI) EndSwitch WEnd GUIDelete($hGUI) EndFunc ;==>Example Each click on the test button will call ArrayDisplay, then you close the ArrayDisplay GUI and click on the test button again. After you do this 5 times, you'll end with this kind of display : This red-circled "5" means that DllCallbackRegister() has been called 5 times without de-allocating it. But if we look at the help file, topic DllCallbackRegister, this is what we read : When finished working with a callback, call the DllCallbackFree() function to close it. AutoIt normally closes all files upon termination, but explicitly calling DllCallbackFree() is still a good idea. In the precedent script, we're not terminating AutoIt because each ArrayDisplay call brings us back to our script. To fix this potential issue, here is what could be done, by adding 2 lines (DllCallbackFree) in ArrayDisplayInternals.au3 Case $idExit_Script ; Clear up DllCallbackFree($__g_aArrayDisplay_SortInfo[2]) ; <===================== GUIDelete($hGUI) Exit EndSwitch WEnd ; Clear up DllCallbackFree($__g_aArrayDisplay_SortInfo[2]) ; <===================== GUIDelete($hGUI) Opt("GUICoordMode", $iCoordMode) ; Reset original Coord mode Opt("GUIOnEventMode", $iOnEventMode) ; Reset original GUI mode ;~ Opt("GUIDataSeparatorChar", $sCurr_Separator) ; Reset original separator Return 1 EndFunc ;==>__ArrayDisplay_Share Now we have a correct display & de-allocation, even after we click several times the button in the test script : 2 remarks : * Row 10 indicates a wrong header handle 0x00000000 in the 1st pic. Trac ticket #3791 fixes this issue in the 2nd pic. * In the test script, if you uncomment the line ; _ArrayDisplay($aSortTest) Then you'll notice that the value in Row2 is incremented 2 by 2 (1-3-5...) as there are now 2 ArrayDisplay processed in the script for each clic on the test button. If you think this is a potential issue, please let me know so I'll open a trac ticket, suggesting to add the 2 DllCallbackFree() lines to ArrayDisplayInternals.au31 point -
WMI in Autoit - (Moved)
DirtyJohny reacted to GokAy for a topic
Ok, figured it out once I was able to run it. My bad really You may be an idiot, but I am the King of Idiots! Messed up with check if $aDisplayInfo is an array. This window being slightly transparent makes it hard to read. Also, friendlyname as you see from my laptop (Display 2), may not show any info. Anyway, here is working script: #RequireAdmin #NoTrayIcon #include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <ButtonConstants.au3> #include <Constants.au3> #include <Array.au3> Opt("MustDeclareVars",1) ;??? ??? ????????, ????? ';' ??????? ???????????? ? ?? ??? ?? ?????? ?? ?????? ???????. Global $iKabina, $iType, $iModel, $iSerialNum, $iInv ;????????? ??????????, ??????? ????? ?????????????? ? ????? Global $rKabina, $rType, $rModel, $rSerialNum, $rInv, $Main, $iConnect, $hFile, $sInfo, $CopyBtn, $fFile = @ScriptDir & "\" & "(" & @MDAY & "." & @MON & "." & @YEAR & ")" & ".txt" $Main = GUICreate('Inventarisation', 315, 352) ;?????? ??????? ???? GUISetBkColor(0x02101B) $iKabina = GUICtrlCreateInput('', 20, 30, 272, 21) $iType = GUICtrlCreateInput('', 20, 75, 272, 21) $iModel = GUICtrlCreateInput('', 20, 120, 272, 21) $iSerialNum = GUICtrlCreateInput('', 20, 165, 272, 21) $iInv = GUICtrlCreateInput('', 20, 210, 272, 21) GUISetFont(10, 800, 0, 'Tahoma'); ????????????? ????? ?? ????????? ??? ??????????? ????????? GUI-????. $iConnect = GUICtrlCreateButton('Send', 23, 305, 267, 33, $BS_DEFPUSHBUTTON) ;??????? ?????? ??????????? GUICtrlSetDefColor(0xDEDEDE); ????????????? ???? ?????? ?? ????????? ??? ??????????? ????????? GUI-????. GUICtrlCreateLabel('Cabinet', 20, 10, 150, 17) GUICtrlCreateLabel('Type', 20, 55, 150, 17) GUICtrlCreateLabel('Model', 20, 100, 150, 17) GUICtrlCreateLabel('?erial number PC', 20, 145, 150, 17) GUICtrlCreateLabel('Inventarisation number', 20, 190, 150, 17) WinSetTrans($Main, '', 0) GUISetState(@SW_SHOW) For $i = 0 To 230 Step 9 Sleep(10) WinSetTrans($Main, '', $i) ;???????????? 0-255 Next $hFile = FileOpen(@ScriptDir & "\" & "(" & @MDAY & "." & @MON & "." & @YEAR & ")" & ".txt", 1) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $iConnect $rKabina = GUICtrlRead($iKabina) $rType = GUICtrlRead($iType) $rModel = GUICtrlRead($iModel) $rSerialNum = GUICtrlRead($iSerialNum) $rInv = GUICtrlRead($iInv) Select Case (Not StringStripWS($rKabina, 8)) MsgBox(16 + 8192 + 262144, 'Error', '???? ??????? - ??????') Case (Not StringStripWS($rType, 8)) MsgBox(16 + 8192 + 262144, 'Error', '???? ??? - ??????') Case (Not StringStripWS($rModel, 8)) MsgBox(16 + 8192 + 262144, 'Error', '???? ?????? - ??????') Case (Not StringStripWS($rSerialNum, 8)) MsgBox(16 + 8192 + 262144, 'Error', '???? ???????? ????? - ??????') Case (Not StringStripWS($rInv, 8)) MsgBox(16 + 8192 + 262144, 'Error', '???? ??????????? - ??????') Case $hFile = -1 MsgBox(4096, '??????', '?????????? ??????? ????.') Case Else _hide() ;????????? ??? ???????? ????? ? ?????? $sInfo = '======================================================================================' & @CRLF & _ '[??????????????:]' & @CRLF & _ @TAB & 'Date: ................... ' & @MDAY & '.' & @MON & '.' & @YEAR & ' ' & @CRLF & _ @TAB & 'Cabinet: ................ ' & $rKabina & @CRLF & _ @TAB & 'Type: .................... ' & $rType & @CRLF & _ @TAB & 'Model: ................. ' & $rModel & @CRLF & _ @TAB & '?erial number PC: ......... ' & $rSerialNum & @CRLF & _ @TAB & 'Inventarisation number: ...... ' & $rInv & @CRLF & _ @TAB & 'Current User: ......... ' & @UserName & @CRLF & @CRLF $sInfo &= _InfoPC() FileWrite($hFile, $sInfo) FileClose($hFile) _show() ;???????? ??? ???????? ????? ? ?????? _ShowOtchot() EndSelect EndSwitch WEnd Func _InfoPC() Local $ObjService = ObjGet('winmgmts:{impersonationLevel = impersonate}!\\' & @ComputerName & '\root\cimv2') Local $ObjMB = $ObjService.ExecQuery('SELECT * FROM Win32_BaseBoard', 'WQL', 0x30) Local $ObjProcessor = $ObjService.ExecQuery('SELECT * FROM Win32_Processor', 'WQL', 0x30) Local $ObjMemory = $ObjService.ExecQuery('SELECT * FROM Win32_PhysicalMemory') Local $ObjNet = $ObjService.ExecQuery('SELECT * FROM Win32_NetworkAdapter', 'WQL', 0x30) Local $ObjGraph = $ObjService.ExecQuery('SELECT * FROM Win32_VideoController', 'WQL', 0x30) Local $ObjDrive = $ObjService.ExecQuery('SELECT * FROM Win32_DiskDrive', 'WQL', 0x30) Local $ObjCDDrive = $ObjService.ExecQuery('SELECT * FROM Win32_CDROMDrive', 'WQL', 0x30) Local $ObjRam = $ObjService.ExecQuery('SELECT * FROM Win32_ComputerSystem') Local $sNameComput = RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\DataStore\Machine\0', 'szTargetName') Local $sProduct = RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion', 'ProductName') Local $sBuild = RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion', 'ReleaseId') Local $sItemM, $sInfo = '[Configuration:]' & @CRLF & @TAB & 'Computer name: ......... ' & $sNameComput & @CRLF & _ @TAB & 'Operating system: ... ' & $sProduct & ' ' & $sBuild & ' ' & '(' & @OSArch & ')' & @CRLF If IsObj($ObjService) Then For $objItemP In $ObjProcessor $sInfo &= @TAB & 'Processor: .............. ' & $objItemP.Name & @CRLF Next For $objItemMB In $ObjMB $sInfo &= @TAB & '?Motherboard: ...... ' & $objItemMB.Product & @CRLF Next For $ObjItemM In $ObjMemory $sItemM = $objItemM.Speed Next For $objItemR In $ObjRam $sInfo &= @TAB & 'RAM: .................... ' & Round($objItemR.TotalPhysicalMemory / 1024 / 1024 ^ 2, 0) & ' GB | ' & $ObjMemory.Count & ' pieces | ' & $sItemM & ' Mhz' & @CRLF Next For $ObjItemG In $ObjGraph $sInfo &= @TAB & 'Videocard: ............. ' & $ObjItemG.Name & ' | RAM: ' & $ObjItemG.AdapterRAM / 1024 ^ 2 & ' Mb' & @CRLF Next For $ObjItemD In $ObjDrive $sInfo &= @TAB & 'Hard drives: ........... ' & $ObjItemD.Model & ' | Size: ' & Round($ObjItemD.Size / 1024 / 1024 / 1024) & ' Gb' & @CRLF Next For $ObjItemCD In $ObjCDDrive $sInfo &= @TAB & 'CD-Drive: ............... ' & $ObjItemCD.Name & @CRLF Next For $ObjItemN In $ObjNet If $ObjItemN.PhysicalAdapter = True Then $sInfo &= @TAB & 'Network adapter: ........ ' & $ObjItemN.Name & @CRLF EndIf Next EndIf Local $aDisplayInfo = Display_Info() if $aDisplayInfo = "" then ConsoleWrite("$aDisplayInfo is not an array" & @crlf) Else for $i = 0 to (ubound($aDisplayInfo)/2)-1 $sInfo &= @TAB & "Display " & $i+1 & ": UserFriendlyName: " & $aDisplayInfo[(2*$i)] & @CRLF $sInfo &= @TAB & "Display " & $i+1 & ": SerialNumberId: " & $aDisplayInfo[(2*$i)+1] & @CRLF Next EndIf $sInfo &= @CRLF Return $sInfo EndFunc ;==>_InfoPC Func _hide() ;???????. ????????? ???????? ????? ? ??????, ???? ???????? ?????? GUICtrlSetState($iConnect, $GUI_disable) GUICtrlSetState($iKabina, $GUI_disable) GUICtrlSetState($iType, $GUI_disable) GUICtrlSetState($iModel, $GUI_disable) GUICtrlSetState($iSerialNum, $GUI_disable) GUICtrlSetState($iInv, $GUI_disable) EndFunc ;==>_hide Func _show() ;???????. ???????? ???????? ????? ? ??????, ????? ?????? ????????? GUICtrlSetState($iConnect, $GUI_enable) GUICtrlSetState($iKabina, $GUI_enable) GUICtrlSetState($iType, $GUI_enable) GUICtrlSetState($iModel, $GUI_enable) GUICtrlSetState($iSerialNum, $GUI_enable) GUICtrlSetState($iInv, $GUI_enable) EndFunc ;==>_show Func _a() Local $sls=ObjGet("winmgmts:{impersonationLevel=impersonate," _ &"authenticationLevel=Pkt}!\\"& _ @ComputerName&'\root\wmi'),$lss=$sls.ExecQuery _ ('SELECT * FROM WmiMonitorID'), _ $lll,$sll,$sss="",$lsl,$lls,$i,$z For $z In $lss $lsl=$z.UserFriendlyName For $i=0 To Ubound($lsl)-1 if ($lsl[$i]) Then $lll&=Chr($lsl[$i]) Next $lls=$z.SerialNumberID For $i=0 To Ubound($lls)-1 if ($lls[$i]) Then $sll&=Chr($lls[$i]) Next $sss&="Model"&@TAB&@TAB&": "&$lll&@CR&"Serial Number"&@TAB&": "&$sll&@CR&@CR $lll="" $sll="" Next $lss=Null $sls=Null $sInfo &= @CRLF EndFunc Func _ShowOtchot() Local $Form1 = GUICreate("Order", 482, 438, Default, Default, Default, 0x00000080, $Main) GUISetBkColor(0x02101B) Local $Edit1 = GUICtrlCreateEdit("", 0, 0, 482, 385) GUICtrlSetData(-1, FileRead($fFile)) $CopyBtn = GUICtrlCreateButton("Copy in txt", 194, 400, 99, 25, $BS_DEFPUSHBUTTON) For $i = 0 To 230 Step 9 Sleep(10) WinSetTrans($Form1, '', $i) ;???????????? 0-255 Next GUISetState(@SW_SHOW) While 1 Local $msg = GUIGetMsg() Switch $msg Case $CopyBtn ClipPut(GUICtrlRead($Edit1)) DirCreate (@ScriptDir & "\COPY") FileCopy(@ScriptDir & "\" & "(" & @MDAY & "." & @MON & "." & @YEAR & ")" & ".txt", @ScriptDir & "\COPY", 1) MsgBox(64, "??????", 'Copied', Default, $Main) Case -3 GUIDelete($Form1) WinActivate($Main) ExitLoop EndSwitch WEnd EndFunc Func Display_Info() Local $oComErr, $oWmi, $oInstances $oComErr = ObjEvent("AutoIt.Error", comm_error_handler) #forceref $oComErr ;Get WMI object $oWmi = ObjGet("winmgmts:\root\WMI") If Not IsObj($oWmi) Then Exit MsgBox($MB_ICONERROR, "ERROR", "Unable to create WMI object") ;Select object instances $oInstances = $oWmi.ExecQuery("SELECT * FROM WMIMonitorID") If $oInstances.Count = 0 Then Exit MsgBox($MB_ICONWARNING,"Warning","No objects found") ; Changed part Local $aReturn[2] ; change number if you want to return more info Local $iDisplayCount = 1 ;Display instance properties For $oInstance in $oInstances With $oInstance ConsoleWrite(@CRLF) if ubound($aReturn) < $iDisplayCount * 2 then redim $aReturn[2*$iDisplayCount] If IsArray(.UserFriendlyName) Then $aReturn[2*($iDisplayCount-1)] = convert_uint16_array_to_string(.UserFriendlyName) ;StringFormat("UserFriendlyName = %s", convert_uint16_array_to_string(.UserFriendlyName)) If IsArray(.SerialNumberId) Then $aReturn[2*($iDisplayCount-1)+1] = convert_uint16_array_to_string(.SerialNumberId) ;StringFormat("SerialNumberId = %s", convert_uint16_array_to_string(.SerialNumberId)) $iDisplayCount += 1 EndWith Next Return $aReturn EndFunc Func convert_uint16_array_to_string($aBytes) Local $s = "" For $i in $aBytes If $i <> 0 Then $s &= Chr($i) Next Return $s EndFunc Func comm_error_handler($oComError) ConsoleWrite(@CRLF) ConsoleWrite(StringFormat("Script Line = %s", $oComError.ScriptLine) & @CRLF) ConsoleWrite(StringFormat("Win Err Desc = %s", StringStripWS($oComError.WinDescription, $STR_STRIPTRAILING)) & @CRLF) ConsoleWrite(StringFormat("Error Number = %i (0x%x)", $oComError.Number, $oComError.Number) & @CRLF) ConsoleWrite(StringFormat("Error Desc = %s", $oComError.Description) & @CRLF) Exit EndFunc Edit: Couldn't post sooner as the forums were down1 point -
WMI in Autoit - (Moved)
DirtyJohny reacted to GokAy for a topic
@DirtyJohny I guess I am supposed to enter some text at the boxes when running your script. And I just get an error, when I click "SEND". One of these: Select Case (Not StringStripWS($rKabina, 8)) MsgBox(16 + 8192 + 262144, 'Error', '???? ??????? - ??????') Case (Not StringStripWS($rType, 8)) MsgBox(16 + 8192 + 262144, 'Error', '???? ??? - ??????') Case (Not StringStripWS($rModel, 8)) MsgBox(16 + 8192 + 262144, 'Error', '???? ?????? - ??????') Case (Not StringStripWS($rSerialNum, 8)) MsgBox(16 + 8192 + 262144, 'Error', '???? ???????? ????? - ??????') Case (Not StringStripWS($rInv, 8)) MsgBox(16 + 8192 + 262144, 'Error', '???? ??????????? - ??????') Case $hFile = -1 MsgBox(4096, '??????', '?????????? ??????? ????.') Case Else _hide() ;????????? ??? ???????? ????? ? ??????1 point -
WMI in Autoit - (Moved)
DirtyJohny reacted to GokAy for a topic
@TheXman Yeah, I just ran it. And I see the problem. There is no friendlyname for laptop display and serial is 0. So, it is working as intended. InstanceName = DISPLAY\SAM05C5\4&a0cd8b3&0&UID198147_0 YearOfManufacture = 2010 WeekOfManufacture = 14 UserFriendlyName = SyncMaster ManufacturerName = SAM SerialNumberId = 1110529591 ProductCodeID = 05C5 InstanceName = DISPLAY\LGD04B9\4&a0cd8b3&0&UID265988_0 YearOfManufacture = 2015 WeekOfManufacture = 0 ManufacturerName = LGD SerialNumberId = 0 ProductCodeID = 04B91 point -
WMI in Autoit - (Moved)
DirtyJohny reacted to TheXman for a topic
@GokAy What do you get on your laptop when you run my original example?1 point -
WMI in Autoit - (Moved)
DirtyJohny reacted to GokAy for a topic
Can you try this one? #include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <ButtonConstants.au3> #include <Constants.au3> #include <Array.au3> #RequireAdmin #NoTrayIcon ;??? ??? ????????, ????? ';' ??????? ???????????? ? ?? ??? ?? ?????? ?? ?????? ???????. ;~ Global $aDispTest = Display_Info() ;~ if $aDispTest = "" Then ;~ ConsoleWrite("problem" & @crlf) ;~ Else ;~ for $i = 0 to (ubound($aDispTest)/2)-1 ;~ ConsoleWrite("Str: " & $i & " " & $aDispTest[(2*$i)] & @crlf) ;~ ConsoleWrite("Str: " & $i & " " & $aDispTest[(2*$i)+1] & @crlf) ;~ Next ;~ EndIf ;~ Exit Global $iKabina, $iType, $iModel, $iSerialNum, $iInv ;????????? ??????????, ??????? ????? ?????????????? ? ????? Global $rKabina, $rType, $rModel, $rSerialNum, $rInv, $Main, $iConnect, $hFile, $sInfo, $CopyBtn, $fFile = @ScriptDir & "\" & "(" & @MDAY & "." & @MON & "." & @YEAR & ")" & ".txt" $Main = GUICreate('Inventarisation', 315, 352) ;?????? ??????? ???? GUISetBkColor(0x02101B) $iKabina = GUICtrlCreateInput('', 20, 30, 272, 21) $iType = GUICtrlCreateInput('', 20, 75, 272, 21) $iModel = GUICtrlCreateInput('', 20, 120, 272, 21) $iSerialNum = GUICtrlCreateInput('', 20, 165, 272, 21) $iInv = GUICtrlCreateInput('', 20, 210, 272, 21) GUISetFont(10, 800, 0, 'Tahoma'); ????????????? ????? ?? ????????? ??? ??????????? ????????? GUI-????. $iConnect = GUICtrlCreateButton('Send', 23, 305, 267, 33, $BS_DEFPUSHBUTTON) ;??????? ?????? ??????????? GUICtrlSetDefColor(0xDEDEDE); ????????????? ???? ?????? ?? ????????? ??? ??????????? ????????? GUI-????. GUICtrlCreateLabel('Cabinet', 20, 10, 150, 17) GUICtrlCreateLabel('Type', 20, 55, 150, 17) GUICtrlCreateLabel('Model', 20, 100, 150, 17) GUICtrlCreateLabel('?erial number PC', 20, 145, 150, 17) GUICtrlCreateLabel('Inventarisation number', 20, 190, 150, 17) WinSetTrans($Main, '', 0) GUISetState(@SW_SHOW) For $i = 0 To 230 Step 9 Sleep(10) WinSetTrans($Main, '', $i) ;???????????? 0-255 Next $hFile = FileOpen(@ScriptDir & "\" & "(" & @MDAY & "." & @MON & "." & @YEAR & ")" & ".txt", 1) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $iConnect $rKabina = GUICtrlRead($iKabina) $rType = GUICtrlRead($iType) $rModel = GUICtrlRead($iModel) $rSerialNum = GUICtrlRead($iSerialNum) $rInv = GUICtrlRead($iInv) Select Case (Not StringStripWS($rKabina, 8)) MsgBox(16 + 8192 + 262144, 'Error', '???? ??????? - ??????') Case (Not StringStripWS($rType, 8)) MsgBox(16 + 8192 + 262144, 'Error', '???? ??? - ??????') Case (Not StringStripWS($rModel, 8)) MsgBox(16 + 8192 + 262144, 'Error', '???? ?????? - ??????') Case (Not StringStripWS($rSerialNum, 8)) MsgBox(16 + 8192 + 262144, 'Error', '???? ???????? ????? - ??????') Case (Not StringStripWS($rInv, 8)) MsgBox(16 + 8192 + 262144, 'Error', '???? ??????????? - ??????') Case $hFile = -1 MsgBox(4096, '??????', '?????????? ??????? ????.') Case Else _hide() ;????????? ??? ???????? ????? ? ?????? $sInfo = '======================================================================================' & @CRLF & _ '[??????????????:]' & @CRLF & _ @TAB & 'Date: ................... ' & @MDAY & '.' & @MON & '.' & @YEAR & ' ' & @CRLF & _ @TAB & 'Cabinet: ................ ' & $rKabina & @CRLF & _ @TAB & 'Type: .................... ' & $rType & @CRLF & _ @TAB & 'Model: ................. ' & $rModel & @CRLF & _ @TAB & '?erial number PC: ......... ' & $rSerialNum & @CRLF & _ @TAB & 'Inventarisation number: ...... ' & $rInv & @CRLF & _ @TAB & 'Current User: ......... ' & @UserName & @CRLF & @CRLF $sInfo &= _InfoPC() FileWrite($hFile, $sInfo) FileClose($hFile) _show() ;???????? ??? ???????? ????? ? ?????? _ShowOtchot() EndSelect EndSwitch WEnd Func _InfoPC() Local $ObjService = ObjGet('winmgmts:{impersonationLevel = impersonate}!\\' & @ComputerName & '\root\cimv2') Local $ObjMB = $ObjService.ExecQuery('SELECT * FROM Win32_BaseBoard', 'WQL', 0x30) Local $ObjProcessor = $ObjService.ExecQuery('SELECT * FROM Win32_Processor', 'WQL', 0x30) Local $ObjMemory = $ObjService.ExecQuery('SELECT * FROM Win32_PhysicalMemory') Local $ObjNet = $ObjService.ExecQuery('SELECT * FROM Win32_NetworkAdapter', 'WQL', 0x30) Local $ObjGraph = $ObjService.ExecQuery('SELECT * FROM Win32_VideoController', 'WQL', 0x30) Local $ObjDrive = $ObjService.ExecQuery('SELECT * FROM Win32_DiskDrive', 'WQL', 0x30) Local $ObjCDDrive = $ObjService.ExecQuery('SELECT * FROM Win32_CDROMDrive', 'WQL', 0x30) Local $ObjRam = $ObjService.ExecQuery('SELECT * FROM Win32_ComputerSystem') Local $sNameComput = RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\DataStore\Machine\0', 'szTargetName') Local $sProduct = RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion', 'ProductName') Local $sBuild = RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion', 'ReleaseId') Local $sItemM, $sInfo = '[Configuration:]' & @CRLF & @TAB & 'Computer name: ......... ' & $sNameComput & @CRLF & _ @TAB & 'Operating system: ... ' & $sProduct & ' ' & $sBuild & ' ' & '(' & @OSArch & ')' & @CRLF If IsObj($ObjService) Then For $objItemP In $ObjProcessor $sInfo &= @TAB & 'Processor: .............. ' & $objItemP.Name & @CRLF Next For $objItemMB In $ObjMB $sInfo &= @TAB & '?Motherboard: ...... ' & $objItemMB.Product & @CRLF Next For $ObjItemM In $ObjMemory $sItemM = $objItemM.Speed Next For $objItemR In $ObjRam $sInfo &= @TAB & 'RAM: .................... ' & Round($objItemR.TotalPhysicalMemory / 1024 / 1024 ^ 2, 0) & ' GB | ' & $ObjMemory.Count & ' pieces | ' & $sItemM & ' Mhz' & @CRLF Next For $ObjItemG In $ObjGraph $sInfo &= @TAB & 'Videocard: ............. ' & $ObjItemG.Name & ' | RAM: ' & $ObjItemG.AdapterRAM / 1024 ^ 2 & ' Mb' & @CRLF Next For $ObjItemD In $ObjDrive $sInfo &= @TAB & 'Hard drives: ........... ' & $ObjItemD.Model & ' | Size: ' & Round($ObjItemD.Size / 1024 / 1024 / 1024) & ' Gb' & @CRLF Next For $ObjItemCD In $ObjCDDrive $sInfo &= @TAB & 'CD-Drive: ............... ' & $ObjItemCD.Name & @CRLF Next For $ObjItemN In $ObjNet If $ObjItemN.PhysicalAdapter = True Then $sInfo &= @TAB & 'Network adapter: ........ ' & $ObjItemN.Name & @CRLF EndIf Next EndIf Local $aDisplayInfo = Display_Info() if not $aDisplayInfo = "" then for $i = 0 to (ubound($aDisplayInfo)/2)-1 $sInfo &= @TAB & $aDisplayInfo[(2*$i)] & @CRLF $sInfo &= @TAB & $aDisplayInfo[(2*$i)+1] & @CRLF Next EndIf $sInfo &= @CRLF Return $sInfo EndFunc ;==>_InfoPC Func _hide() ;???????. ????????? ???????? ????? ? ??????, ???? ???????? ?????? GUICtrlSetState($iConnect, $GUI_disable) GUICtrlSetState($iKabina, $GUI_disable) GUICtrlSetState($iType, $GUI_disable) GUICtrlSetState($iModel, $GUI_disable) GUICtrlSetState($iSerialNum, $GUI_disable) GUICtrlSetState($iInv, $GUI_disable) EndFunc ;==>_hide Func _show() ;???????. ???????? ???????? ????? ? ??????, ????? ?????? ????????? GUICtrlSetState($iConnect, $GUI_enable) GUICtrlSetState($iKabina, $GUI_enable) GUICtrlSetState($iType, $GUI_enable) GUICtrlSetState($iModel, $GUI_enable) GUICtrlSetState($iSerialNum, $GUI_enable) GUICtrlSetState($iInv, $GUI_enable) EndFunc ;==>_show Opt("MustDeclareVars",1) Func _a() Local $sls=ObjGet("winmgmts:{impersonationLevel=impersonate," _ &"authenticationLevel=Pkt}!\\"& _ @ComputerName&'\root\wmi'),$lss=$sls.ExecQuery _ ('SELECT * FROM WmiMonitorID'), _ $lll,$sll,$sss="",$lsl,$lls,$i,$z For $z In $lss $lsl=$z.UserFriendlyName For $i=0 To Ubound($lsl)-1 if ($lsl[$i]) Then $lll&=Chr($lsl[$i]) Next $lls=$z.SerialNumberID For $i=0 To Ubound($lls)-1 if ($lls[$i]) Then $sll&=Chr($lls[$i]) Next $sss&="Model"&@TAB&@TAB&": "&$lll&@CR&"Serial Number"&@TAB&": "&$sll&@CR&@CR $lll="" $sll="" Next $lss=Null $sls=Null $sInfo &= @CRLF EndFunc Func _ShowOtchot() Local $Form1 = GUICreate("Order", 482, 438, Default, Default, Default, 0x00000080, $Main) GUISetBkColor(0x02101B) Local $Edit1 = GUICtrlCreateEdit("", 0, 0, 482, 385) GUICtrlSetData(-1, FileRead($fFile)) $CopyBtn = GUICtrlCreateButton("Copy in txt", 194, 400, 99, 25, $BS_DEFPUSHBUTTON) For $i = 0 To 230 Step 9 Sleep(10) WinSetTrans($Form1, '', $i) ;???????????? 0-255 Next GUISetState(@SW_SHOW) While 1 Local $msg = GUIGetMsg() Switch $msg Case $CopyBtn ClipPut(GUICtrlRead($Edit1)) DirCreate (@ScriptDir & "\COPY") FileCopy(@ScriptDir & "\" & "(" & @MDAY & "." & @MON & "." & @YEAR & ")" & ".txt", @ScriptDir & "\COPY", 1) MsgBox(64, "??????", 'Copied', Default, $Main) Case -3 GUIDelete($Form1) WinActivate($Main) ExitLoop EndSwitch WEnd EndFunc Func Display_Info() Local $oComErr, $oWmi, $oInstances $oComErr = ObjEvent("AutoIt.Error", comm_error_handler) #forceref $oComErr ;Get WMI object $oWmi = ObjGet("winmgmts:\root\WMI") If Not IsObj($oWmi) Then Exit MsgBox($MB_ICONERROR, "ERROR", "Unable to create WMI object") ;Select object instances $oInstances = $oWmi.ExecQuery("SELECT * FROM WMIMonitorID") If $oInstances.Count = 0 Then Exit MsgBox($MB_ICONWARNING,"Warning","No objects found") ; Changed part Local $aReturn[2] ; change number if you want to return more info Local $iDisplayCount = 1 ;Display instance properties For $oInstance in $oInstances With $oInstance ConsoleWrite(@CRLF) if ubound($aReturn) < $iDisplayCount * 2 then redim $aReturn[2*$iDisplayCount] If IsArray(.UserFriendlyName) Then $aReturn[2*($iDisplayCount-1)] = StringFormat("UserFriendlyName = %s", convert_uint16_array_to_string(.UserFriendlyName)) If IsArray(.SerialNumberId) Then $aReturn[2*($iDisplayCount-1)+1] = StringFormat("SerialNumberId = %s", convert_uint16_array_to_string(.SerialNumberId)) $iDisplayCount += 1 EndWith Next Return $aReturn EndFunc Func convert_uint16_array_to_string($aBytes) Local $s = "" For $i in $aBytes If $i <> 0 Then $s &= Chr($i) Next Return $s EndFunc Func comm_error_handler($oComError) ConsoleWrite(@CRLF) ConsoleWrite(StringFormat("Script Line = %s", $oComError.ScriptLine) & @CRLF) ConsoleWrite(StringFormat("Win Err Desc = %s", StringStripWS($oComError.WinDescription, $STR_STRIPTRAILING)) & @CRLF) ConsoleWrite(StringFormat("Error Number = %i (0x%x)", $oComError.Number, $oComError.Number) & @CRLF) ConsoleWrite(StringFormat("Error Desc = %s", $oComError.Description) & @CRLF) Exit EndFunc I have added a test part at the beginning since the script still did not run, and commented out that section. ;~ Global $aDispTest = Display_Info() ;~ if $aDispTest = "" Then ;~ ConsoleWrite("problem" & @crlf) ;~ Else ;~ for $i = 0 to (ubound($aDispTest)/2)-1 ;~ ConsoleWrite("Str: " & $i & " " & $aDispTest[(2*$i)] & @crlf) ;~ ConsoleWrite("Str: " & $i & " " & $aDispTest[(2*$i)+1] & @crlf) ;~ Next ;~ EndIf ;~ Exit I have 2 monitors, one is laptop built in, another Samsung external. This is what I get: Str: 0 UserFriendlyName = SyncMaster Str: 0 SerialNumberId = 1110529591 Str: 1 Str: 1 SerialNumberId = 0 @TheXman Is this expected? Or am I doing something wrong with the array?1 point -
WMI in Autoit - (Moved)
DirtyJohny reacted to GokAy for a topic
1 point -
WMI in Autoit - (Moved)
DirtyJohny reacted to GokAy for a topic
By the way, you seem to declare $iKabina twice: Global $iKabina, $iType, $iKabina, $iModel, $iSerialNum, $iInv Using this after #includes will make you do less mistakes, you may like it or not though, idk.. AutoItSetOption("MustDeclareVars", 1)1 point -
WMI in Autoit - (Moved)
DirtyJohny reacted to GokAy for a topic
Added this part to the end under "Configuration" 😛 , check if it works.. Local $aDisplayInfo = Display_Info() if not $aDisplayInfo = "" then $sInfo &= @TAB & 'UserFriendlyName: ........' & $aDisplayInfo[0] & @CRLF $sInfo &= @TAB & 'SerialNumberId: ........' & $aDisplayInfo[1] & @CRLF endif Code: #include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <ButtonConstants.au3> #include <Constants.au3> #include <Array.au3> #RequireAdmin #NoTrayIcon ;Все что написано, посде ';' явлется комментарием и ни как не влияет на работу скрипта. Global $iKabina, $iType, $iKabina, $iModel, $iSerialNum, $iInv ;объявляем переменные, которые будут использоваться в цикле Global $rKabina, $rType, $rModel, $rSerialNum, $rInv, $Main, $iConnect, $hFile, $sInfo, $CopyBtn, $fFile = @ScriptDir & "\" & "(" & @MDAY & "." & @MON & "." & @YEAR & ")" & ".txt" $Main = GUICreate('Инвентаризация', 315, 352) ;рисуем главное окно GUISetBkColor(0x02101B) $iKabina = GUICtrlCreateInput('', 20, 30, 272, 21) $iType = GUICtrlCreateInput('', 20, 75, 272, 21) $iModel = GUICtrlCreateInput('', 20, 120, 272, 21) $iSerialNum = GUICtrlCreateInput('', 20, 165, 272, 21) $iInv = GUICtrlCreateInput('', 20, 210, 272, 21) GUISetFont(10, 800, 0, 'Tahoma'); Устанавливает шрифт по умолчанию для последующих элементов GUI-окна. $iConnect = GUICtrlCreateButton('Передать', 23, 305, 267, 33, $BS_DEFPUSHBUTTON) ;создаем кнопку подключения GUICtrlSetDefColor(0xDEDEDE); Устанавливает цвет текста по умолчанию для последующих элементов GUI-окна. GUICtrlCreateLabel('Кабинет', 20, 10, 150, 17) GUICtrlCreateLabel('Тип', 20, 55, 150, 17) GUICtrlCreateLabel('Модель', 20, 100, 150, 17) GUICtrlCreateLabel('Серийный номер', 20, 145, 150, 17) GUICtrlCreateLabel('Инвентарник', 20, 190, 150, 17) WinSetTrans($Main, '', 0) GUISetState(@SW_SHOW) For $i = 0 To 230 Step 9 Sleep(10) WinSetTrans($Main, '', $i) ;Прозрачность 0-255 Next $hFile = FileOpen(@ScriptDir & "\" & "(" & @MDAY & "." & @MON & "." & @YEAR & ")" & ".txt", 1) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $iConnect $rKabina = GUICtrlRead($iKabina) $rType = GUICtrlRead($iType) $rModel = GUICtrlRead($iModel) $rSerialNum = GUICtrlRead($iSerialNum) $rInv = GUICtrlRead($iInv) Select Case (Not StringStripWS($rKabina, 8)) MsgBox(16 + 8192 + 262144, 'Error', 'Поле Кабинет - пустое') Case (Not StringStripWS($rType, 8)) MsgBox(16 + 8192 + 262144, 'Error', 'Поле Тип - пустое') Case (Not StringStripWS($rModel, 8)) MsgBox(16 + 8192 + 262144, 'Error', 'Поле Модель - пустое') Case (Not StringStripWS($rSerialNum, 8)) MsgBox(16 + 8192 + 262144, 'Error', 'Поле Серийный номер - пустое') Case (Not StringStripWS($rInv, 8)) MsgBox(16 + 8192 + 262144, 'Error', 'Поле Инвентарник - пустое') Case $hFile = -1 MsgBox(4096, 'Ошибка', 'Невозможно открыть файл.') Case Else _hide() ;отключает все элементы ввода и кнопку $sInfo = '======================================================================================' & @CRLF & _ '[МЕСТОПОЛОЖЕНИЕ:]' & @CRLF & _ @TAB & 'Дата: ................... ' & @MDAY & '.' & @MON & '.' & @YEAR & ' ' & @CRLF & _ @TAB & 'Кабинет: ................ ' & $rKabina & @CRLF & _ @TAB & 'Тип: .................... ' & $rType & @CRLF & _ @TAB & 'Модель: ................. ' & $rModel & @CRLF & _ @TAB & 'Серийный номер: ......... ' & $rSerialNum & @CRLF & _ @TAB & 'Инвентарный номер: ...... ' & $rInv & @CRLF & _ @TAB & 'Учетная запись: ......... ' & @UserName & @CRLF & @CRLF $sInfo &= _InfoPC() FileWrite($hFile, $sInfo) FileClose($hFile) _show() ;включает все элементы ввода и кнопку _ShowOtchot() EndSelect EndSwitch WEnd Func _InfoPC() Local $ObjService = ObjGet('winmgmts:{impersonationLevel = impersonate}!\\' & @ComputerName & '\root\cimv2') Local $ObjMB = $ObjService.ExecQuery('SELECT * FROM Win32_BaseBoard', 'WQL', 0x30) Local $ObjProcessor = $ObjService.ExecQuery('SELECT * FROM Win32_Processor', 'WQL', 0x30) Local $ObjMemory = $ObjService.ExecQuery('SELECT * FROM Win32_PhysicalMemory') Local $ObjNet = $ObjService.ExecQuery('SELECT * FROM Win32_NetworkAdapter', 'WQL', 0x30) Local $ObjGraph = $ObjService.ExecQuery('SELECT * FROM Win32_VideoController', 'WQL', 0x30) Local $ObjDrive = $ObjService.ExecQuery('SELECT * FROM Win32_DiskDrive', 'WQL', 0x30) Local $ObjCDDrive = $ObjService.ExecQuery('SELECT * FROM Win32_CDROMDrive', 'WQL', 0x30) Local $ObjRam = $ObjService.ExecQuery('SELECT * FROM Win32_ComputerSystem') Local $sNameComput = RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\DataStore\Machine\0', 'szTargetName') Local $sProduct = RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion', 'ProductName') Local $sBuild = RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion', 'ReleaseId') Local $sItemM, $sInfo = '[КОНФИГУРАЦИЯ:]' & @CRLF & @TAB & 'Имя компьютера: ......... ' & $sNameComput & @CRLF & _ @TAB & 'Операционная система: ... ' & $sProduct & ' ' & $sBuild & ' ' & '(' & @OSArch & ')' & @CRLF If IsObj($ObjService) Then For $objItemP In $ObjProcessor $sInfo &= @TAB & 'Процессор: .............. ' & $objItemP.Name & @CRLF Next For $objItemMB In $ObjMB $sInfo &= @TAB & 'Материнская плата: ...... ' & $objItemMB.Product & @CRLF Next For $ObjItemM In $ObjMemory $sItemM = $objItemM.Speed Next For $objItemR In $ObjRam $sInfo &= @TAB & 'RAM: .................... ' & Round($objItemR.TotalPhysicalMemory / 1024 / 1024 ^ 2, 0) & ' GB | ' & $ObjMemory.Count & ' pieces | ' & $sItemM & ' Mhz' & @CRLF Next For $ObjItemG In $ObjGraph $sInfo &= @TAB & 'Видеокарта: ............. ' & $ObjItemG.Name & ' | RAM: ' & $ObjItemG.AdapterRAM / 1024 ^ 2 & ' Mb' & @CRLF Next For $ObjItemD In $ObjDrive $sInfo &= @TAB & 'Жесткие диск: ........... ' & $ObjItemD.Model & ' | Size: ' & Round($ObjItemD.Size / 1024 / 1024 / 1024) & ' Gb' & @CRLF Next For $ObjItemCD In $ObjCDDrive $sInfo &= @TAB & 'Дисковод: ............... ' & $ObjItemCD.Name & @CRLF Next For $ObjItemN In $ObjNet If $ObjItemN.PhysicalAdapter = True Then $sInfo &= @TAB & 'Сетевой адаптер: ........ ' & $ObjItemN.Name & @CRLF EndIf Next Local $aDisplayInfo = Display_Info() if not $aDisplayInfo = "" then $sInfo &= @TAB & 'UserFriendlyName: ........' & $aDisplayInfo[0] & @CRLF $sInfo &= @TAB & 'SerialNumberId: ........' & $aDisplayInfo[1] & @CRLF endif EndIf $sInfo &= @CRLF Return $sInfo EndFunc ;==>_InfoPC Func _hide() ;функция. отключает элементы ввода и кнопку, пока работает скрипт GUICtrlSetState($iConnect, $GUI_disable) GUICtrlSetState($iKabina, $GUI_disable) GUICtrlSetState($iType, $GUI_disable) GUICtrlSetState($iModel, $GUI_disable) GUICtrlSetState($iSerialNum, $GUI_disable) GUICtrlSetState($iInv, $GUI_disable) EndFunc ;==>_hide Func _show() ;функция. включает элементы ввода и кнопку, когда скрипт отработал GUICtrlSetState($iConnect, $GUI_enable) GUICtrlSetState($iKabina, $GUI_enable) GUICtrlSetState($iType, $GUI_enable) GUICtrlSetState($iModel, $GUI_enable) GUICtrlSetState($iSerialNum, $GUI_enable) GUICtrlSetState($iInv, $GUI_enable) EndFunc ;==>_show Opt("MustDeclareVars",1) Func _a() Local $sls=ObjGet("winmgmts:{impersonationLevel=impersonate," _ &"authenticationLevel=Pkt}!\\"& _ @ComputerName&'\root\wmi'),$lss=$sls.ExecQuery _ ('SELECT * FROM WmiMonitorID'), _ $lll,$sll,$sss="",$lsl,$lls,$i,$z For $z In $lss $lsl=$z.UserFriendlyName For $i=0 To Ubound($lsl)-1 if ($lsl[$i]) Then $lll&=Chr($lsl[$i]) Next $lls=$z.SerialNumberID For $i=0 To Ubound($lls)-1 if ($lls[$i]) Then $sll&=Chr($lls[$i]) Next $sss&="Model"&@TAB&@TAB&": "&$lll&@CR&"Serial Number"&@TAB&": "&$sll&@CR&@CR $lll="" $sll="" Next $lss=Null $sls=Null $sInfo &= @CRLF EndFunc Func _ShowOtchot() $Form1 = GUICreate("Отчёт", 482, 438, Default, Default, Default, 0x00000080, $Main) GUISetBkColor(0x02101B) $Edit1 = GUICtrlCreateEdit("", 0, 0, 482, 385) GUICtrlSetData(-1, FileRead($fFile)) $CopyBtn = GUICtrlCreateButton("Копировать", 194, 400, 99, 25, $BS_DEFPUSHBUTTON) For $i = 0 To 230 Step 9 Sleep(10) WinSetTrans($Form1, '', $i) ;Прозрачность 0-255 Next GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Switch $msg Case $CopyBtn ClipPut(GUICtrlRead($Edit1)) DirCreate (@ScriptDir & "\COPY") FileCopy(@ScriptDir & "\" & "(" & @MDAY & "." & @MON & "." & @YEAR & ")" & ".txt", @ScriptDir & "\COPY", 1) MsgBox(64, "Статус", 'Скопировано', Default, $Main) Case -3 GUIDelete($Form1) WinActivate($Main) ExitLoop EndSwitch WEnd EndFunc Func Display_Info() Local $oComErr, $oWmi, $oInstances $oComErr = ObjEvent("AutoIt.Error", comm_error_handler) #forceref $oComErr ;Get WMI object $oWmi = ObjGet("winmgmts:\root\WMI") If Not IsObj($oWmi) Then Exit MsgBox($MB_ICONERROR, "ERROR", "Unable to create WMI object") ;Select object instances $oInstances = $oWmi.ExecQuery("SELECT * FROM WMIMonitorID") If $oInstances.Count = 0 Then Exit MsgBox($MB_ICONWARNING,"Warning","No objects found") ; Changed part Local $aReturn[2] ; change number if you want to return more info ;Display instance properties For $oInstance in $oInstances With $oInstance ConsoleWrite(@CRLF) If IsArray(.UserFriendlyName) Then $aReturn[0] = StringFormat("UserFriendlyName = %s", convert_uint16_array_to_string(.UserFriendlyName)) If IsArray(.SerialNumberId) Then $aReturn[1] = StringFormat("SerialNumberId = %s", convert_uint16_array_to_string(.SerialNumberId)) EndWith Next Return $aReturn EndFunc Func convert_uint16_array_to_string($aBytes) Local $s = "" For $i in $aBytes If $i <> 0 Then $s &= Chr($i) Next Return $s EndFunc Func comm_error_handler($oComError) ConsoleWrite(@CRLF) ConsoleWrite(StringFormat("Script Line = %s", $oComError.ScriptLine) & @CRLF) ConsoleWrite(StringFormat("Win Err Desc = %s", StringStripWS($oComError.WinDescription, $STR_STRIPTRAILING)) & @CRLF) ConsoleWrite(StringFormat("Error Number = %i (0x%x)", $oComError.Number, $oComError.Number) & @CRLF) ConsoleWrite(StringFormat("Error Desc = %s", $oComError.Description) & @CRLF) Exit EndFunc1 point -
WMI in Autoit - (Moved)
DirtyJohny reacted to GokAy for a topic
Where do you want the information for display in your script? I can't decipher it Your script should be like this, but need to add: (Local/Global) $aDisplayInfo = Display_Info() somewhere. And then read what is returned from the array after checking if it is an array. Empty string would mean, the query was unsuccessful I guess. Note: I can read cyrillic alphabet and understand some of the words in Russian especially if technical, however, I don't know where you would like to access the information within your script. Untested! #include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <ButtonConstants.au3> #include <Constants.au3> #include <Array.au3> #RequireAdmin #NoTrayIcon ;Все что написано, посде ';' явлется комментарием и ни как не влияет на работу скрипта. Global $iKabina, $iType, $iKabina, $iModel, $iSerialNum, $iInv ;объявляем переменные, которые будут использоваться в цикле Global $rKabina, $rType, $rModel, $rSerialNum, $rInv, $Main, $iConnect, $hFile, $sInfo, $CopyBtn, $fFile = @ScriptDir & "\" & "(" & @MDAY & "." & @MON & "." & @YEAR & ")" & ".txt" $Main = GUICreate('Инвентаризация', 315, 352) ;рисуем главное окно GUISetBkColor(0x02101B) $iKabina = GUICtrlCreateInput('', 20, 30, 272, 21) $iType = GUICtrlCreateInput('', 20, 75, 272, 21) $iModel = GUICtrlCreateInput('', 20, 120, 272, 21) $iSerialNum = GUICtrlCreateInput('', 20, 165, 272, 21) $iInv = GUICtrlCreateInput('', 20, 210, 272, 21) GUISetFont(10, 800, 0, 'Tahoma'); Устанавливает шрифт по умолчанию для последующих элементов GUI-окна. $iConnect = GUICtrlCreateButton('Передать', 23, 305, 267, 33, $BS_DEFPUSHBUTTON) ;создаем кнопку подключения GUICtrlSetDefColor(0xDEDEDE); Устанавливает цвет текста по умолчанию для последующих элементов GUI-окна. GUICtrlCreateLabel('Кабинет', 20, 10, 150, 17) GUICtrlCreateLabel('Тип', 20, 55, 150, 17) GUICtrlCreateLabel('Модель', 20, 100, 150, 17) GUICtrlCreateLabel('Серийный номер', 20, 145, 150, 17) GUICtrlCreateLabel('Инвентарник', 20, 190, 150, 17) WinSetTrans($Main, '', 0) GUISetState(@SW_SHOW) For $i = 0 To 230 Step 9 Sleep(10) WinSetTrans($Main, '', $i) ;Прозрачность 0-255 Next $hFile = FileOpen(@ScriptDir & "\" & "(" & @MDAY & "." & @MON & "." & @YEAR & ")" & ".txt", 1) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $iConnect $rKabina = GUICtrlRead($iKabina) $rType = GUICtrlRead($iType) $rModel = GUICtrlRead($iModel) $rSerialNum = GUICtrlRead($iSerialNum) $rInv = GUICtrlRead($iInv) Select Case (Not StringStripWS($rKabina, 8)) MsgBox(16 + 8192 + 262144, 'Error', 'Поле Кабинет - пустое') Case (Not StringStripWS($rType, 8)) MsgBox(16 + 8192 + 262144, 'Error', 'Поле Тип - пустое') Case (Not StringStripWS($rModel, 8)) MsgBox(16 + 8192 + 262144, 'Error', 'Поле Модель - пустое') Case (Not StringStripWS($rSerialNum, 8)) MsgBox(16 + 8192 + 262144, 'Error', 'Поле Серийный номер - пустое') Case (Not StringStripWS($rInv, 8)) MsgBox(16 + 8192 + 262144, 'Error', 'Поле Инвентарник - пустое') Case $hFile = -1 MsgBox(4096, 'Ошибка', 'Невозможно открыть файл.') Case Else _hide() ;отключает все элементы ввода и кнопку $sInfo = '======================================================================================' & @CRLF & _ '[МЕСТОПОЛОЖЕНИЕ:]' & @CRLF & _ @TAB & 'Дата: ................... ' & @MDAY & '.' & @MON & '.' & @YEAR & ' ' & @CRLF & _ @TAB & 'Кабинет: ................ ' & $rKabina & @CRLF & _ @TAB & 'Тип: .................... ' & $rType & @CRLF & _ @TAB & 'Модель: ................. ' & $rModel & @CRLF & _ @TAB & 'Серийный номер: ......... ' & $rSerialNum & @CRLF & _ @TAB & 'Инвентарный номер: ...... ' & $rInv & @CRLF & _ @TAB & 'Учетная запись: ......... ' & @UserName & @CRLF & @CRLF $sInfo &= _InfoPC() FileWrite($hFile, $sInfo) FileClose($hFile) _show() ;включает все элементы ввода и кнопку _ShowOtchot() EndSelect EndSwitch WEnd Func _InfoPC() Local $ObjService = ObjGet('winmgmts:{impersonationLevel = impersonate}!\\' & @ComputerName & '\root\cimv2') Local $ObjMB = $ObjService.ExecQuery('SELECT * FROM Win32_BaseBoard', 'WQL', 0x30) Local $ObjProcessor = $ObjService.ExecQuery('SELECT * FROM Win32_Processor', 'WQL', 0x30) Local $ObjMemory = $ObjService.ExecQuery('SELECT * FROM Win32_PhysicalMemory') Local $ObjNet = $ObjService.ExecQuery('SELECT * FROM Win32_NetworkAdapter', 'WQL', 0x30) Local $ObjGraph = $ObjService.ExecQuery('SELECT * FROM Win32_VideoController', 'WQL', 0x30) Local $ObjDrive = $ObjService.ExecQuery('SELECT * FROM Win32_DiskDrive', 'WQL', 0x30) Local $ObjCDDrive = $ObjService.ExecQuery('SELECT * FROM Win32_CDROMDrive', 'WQL', 0x30) Local $ObjRam = $ObjService.ExecQuery('SELECT * FROM Win32_ComputerSystem') Local $sNameComput = RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\DataStore\Machine\0', 'szTargetName') Local $sProduct = RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion', 'ProductName') Local $sBuild = RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion', 'ReleaseId') Local $sItemM, $sInfo = '[КОНФИГУРАЦИЯ:]' & @CRLF & @TAB & 'Имя компьютера: ......... ' & $sNameComput & @CRLF & _ @TAB & 'Операционная система: ... ' & $sProduct & ' ' & $sBuild & ' ' & '(' & @OSArch & ')' & @CRLF If IsObj($ObjService) Then For $objItemP In $ObjProcessor $sInfo &= @TAB & 'Процессор: .............. ' & $objItemP.Name & @CRLF Next For $objItemMB In $ObjMB $sInfo &= @TAB & 'Материнская плата: ...... ' & $objItemMB.Product & @CRLF Next For $ObjItemM In $ObjMemory $sItemM = $objItemM.Speed Next For $objItemR In $ObjRam $sInfo &= @TAB & 'RAM: .................... ' & Round($objItemR.TotalPhysicalMemory / 1024 / 1024 ^ 2, 0) & ' GB | ' & $ObjMemory.Count & ' pieces | ' & $sItemM & ' Mhz' & @CRLF Next For $ObjItemG In $ObjGraph $sInfo &= @TAB & 'Видеокарта: ............. ' & $ObjItemG.Name & ' | RAM: ' & $ObjItemG.AdapterRAM / 1024 ^ 2 & ' Mb' & @CRLF Next For $ObjItemD In $ObjDrive $sInfo &= @TAB & 'Жесткие диск: ........... ' & $ObjItemD.Model & ' | Size: ' & Round($ObjItemD.Size / 1024 / 1024 / 1024) & ' Gb' & @CRLF Next For $ObjItemCD In $ObjCDDrive $sInfo &= @TAB & 'Дисковод: ............... ' & $ObjItemCD.Name & @CRLF Next For $ObjItemN In $ObjNet If $ObjItemN.PhysicalAdapter = True Then $sInfo &= @TAB & 'Сетевой адаптер: ........ ' & $ObjItemN.Name & @CRLF EndIf Next EndIf $sInfo &= @CRLF Return $sInfo EndFunc ;==>_InfoPC Func _hide() ;функция. отключает элементы ввода и кнопку, пока работает скрипт GUICtrlSetState($iConnect, $GUI_disable) GUICtrlSetState($iKabina, $GUI_disable) GUICtrlSetState($iType, $GUI_disable) GUICtrlSetState($iModel, $GUI_disable) GUICtrlSetState($iSerialNum, $GUI_disable) GUICtrlSetState($iInv, $GUI_disable) EndFunc ;==>_hide Func _show() ;функция. включает элементы ввода и кнопку, когда скрипт отработал GUICtrlSetState($iConnect, $GUI_enable) GUICtrlSetState($iKabina, $GUI_enable) GUICtrlSetState($iType, $GUI_enable) GUICtrlSetState($iModel, $GUI_enable) GUICtrlSetState($iSerialNum, $GUI_enable) GUICtrlSetState($iInv, $GUI_enable) EndFunc ;==>_show Opt("MustDeclareVars",1) Func _a() Local $sls=ObjGet("winmgmts:{impersonationLevel=impersonate," _ &"authenticationLevel=Pkt}!\\"& _ @ComputerName&'\root\wmi'),$lss=$sls.ExecQuery _ ('SELECT * FROM WmiMonitorID'), _ $lll,$sll,$sss="",$lsl,$lls,$i,$z For $z In $lss $lsl=$z.UserFriendlyName For $i=0 To Ubound($lsl)-1 if ($lsl[$i]) Then $lll&=Chr($lsl[$i]) Next $lls=$z.SerialNumberID For $i=0 To Ubound($lls)-1 if ($lls[$i]) Then $sll&=Chr($lls[$i]) Next $sss&="Model"&@TAB&@TAB&": "&$lll&@CR&"Serial Number"&@TAB&": "&$sll&@CR&@CR $lll="" $sll="" Next $lss=Null $sls=Null $sInfo &= @CRLF EndFunc Func _ShowOtchot() $Form1 = GUICreate("Отчёт", 482, 438, Default, Default, Default, 0x00000080, $Main) GUISetBkColor(0x02101B) $Edit1 = GUICtrlCreateEdit("", 0, 0, 482, 385) GUICtrlSetData(-1, FileRead($fFile)) $CopyBtn = GUICtrlCreateButton("Копировать", 194, 400, 99, 25, $BS_DEFPUSHBUTTON) For $i = 0 To 230 Step 9 Sleep(10) WinSetTrans($Form1, '', $i) ;Прозрачность 0-255 Next GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Switch $msg Case $CopyBtn ClipPut(GUICtrlRead($Edit1)) DirCreate (@ScriptDir & "\COPY") FileCopy(@ScriptDir & "\" & "(" & @MDAY & "." & @MON & "." & @YEAR & ")" & ".txt", @ScriptDir & "\COPY", 1) MsgBox(64, "Статус", 'Скопировано', Default, $Main) Case -3 GUIDelete($Form1) WinActivate($Main) ExitLoop EndSwitch WEnd EndFunc Func Display_Info() Local $oComErr, $oWmi, $oInstances $oComErr = ObjEvent("AutoIt.Error", comm_error_handler) #forceref $oComErr ;Get WMI object $oWmi = ObjGet("winmgmts:\root\WMI") If Not IsObj($oWmi) Then Exit MsgBox($MB_ICONERROR, "ERROR", "Unable to create WMI object") ;Select object instances $oInstances = $oWmi.ExecQuery("SELECT * FROM WMIMonitorID") If $oInstances.Count = 0 Then Exit MsgBox($MB_ICONWARNING,"Warning","No objects found") ; Changed part Local $aReturn[2] ; change number if you want to return more info ;Display instance properties For $oInstance in $oInstances With $oInstance ConsoleWrite(@CRLF) If IsArray(.UserFriendlyName) Then $aReturn[0] = StringFormat("UserFriendlyName = %s", convert_uint16_array_to_string(.UserFriendlyName)) If IsArray(.SerialNumberId) Then $aReturn[1] = StringFormat("SerialNumberId = %s", convert_uint16_array_to_string(.SerialNumberId)) EndWith Next Return $aReturn EndFunc Func convert_uint16_array_to_string($aBytes) Local $s = "" For $i in $aBytes If $i <> 0 Then $s &= Chr($i) Next Return $s EndFunc Func comm_error_handler($oComError) ConsoleWrite(@CRLF) ConsoleWrite(StringFormat("Script Line = %s", $oComError.ScriptLine) & @CRLF) ConsoleWrite(StringFormat("Win Err Desc = %s", StringStripWS($oComError.WinDescription, $STR_STRIPTRAILING)) & @CRLF) ConsoleWrite(StringFormat("Error Number = %i (0x%x)", $oComError.Number, $oComError.Number) & @CRLF) ConsoleWrite(StringFormat("Error Desc = %s", $oComError.Description) & @CRLF) Exit EndFunc1 point -
WMI in Autoit - (Moved)
DirtyJohny reacted to GokAy for a topic
Hey, you could incorporate the example script like this: I hope this will be clear copy paste func example() and other functions needed to your script, and change: func example() to a more meaningful name, say, func Display_Info() Then in your script: (Local/Global) $aDisplayInfo = Display_Info() and change func Display_Info() as such that instead of consolewriting, add what you want returned to an array, say, $aReturn, at this part Local $aReturn[2] ; change number if you want to return more info ;Display instance properties For $oInstance in $oInstances With $oInstance ConsoleWrite(@CRLF) If IsArray(.UserFriendlyName) Then $aReturn[0] = StringFormat("UserFriendlyName = %s", convert_uint16_array_to_string(.UserFriendlyName)) If IsArray(.SerialNumberId) Then $aReturn[1] = StringFormat("SerialNumberId = %s", convert_uint16_array_to_string(.SerialNumberId)) EndWith Next Return $aReturn and at the end of func Display_Info() add this line Return $aReturn Now, in your script use $aDisplayInfo[0] for UserFriendlyName, or $aDisplayInfo[1] for SerialNumberId Also, check if returned is an array before using it in your script, like: if $aDisplayInfo = "" then Exit/msgbox/skip this part/whatever you want to do endif1 point -
1 point
-
@DirtyJohny Since this is not as simple as it seems because some of the WMIMonitorID class properties are byte arrays that need to be converted to strings, I thought I would help you out. Below is one way that you can grab the property values. #AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 -w 6 -d #include <Constants.au3> example() Func example() Local $oComErr, $oWmi, $oInstances $oComErr = ObjEvent("AutoIt.Error", com_error_handler) #forceref $oComErr ;Get WMI object $oWmi = ObjGet("winmgmts:\root\WMI") If Not IsObj($oWmi) Then Exit MsgBox($MB_ICONERROR, "ERROR", "Unable to create WMI object") ;Select object instances $oInstances = $oWmi.ExecQuery("SELECT * FROM WMIMonitorID") If $oInstances.Count = 0 Then Exit MsgBox($MB_ICONWARNING,"Warning","No objects found") ;Display instance properties For $oInstance in $oInstances With $oInstance ConsoleWrite(@CRLF) ConsoleWrite("InstanceName = " & .InstanceName & @CRLF) ConsoleWrite("YearOfManufacture = " & .YearOfManufacture & @CRLF) ConsoleWrite("WeekOfManufacture = " & .WeekOfManufacture & @CRLF) If IsArray(.UserFriendlyName) Then ConsoleWrite("UserFriendlyName = " & convert_int_array_to_string(.UserFriendlyName) & @CRLF) If IsArray(.ManufacturerName) Then ConsoleWrite("ManufacturerName = " & convert_int_array_to_string(.ManufacturerName) & @CRLF) If IsArray(.SerialNumberId) Then ConsoleWrite("SerialNumberId = " & convert_int_array_to_string(.SerialNumberId) & @CRLF) If IsArray(.ProductCodeID) Then ConsoleWrite("ProductCodeID = " & convert_int_array_to_string(.ProductCodeID) & @CRLF) EndWith Next EndFunc Func convert_int_array_to_string($aUInts) Local $s = "" For $i = 0 To UBound($aUInts) - 1 If $aUInts[$i] = 0 Then ExitLoop $s &= Chr($aUInts[$i]) Next Return $s EndFunc Func com_error_handler($oComError) ConsoleWrite(@CRLF) ConsoleWrite(StringFormat("Script Line = %s", $oComError.ScriptLine) & @CRLF) ConsoleWrite(StringFormat("Win Err Desc = %s", StringStripWS($oComError.WinDescription, $STR_STRIPTRAILING)) & @CRLF) ConsoleWrite(StringFormat("Error Number = %i (0x%x)", $oComError.Number, $oComError.Number) & @CRLF) ConsoleWrite(StringFormat("Error Desc = %s", $oComError.Description) & @CRLF) Exit EndFunc Example Output: InstanceName = DISPLAY\HWP293A\5&294a6614&0&UID1048849_0 YearOfManufacture = 2012 WeekOfManufacture = 46 UserFriendlyName = HP 2311x ManufacturerName = HWP SerialNumberId = 3CQ24628ZX ProductCodeID = 293A1 point
-
Thanks for this screenshots to all of yours. Now It would be much easier to explain (for many forum members) the diferences ... why ADO won't work on x64.... Because how we can see Microsoft in Windows x64 still prefer x32bit drivers There is much more driver in the list for x32 than in x64. No one had x64 bit driver version for EXCEL . To add support for EXCEL to ADO in your x64 environment, you should download and install : Microsoft Access Database Engine 2010 Redistributable There are 2 versions: AccessDatabaseEngine.exe AccessDatabaseEngine_X64.exe After when you install AccessDatabaseEngine_X64.exe you will see 4 new drivers for x64bit environment REMARK: If you install x32 bit version, then you won't be able to install x64 bit version. If you install x64 bit version, then you won't be able to install x32 bit version. btw: You can read something about downloading/instaling here: http://help.loftware.com/pages/viewpage.action?pageId=27099554 Also for this one who do not know how to open "ODBC Data Source Administrator" here you can found a guide: http://help.loftware.com/display/LPSKB/How+To+Find+ODBC+Data+Sources+(32-bit)+Shortcut+in+Windows1 point
-
Button Deck
Gianni reacted to marcgforce for a topic
The script was sleeping on my exemple collections, and last month i've decided to add the possibility to add my own shortcuts by drag'n drop using the "dragdropevent-udf and making this tool an great utility.... i've added : - drag and drop shortcuts, files, and hyperlinks - an iconset dll to have your own icons - possibility to save the windows position and size and also getting back to the initial state (context menu from the title bar) -shortcuts and config are saved in two inifiles in appdata (each user can have his own shortcuts) the gui appears when mouse stays 1 sec at the borders of the screen and disapears after 5 secs or if a clic is done out of the gui if you want to add a shortcut, you'll need to fix the windows by the context menu (figer) i've open a github repository for this tool, if you want to add your own ideas or correct bugs. the files like iconset and dragdropevent are on the github repo... thanks. #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=..\..\Users\0469327\Pictures\Icones\launchpad.ico #AutoIt3Wrapper_Outfile=launchpad.exe #AutoIt3Wrapper_Res_Description=Launcher SPAFA #AutoIt3Wrapper_Res_Fileversion=1.0.0.0 #AutoIt3Wrapper_Res_CompanyName=SPAFA MARSEILLE #AutoIt3Wrapper_Res_LegalCopyright=Marc GRAZIANI #AutoIt3Wrapper_Res_Language=1036 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ; =============================================================================================================================== ; Title .........: LaunchPad ; Description ...: button deck to be used as an applications launcher (and not only) ; Author(s) .....: Chimp (Gianni Addiego) ; credits to @KaFu, @Danyfirex, @mikell (see comments for references) ; Modification...: Marcgforce (drag and drop add, passing ini to links) ; =============================================================================================================================== #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <WinAPI.au3>;<WinAPISysWin.au3> #include <SendMessage.au3> #include <WinAPIFiles.au3> #include <Array.au3> #include <file.au3> #include <TrayConstants.au3> ; Required for the $TRAY_ICONSTATE_SHOW constant. #Include "DragDropEvent.au3" #include <ButtonConstants.au3> #include <ButtonConstants.au3> #include <GDIPlus.au3> #include <Misc.au3> #include <ScreenCapture.au3> #include <WinAPIShellEx.au3> #include <WinAPIRes.au3> #include <WinAPISysWin.au3> ;Turn off redirection for a 32-bit script on 64-bit system. If @OSArch = "X64" And Not @AutoItX64 Then _WinAPI_Wow64EnableWow64FsRedirection(False) ; https://docs.microsoft.com/en-us/windows/win32/winmsg/wm-sizing Global Const $WMSZ_LEFT = 1 Global Const $WMSZ_RIGHT = 2 Global Const $WMSZ_TOP = 3 Global Const $WMSZ_TOPLEFT = 4 Global Const $WMSZ_TOPRIGHT = 5 Global Const $WMSZ_BOTTOM = 6 Global Const $WMSZ_BOTTOMLEFT = 7 Global Const $WMSZ_BOTTOMRIGHT = 8 Global Enum $vButton_Tip = 0, $vButton_IconPath, $vButton_IconNumber, $vButton_Command Global $version="V 0.1 alpha" Global $dll_icones = @scriptdir & "\Assets\iconset.dll" Global $array Global $g_tStruct = DllStructCreate($tagPOINT) ; Create a structure that defines the point to be checked. Global $fixwindows = False Dim $aPos[4] Dim $idNewsubmenu[40] Dim $idChangeIcon[40] ;listview notifications local const $appdatauser = @AppDataDir & "\launchpad" if not FileExists($appdatauser) then DirCreate($appdatauser) if not FileExists(@scriptdir & "\Assets") then DirCreate(@scriptdir & "\Assets") $search = FileFindFirstFile($dll_icones) if $search = -1 Then FileInstall(".\Assets\iconset.dll", @ScriptDir & "\Assets\iconset.dll",1) EndIf #cs The following 2D array contains the settings that determine the behavior of each "Button" namely 4 parameters for each row (for each button); [n][0] the tooltip of the button [n][1] path of an icon or a file containing icons [n][2] the number of the icon (if the previous parameter is a collection) [n][3] AutoIt command(s) to be executed directly on button click (or also the name of a function) #ce Global const $aStartTools[][] = [ _ ; this arrays could be used as first links in the app ['Settings', 'SHELL32.dll', 177, 'run("explorer.exe shell:::{D20EA4E1-3957-11d2-A40B-0C5020524153}")','bouton1'], _ ; 'Test()'], _ ; call a function 'Test()' ['Windows version', 'winver.exe', 1, 'run("explorer.exe shell:::{BB06C0E4-D293-4f75-8A90-CB05B6477EEE}")','bouton2'], _ ; or "Run('winver.exe')" ['This computer', 'netcenter.dll', 6, 'run("explorer.exe shell:::{20D04FE0-3AEA-1069-A2D8-08002B30309D}")','bouton3'], _ ['Devices and Printers', 'SHELL32.dll', 272, 'run("explorer.exe shell:::{A8A91A66-3A7D-4424-8D24-04E180695C7A}")','bouton4'], _ ['Folder options', 'SHELL32.dll', 210, 'run("explorer.exe shell:::{6DFD7C5C-2451-11d3-A299-00C04F8EF6AF}")','bouton5'], _ ['Command Prompt', @ComSpec, 1, 'Run(@ComSpec)','bouton6'], _ ['Internet Explorer', @ProgramFilesDir & '\Internet Explorer\iexplore.exe', 1, "Run(@ProgramFilesDir & '\Internet Explorer\iexplore.exe')",'bouton7'], _ ['Media Player', @ProgramFilesDir & '\Windows media player\wmplayer.exe', 1, "Run(@ProgramFilesDir & '\Windows media player\wmplayer.exe')",'bouton8'], _ ['File browser', @WindowsDir & '\explorer.exe', 1, "Run(@WindowsDir & '\explorer.exe')",'bouton9'], _ ['Notepad', @SystemDir & '\notepad.exe', 1, "Run(@SystemDir & '\notepad.exe')",'bouton10'], _ ['Wordpad', @SystemDir & '\write.exe', 1, "Run(@SystemDir & '\write.exe')",'bouton11'], _ ['Registry editor', @SystemDir & '\regedit.exe', 1, "ShellExecute('regedit.exe')",'bouton12'], _ ['Connect to', 'netcenter.dll', 19, 'run("explorer.exe shell:::{38A98528-6CBF-4CA9-8DC0-B1E1D10F7B1B}")','bouton13'], _ ['Calculator', @SystemDir & '\Calc.exe', 1, "Run(@SystemDir & '\calc.exe')",'bouton14'], _ ['Control panel', 'control.exe', 1, 'run("explorer.exe shell:::{5399E694-6CE5-4D6C-8FCE-1D8870FDCBA0}")','bouton15'], _ ['Users manager', @SystemDir & '\Netplwiz.exe', 1, "ShellExecute('Netplwiz.exe')",'bouton16'], _ ; {7A9D77BD-5403-11d2-8785-2E0420524153} ['Run', 'SHELL32.dll', 25, 'Run("explorer.exe Shell:::{2559a1f3-21d7-11d4-bdaf-00c04f60b9f0}")','bouton17'], _ ['Search files', 'SHELL32.dll', 135, 'run("explorer.exe shell:::{9343812e-1c37-4a49-a12e-4b2d810d956b}")','bouton18'], _ ['On screen Magnifier', @SystemDir & '\Magnify.exe', 1, "ShellExecute('Magnify.exe')",'bouton19'], _ ['Paint', @SystemDir & '\mspaint.exe', 1, "Run(@SystemDir & '\mspaint.exe')",'bouton20'], _ ['Remote desktop', @SystemDir & '\mstsc.exe', 1, " Run('mstsc.exe')",'bouton21'], _ ['Resource monitoring', @SystemDir & '\resmon.exe', 1, "Run('resmon.exe')",'bouton22'], _ ['Device manager', 'SHELL32.dll', 13, 'Run("explorer.exe Shell:::{74246bfc-4c96-11d0-abef-0020af6b0b7a}")','bouton23'], _ ['Audio', 'SndVol.exe', 1, 'Run("explorer.exe Shell:::{F2DDFC82-8F12-4CDD-B7DC-D4FE1425AA4D}")','bouton24'], _ ; or 'run(@SystemDir & "\SndVol.exe")'] ['Task view', 'SHELL32.dll', 133, 'Run("explorer.exe shell:::{3080F90E-D7AD-11D9-BD98-0000947B0257}")','bouton25'], _ ['Task Manager', @SystemDir & '\taskmgr.exe', 1, 'Send("^+{ESC}")''bouton26'], _ ; "Run(@SystemDir & '\taskmgr.exe')",'bouton1'], _ ['On Screen Keyboard', 'osk.exe', 1, 'ProcessExists("osc.exe") ? False : ShellExecute("osk.exe")','bouton27'], _ ; <-- ternary example ['God Mode','control.exe', 1,'Run("explorer.exe Shell:::{ED7BA470-8E54-465E-825C-99712043E01C}")','bouton28'] _ ] ;#ce ;_arraydisplay($aStartTools) Global $fileConfig = $appdatauser & "\config.ini" if not FileExists($fileConfig) Then $file = FileOpen($fileConfig,1) IniWriteSection($fileConfig,"Position","Left=" & @CR & "top=" & @cr & "lignes="& @cr & "colones=") IniWriteSection($fileConfig,"COLOR","color=") FileClose($file) Else $apos[0] = IniRead($fileconfig,"Position","left",0) $apos[1] = iniread($fileconfig,"Position","top",0) $apos[2] = iniread($fileconfig,"Position","lignes",16) $apos[3] = iniread($fileconfig,"Position","colones",2) EndIf ;------------------------- recherche d'un fichier de lien------------------------------- Global $filelink = $appdatauser & "\launchpad.link" Global $aTools ; declaration of the array used by the application for all the links ;------------------------- recherche d'un fichier de lien------------------------------- local $nb_section local $ini = $filelink ; Lecture du fichier ini qui contient les raccourcis $sections = IniReadSectionNames($ini) ; lecture de toutes les sections du fichier ini (.link) if @error <> 0 then $nb_section = 0 if $nb_section == 0 Then ;consolewrite($nb_section & @CRLF) for $i = 1 to 40 iniwritesection($ini, "bouton" & $i,"label=Libre" & @CR& "link=" & @CR & "icone=" & @crlf) Next ;Sleep(1000) For $i = 0 to UBound($aStartTools) -1 iniwrite($ini,$aStartTools[$i][4] ,"label", $aStartTools[$i][0]) iniwrite($ini,$aStartTools[$i][4] ,"link", $aStartTools[$i][3]) iniwrite($ini,$aStartTools[$i][4] ,"icone", $aStartTools[$i][1] & ","& $aStartTools[$i][2]) Next $sections = IniReadSectionNames($ini) EndIf if IsArray($sections) then $nb_section = $sections[0] if $nb_section < 40 Then fileopen($ini,1) for $i = $nb_section + 1 to 40 iniwritesection($ini, "bouton" & $i,"label=Libre" & @CR& "link=" & @CR & "icone=" & @crlf) Next FileClose($ini) $sections = IniReadSectionNames($ini) EndIf $nb = $sections[0] ; tableau de toutes les sections Local $res[$nb+1][5] ; création d'un tableau qui va contenir l'ensemble des liens For $i = 1 to $nb ; remplissage du tableau $res ;$res[$i][0] = $sections[$i] ;consolewrite (@CRLF & $i & @TAB & IniRead($ini,$sections[$i],"label","erreur")) $res[$i-1][0] = IniRead($ini,$sections[$i],"label","erreur") ; lecture du fichier et remplissage des ruches du tableau $fichier_icone = stringsplit(IniRead($ini,$sections[$i],"icone","erreur"),",") if $fichier_icone[0] > 1 Then ;_ArrayDisplay($fichier_icone) $res[$i-1][1] = $fichier_icone[1] $res[$i-1][2] = $fichier_icone[2] Else $res[$i-1][1] = IniRead($ini,$sections[$i],"icone","erreur") EndIf $res[$i-1][3] = IniRead($ini,$sections[$i],"link","erreur") $res[$i-1][4] = $sections[$i] Next $aTools = $res ; Show desktop {3080F90D-D7AD-11D9-BD98-0000947B0257} ; Desktop Background {ED834ED6-4B5A-4bfe-8F11-A626DCB6A921} ; IE internet option {A3DD4F92-658A-410F-84FD-6FBBBEF2FFFE} ; ['Notes', 'StikyNot.exe', 1, "ShellExecute('StikyNot')"], _ ; ['... if Notepad is running' & @CRLF & 'Send F5 to it', 'SHELL32.dll', 167, ' WinExists("[CLASS:Notepad]") ? ControlSend("[CLASS:Notepad]", "", "", "{F5}") : MsgBox(16, ":(", "Notepad not found", 2)'] _ ; Check if Notepad is currently running ;_ArrayDisplay($aTools) Opt("TrayMenuMode", 3) Global $iStep = 40 ; button size Global $iNrPerLine if $apos[3] = "" Then $iNrPerLine = 2 Else $iNrPerLine = $apos[3] EndIf Global $iNrOfLines if $apos[2] = "" then $iNrOfLines = 20;Ceiling(UBound($aTools) / $iNrPerLine) Else $iNrOfLines = $aPos[2] EndIf if $apos[0] = "" then $apos[0] = @DesktopWidth - $iStep * 3 if $apos[1] = "" then $apos[1] = @DesktopHeight / 20 Global $GUI = GUICreate('LaunchPad', 10, 10, $apos[0] , $apos[1] ,$WS_THICKFRAME + $WS_EX_ACCEPTFILES, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) GUICtrlSetBkColor(-1,0xFFFFFF) $GuiContextMenu = GUICtrlCreateContextMenu() $idSavePosition = GUICtrlCreateMenuItem("Sauver la position", $GuiContextMenu) $idReinitializePosition = GUICtrlCreateMenuItem("Reinitialiser la position", $GuiContextMenu) GUICtrlCreateMenuItem("", $GuiContextMenu) $idReinstallLinkFile = GUICtrlCreateMenuItem("Reinitialisation complete", $GuiContextMenu) $idFixWindows = GUICtrlCreateMenuItem("Figer", $GuiContextMenu) Global $aMyMatrix = _GuiControlPanel("Button", $iNrPerLine, $iNrOfLines, $iStep, $iStep, BitOR(0x40, 0x1000), -1, 0, 0, 0, 0, 0, 0, False, "") ;_ArrayDisplay($idNewsubmenu) Global $iPreviousX = ($aMyMatrix[0])[1], $iPreviousY = ($aMyMatrix[0])[2] For $i = 1 To UBound($aMyMatrix)-1 GUICtrlSetResizing($aMyMatrix[$i], $GUI_DOCKALL) ; (2+32+256+512) so the control will not move during resizing If $i <= UBound($aTools) Then If $aTools[$i-1][$vButton_IconPath] = "" Then GUICtrlSetImage($aMyMatrix[$i], $dll_icones,80) GUICtrlSetTip(-1,"Glisser/déposer de (fichier/dossier/raccourcis) pour créer un nouveau lien") Else GUICtrlSetImage($aMyMatrix[$i], $aTools[$i-1 ][$vButton_IconPath], $aTools[$i-1 ][$vButton_IconNumber]) GUICtrlSetTip($aMyMatrix[$i], $aTools[$i -1][$vButton_Command],$aTools[$i-1 ][$vButton_Tip] ) EndIf EndIf Next _WinSetClientSize($GUI, ($aMyMatrix[0])[11], ($aMyMatrix[0])[12]) ; thanks to KaFu DragDropEvent_Startup() ;GUISetState(@SW_SHOW, $GUI) ;GUISetState(@SW_SHOW, $GuiIcon) ; https://devblogs.microsoft.com/oldnewthing/20110218-00/?p=11453 GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST") GUIRegisterMsg($WM_SIZING, "WM_SIZING") GUIRegisterMsg($WM_NOTIFY, WM_NOTIFY) TrayCreateItem("LAUNCHPAD") TrayCreateItem("") ; Create a separator line. Global $idHide = TrayCreateItem("Hide") Global $idShow = TrayCreateItem("Show") TrayCreateItem("") ; Create a separator line. Global $idExit = TrayCreateItem("Exit") Global $idPos = TrayCreateItem("Save windows Position") Global $idDfault = TrayCreateItem("Reinitialiser la position") Global $idOpenFileLink = TrayCreateItem("ouvrir le dossier des liens") TraySetState($TRAY_ICONSTATE_SHOW) _MainLoop() Func _MainLoop() Local $iDeltaX, $iDeltaY, $row, $col, $left, $top Global $hTimer = TimerInit() Local $aPos DragDropEvent_Register($GUI) GUIRegisterMsg($WM_DRAGENTER, "OnDragDrop") GUIRegisterMsg($WM_DRAGOVER, "OnDragDrop") GUIRegisterMsg($WM_DRAGLEAVE, "OnDragDrop") GUIRegisterMsg($WM_DROP, "OnDragDrop") While 1 Sleep (10) If _MouseIsOverHWnd($GUI) == false and _IsPressed(01) and $fixwindows = False then GUISetState(@SW_HIDE, $GUI) $hTimer = 0 EndIf If TimerDiff($hTimer) > 5000 and _MouseIsOverHWnd($GUI) == False and $fixwindows = False Then GUISetState(@SW_HIDE, $GUI) $hTimer = 0 EndIf $aCursor = GUIGetCursorInfo($GUI) $aPos = MouseGetPos () If $aPos[0] = 0 Or $aPos[1] = 0 Or $aPos[0] = @DesktopWidth-1 Or $aPos[1] = @DesktopHeight-1 Then $hTimer = TimerInit () EndIf While $aPos[0] = 0 Or $aPos[1] = 0 Or $aPos[0] = @DesktopWidth-1 Or $aPos[1] = @DesktopHeight-1 and not _IsPressed(01); The GUI appears when the mouse touch the screen borders for 1500 ms $aPos = MouseGetPos() if TimerDiff($hTimer) > 1000 then GUISetState(@SW_SHOW, $GUI) $hTimer = TimerInit() ExitLoop EndIf sleep(1) WEnd ;_______________________ ; If TimerDiff($hTimer) > 5000 Then ; GUISetState(@SW_HIDE, $GUI) ; $hTimer = 0 ; EndIf ; $aPos = MouseGetPos () ; If $aPos[0] = 0 Or $aPos[1] = 0 Or $aPos[0] = @DesktopWidth-1 Or $aPos[1] = @DesktopHeight-1 Then ; $hTimer = TimerInit () ; GUISetState(@SW_SHOW, $GUI) ; EndIf $Msg = GUIGetMsg() for $i = 0 to ubound($idNewsubmenu)-1 if $Msg = $idNewsubmenu[$i] and $aTools[$i][3] <> "" Then $sMsg = Msgbox(4,"","Etes vous sur de vouloir supprimer ce raccourcis ?") if $sMsg == 6 Then iniwrite($filelink,$aTools[$i][4],"label","Libre") iniwrite($filelink,$aTools[$i][4],"link","") iniwrite($filelink,$aTools[$i][4],"icone","") $atools[$i][0] = "Libre" $atools[$i][1] = "" $atools[$i][2] = "" $atools[$i][3] = "" GUICtrlSetImage($aMyMatrix[$i+1], $dll_icones,80) ToolTip("") EndIf EndIf Next For $i = 0 to ubound($idChangeIcon) - 1 If $Msg = $idChangeIcon[$i] and $atools[$i][3] <> "" Then $aRet = _PickIconDlg($dll_icones) If Not @error Then $aTools[$i][1] = $aRet[0] $aTools[$i][2] = $aRet[1] IniWrite($filelink,$aTools[$i][4],"icone",$aRet[0] & "," & $aRet[1]) GUICtrlSetImage($aMyMatrix[$i+1], $aTools[$i][1], $aTools[$i][2]) EndIf EndIf Next Switch $Msg Case $GUI_EVENT_CLOSE GUISetState(@SW_HIDE) $hTimer = 0 Case $aMyMatrix[1] To $aMyMatrix[40] $hTimer = TimerInit () For $i = 1 To UBound($aMyMatrix) - 1 If $Msg = $aMyMatrix[$i] Then If $i <= UBound($aTools) and $aTools[$i-1][3] <> "" Then if StringInStr($atools[$i-1][3],"run(") then $dummy = Execute($aTools[$i - 1][3]) Else $dummy = ShellExecute($aTools[$i - 1][3]) EndIf EndIf EndIf Next case $idSavePosition $apos = WinGetPos($gui) iniwrite($fileConfig,"Position","left",$apos[0]) iniwrite($fileConfig,"Position","top",$apos[1]) IniWrite($fileconfig,"Position","lignes",($aMyMatrix[0])[2]) IniWrite($fileconfig,"Position","colones",($aMyMatrix[0])[1]) msgbox(0,"","Position sauvegardée avec succès",3) Case $idReinitializePosition iniwrite($fileconfig,"position","left","") iniwrite($fileConfig,"Position","top","") IniWrite($fileconfig,"Position","lignes","") IniWrite($fileconfig,"Position","colones","") _RestartProgram() Case $idReinstallLinkFile local $sMsg = Msgbox(4,"","Etes vous certain de vouloir reinitialiser tous les liens ?") if $sMsg == 6 Then FileDelete($filelink) _RestartProgram() EndIf Case $idFixWindows if $fixwindows = False Then $fixwindows = True GUICtrlSetState($msg, $GUI_CHECKED + $GUI_UNCHECKED - BitAND(GUICtrlRead($msg), $GUI_UNCHECKED) - BitAND(GUICtrlRead($msg), $GUI_CHECKED)) Else $fixwindows = False GUICtrlSetState($msg, $GUI_CHECKED + $GUI_UNCHECKED - BitAND(GUICtrlRead($msg), $GUI_CHECKED) - BitAND(GUICtrlRead($msg), $GUI_UNCHECKED)) EndIf EndSwitch Switch TrayGetMsg() Case $idShow $hTimer = TimerInit () GUISetState(@SW_SHOW) Case $idHide GUISetState(@SW_HIDE) $hTimer = 0 Case $idExit ExitLoop Case $idPos $apos = WinGetPos($gui) iniwrite($fileConfig,"Position","left",$apos[0]) iniwrite($fileConfig,"Position","top",$apos[1]) IniWrite($fileconfig,"Position","lignes",($aMyMatrix[0])[2]) IniWrite($fileconfig,"Position","colones",($aMyMatrix[0])[1]) case $idDfault iniwrite($fileconfig,"position","left","") iniwrite($fileConfig,"Position","top","") IniWrite($fileconfig,"Position","lignes","") IniWrite($fileconfig,"Position","colones","") _RestartProgram() Case $idOpenFileLink ShellExecute(@AppDataDir & "\Launchpad") EndSwitch ; check if any size has changed If $iPreviousX <> ($aMyMatrix[0])[1] Or $iPreviousY <> ($aMyMatrix[0])[2] Then ; calculate the variations $iDeltaX = Abs($iPreviousX - ($aMyMatrix[0])[1]) $iDeltaY = Abs($iPreviousY - ($aMyMatrix[0])[2]) ; if both dimensions changed at the same time, the largest variation prevails over the other If $iDeltaX >= $iDeltaY Then ; keep the new number of columns ; calculate and set the correct number of lines accordingly _SubArraySet($aMyMatrix[0], 2, Ceiling((UBound($aMyMatrix) - 1) / ($aMyMatrix[0])[1])) Else ; otherwise keep the new number of rows ; calculate and set the correct number of columns accordingly _SubArraySet($aMyMatrix[0], 1, Ceiling((UBound($aMyMatrix) - 1) / ($aMyMatrix[0])[2])) EndIf ; set client area new sizes _WinSetClientSize($GUI, ($aMyMatrix[0])[1] * $iStep, ($aMyMatrix[0])[2] * $iStep) ; remember the new panel settings $iPreviousX = ($aMyMatrix[0])[1] $iPreviousY = ($aMyMatrix[0])[2] ; rearrange the controls inside the panel For $i = 0 To UBound($aMyMatrix) - 2 ; coordinates 1 based $col = Mod($i, $iPreviousX) + 1 ; Horizontal position within the grid (column) $row = Int($i / $iPreviousX) + 1 ; Vertical position within the grid (row number) $left = ($aMyMatrix[0])[5] + (((($aMyMatrix[0])[3] + ($aMyMatrix[0])[9]) * $col) - ($aMyMatrix[0])[9]) - ($aMyMatrix[0])[3] + ($aMyMatrix[0])[7] $top = ($aMyMatrix[0])[6] + (((($aMyMatrix[0])[4] + ($aMyMatrix[0])[10]) * $row) - ($aMyMatrix[0])[10]) - ($aMyMatrix[0])[4] + ($aMyMatrix[0])[8] GUICtrlSetPos($aMyMatrix[$i + 1], $left, $top) Next EndIf WEnd EndFunc ;==>_MainLoop Func _MouseIsOverHWnd($hWnd) ;to check if mouse is on or off GUI Local $bMouseOver If not WinActive($hWnd) then return False Local $aMousePos = MouseGetPos() Local $aWinPos = WinGetPos($hWnd) if ($aMousePos[0] < $aWinPos[0] Or $aMousePos[0] > $aWinPos[0] + $aWinPos[2]) Or ($aMousePos[1] < $aWinPos[1] Or $aMousePos[1] > $aWinPos[1] + $aWinPos[3]) Then $bMouseOver = False Else $bMouseOver = True EndIf Return $bMouseOver EndFunc ;==>_MouseIsOverHWnd Func WM_NOTIFY ($hwnd, $iMsg, $iwParam, $ilParam) If $hwnd = $GUI Then $hTimer = TimerInit () Return $GUI_RUNDEFMSG EndFunc ; Allow/Disallow specific borders resizing ; thanks to Danyfirex ; --------- ; https://www.autoitscript.com/forum/topic/201464-partially-resizable-window-how-solved-by-danyfirex-%F0%9F%91%8D/?do=findComment&comment=1445748 Func WM_NCHITTEST($hwnd, $iMsg, $iwParam, $ilParam) If $hwnd = $GUI Then $hTimer = TimerInit() Local $iRet = _WinAPI_DefWindowProc($hwnd, $iMsg, $iwParam, $ilParam) ; https://docs.microsoft.com/en-us/windows/win32/inputdev/wm-nchittest If $iRet = $HTBOTTOM Or $iRet = $HTRIGHT Or $iRet = $HTBOTTOMRIGHT Or $iRet = $HTCAPTION Or $iRet = $HTCLOSE Then Return $iRet ; default process of border resizing Else ; resizing not allowed Return $HTCLIENT ; do like if cursor is in the client area EndIf EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_NCHITTEST ; controls and process resizing operations in real time ; thanks to mikell ; ------ ; https://www.autoitscript.com/forum/topic/201464-partially-resizable-window-how-solved-by-danyfirex-%F0%9F%91%8D/?do=findComment&comment=1445754 Func WM_SIZING($hwnd, $iMsg, $wparam, $lparam) ; https://docs.microsoft.com/en-us/windows/win32/winmsg/wm-sizing Local $iCols = ($aMyMatrix[0])[1] Local $iRows = ($aMyMatrix[0])[2] Local $xClientSizeNew, $yClientSizeNew #cs $wparam The edge of the window that is being sized. $lparam A pointer to a RECT structure with the screen coordinates of the drag rectangle. To change the size or position of the drag rectangle, an application must change the members of this structure. Return value Type: LRESULT #ce $wparam $aPos = WinGetPos($GUI) #cs Success : a 4 - element array containing the following information : $aArray[0] = X position $aArray[1] = Y position $aArray[2] = Width #ce Success : a 4 - element array containing the following information : $aPos2 = WinGetClientSize($GUI) #cs Success: a 2-element array containing the following information: $aArray[0] = Width of window's client area #ce Success: a 2-element array containing the following information: ; https://docs.microsoft.com/en-us/previous-versions//dd162897(v=vs.85) Local $sRect = DllStructCreate("Int[4]", $lparam) ; outer dimensions (includes borders) Local $left = DllStructGetData($sRect, 1, 1) Local $top = DllStructGetData($sRect, 1, 2) Local $Right = DllStructGetData($sRect, 1, 3) Local $bottom = DllStructGetData($sRect, 1, 4) ; border width Local $iEdgeWidth = ($aPos[2] - $aPos2[0]) / 2 Local $iHeadHeigth = $aPos[3] - $aPos2[1] - $iEdgeWidth * 2 Local $aEdges[2] $aEdges[0] = $aPos[2] - $aPos2[0] ; x $aEdges[1] = $aPos[3] - $aPos2[1] ; y $xClientSizeNew = $Right - $left - $aEdges[0] $xClientSizeNew = Round($xClientSizeNew / $iStep) * $iStep $yClientSizeNew = $bottom - $top - $aEdges[1] $yClientSizeNew = Round($yClientSizeNew / $iStep) * $iStep Switch $wparam Case $WMSZ_RIGHT ; calculate the new position of the right border DllStructSetData($sRect, 1, $left + $xClientSizeNew + $aEdges[0], 3) Case $WMSZ_BOTTOM ; calculate the new position of the bottom border DllStructSetData($sRect, 1, $top + $yClientSizeNew + $aEdges[1], 4) Case $WMSZ_BOTTOMRIGHT ; calculate the new position of both borders DllStructSetData($sRect, 1, $left + $xClientSizeNew + $aEdges[0], 3) DllStructSetData($sRect, 1, $top + $yClientSizeNew + $aEdges[1], 4) EndSwitch #cs If DllStructGetData($sRect, 1, 3) > @DesktopWidth Then ; $Right DllStructSetData($sRect, 1, DllStructGetData($sRect, 1, 3) - $iStep, 3) $xClientSizeNew -= $iStep EndIf If DllStructGetData($sRect, 1, 4) > @DesktopHeight Then ; $bottom DllStructSetData($sRect, 1, DllStructGetData($sRect, 1, 4), 4) $yClientSizeNew -= $iStep #ce If DllStructGetData($sRect, 1, 3) > @DesktopWidth Then ; $Right ; check if number of rows has changed If $iRows <> $yClientSizeNew / $iStep Then _SubArraySet($aMyMatrix[0], 2, $yClientSizeNew / $iStep) EndIf ; check if number of columns has changed If $iCols <> $xClientSizeNew / $iStep Then _SubArraySet($aMyMatrix[0], 1, $xClientSizeNew / $iStep) EndIf ;consolewrite(@crlf & "rows =" & @tab & $iRows & @tab & "Col =" & @TAB & $iCols & @tab & "$xClientSizeNew = " & @tab & $xClientSizeNew & @tab & "$yClientSizeNew =" & @tab & $yClientSizeNew ) Return $GUI_RUNDEFMSG EndFunc ;==>WM_SIZING ; set client area new sizes ; thanks to 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 ; ; #FUNCTION# ==================================================================================================================== ; Name...........: _GuiControlPanel ; 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, $style, $exStyle, $xPos = 0, $yPos = 0, $xBorder, $yBorder, $xSpace = 1, $ySpace = 1, $Group = false, , $sGrpTitle = "") ; 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 ; $Style - Defines the style of the control ; $exStyle - Defines the extended style of the 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, $style = -1, $exStyle = -1, $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 $PanelWidth = (($ctrlWidth + $xSpace) * $nrPerLine) - $xSpace + ($xBorder * 2) Local $PanelHeight = (($ctrlHeight + $ySpace) * $nrOfLines) - $ySpace + ($yBorder * 2) Local $hGroup If $Group Then If $sGrpTitle = "" Then $xPanelPos += 1 $yPanelPos += 1 $hGroup = GUICtrlCreateGroup("", $xPanelPos - 1, $yPanelPos - 7, $PanelWidth + 2, $PanelHeight + 8) GUICtrlSetColor(-1, 0xFFFFFF) Else $xPanelPos += 1 $yPanelPos += 15 $hGroup = GUICtrlCreateGroup($sGrpTitle, $xPanelPos - 1, $yPanelPos - 15, $PanelWidth + 2, $PanelHeight + 16) GUICtrlSetColor(-1, 0xFFFFFF) EndIf EndIf ; create the controls Local $aGuiGridCtrls[$nrPerLine * $nrOfLines + 1] Local $aPanelParams[14] = [ _ $ControlType, $nrPerLine, $nrOfLines, $ctrlWidth, $ctrlHeight, _ $xPanelPos, $yPanelPos, $xBorder, $yBorder, $xSpace, $ySpace, $PanelWidth, $PanelHeight, $hGroup] For $i = 0 To $nrPerLine * $nrOfLines - 1 ; coordinates 1 based $col = Mod($i, $nrPerLine) + 1 ; Horizontal position within the grid (column) $row = Int($i / $nrPerLine) + 1 ; Vertical position within the grid (row) $left = $xPanelPos + ((($ctrlWidth + $xSpace) * $col) - $xSpace) - $ctrlWidth + $xBorder $top = $yPanelPos + ((($ctrlHeight + $ySpace) * $row) - $ySpace) - $ctrlHeight + $yBorder $text = $i + 1 ; "*" ; "." ; "(*)" ; create the control(s) if $i >= ubound($aTools)-1 Then ExitLoop Else $aGuiGridCtrls[$i + 1] = Execute("GUICtrlCreate" & $ControlType & "($text, $left, $top, $ctrlWidth, $ctrlHeight, $style, $exStyle)") ;Global $g_tile_notif = GUICtrlCreateDummy() $idContextmenu = GUICtrlCreateContextMenu($aGuiGridCtrls[$i + 1]) $idNewsubmenu[$i] = GUICtrlCreateMenuItem("Supprimer", $idContextmenu) $idChangeIcon[$i] = GUICtrlCreateMenuItem("Changer Icone", $idContextmenu) if $aTools[$i][1] = "" then ;GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT) ;WinSetTrans(-1,Default,100) EndIf EndIf Next If $Group Then GUICtrlCreateGroup("", -99, -99, 1, 1) ; close group $aGuiGridCtrls[0] = $aPanelParams Return $aGuiGridCtrls EndFunc ;==>_GuiControlPanel ; writes a value to an element of an array embedded in another array Func _SubArraySet(ByRef $aSubArray, $iElement, $vValue) $aSubArray[$iElement] = $vValue EndFunc ;==>_SubArraySet ;Func _WinAPI_AdjustWindowRectEx(ByRef $tRECT, $iStyle, $iExStyle = 0, $bMenu = False) ; Local $aRet = DllCall('user32.dll', 'bool', 'AdjustWindowRectEx', 'struct*', $tRECT, 'dword', $iStyle, 'bool', $bMenu, _ ; 'dword', $iExStyle) ; If @error Then Return SetError(@error, @extended, False) ; ; If Not $aRet[0] Then Return SetError(1000, 0, 0) ; ; Return $aRet[0] ;EndFunc ;==>_WinAPI_AdjustWindowRectEx Func OnDragDrop($hWnd, $Msg, $wParam, $lParam) ;consolewrite($hWnd & @tab & $Msg & @crlf) Static $DropAccept Switch $Msg Case $WM_DRAGENTER, $WM_DROP ToolTip("") Select Case DragDropEvent_IsFile($wParam) If $Msg = $WM_DROP Then Position() ; needed for _WinAPI_WindowFromPoint Local $mouseId = _WinAPI_WindowFromPoint($g_tStruct) ; Find de hwnd of the control because GUIGetCursorInfo doesn't work with text file $mouseId = _WinAPI_GetDlgCtrlID($mouseId) ; gets the Id of hwnd Local $FileList = DragDropEvent_GetFile($wParam) consolewrite(@CRLF & $FileList) Local $section , $latools Local $aDetails = FileGetShortcut($FileList) if IsArray($aDetails) Then $Program = $aDetails[0] EndIf Local $ProposeLink = stringsplit($FileList,"\") $ProposeLink = StringRegExpReplace($ProposeLink[UBound($ProposeLink)-1], '(.*)\..*', "$1") For $i = 1 To UBound($aMyMatrix) - 1 If $mouseId = $aMyMatrix[$i] and $aTools[$i - 1][3] = "" Then $section = $aTools[$i -1][4] $latools = $i - 1 consolewrite(@crlf & $section & @TAB & $fileList) iniwrite($filelink,$section,"link",$FileList) ExitLoop Elseif $mouseId = $aMyMatrix[$i] and $aTools[$i -1][3] <> "" Then $section = $aTools[$i -1][4] $latools = $i -1 Local $question = msgbox(4,"", "Etes vous certain de vouloir écraser le raccourcis existant ?") if $question == 6 then consolewrite(@crlf & $section & @TAB & $filelist) iniwrite($filelink,$section,"link",$FileList) else Return EndIf ExitLoop EndIf Next Local $reponse = InputBox("Nom de l'icone","Donnez un titre au raccourcis",$ProposeLink); quel label aura le raccourcis if @error == 1 or $reponse = "" Then iniwrite($filelink,$section,"link","") Iniwrite($filelink,$section,"label","") Return EndIf Iniwrite($filelink,$section,"label",$reponse); tout est ok on peut ecrire la valeur dans le fichier de config local $sExt = StringRegExpReplace($FileList, "^.*\.", "") ; extraction de son extension Switch $sExt case "doc" , "docx" , "odt" IniWrite($filelink,$section,"icone",$dll_icones &",436") case "xls" , "xlsx" , "ods" IniWrite($filelink,$section,"icone",$dll_icones &",441") case "pdf" IniWrite($filelink,$section,"icone",$dll_icones &",400") Case "ppt" , "pptx" , "odp" IniWrite($filelink,$section,"icone",$dll_icones &",431") Case "txt" , "rtf" IniWrite($filelink,$section,"icone",$dll_icones &",406") Case Else if $sExt = "lnk" then $FileList = $Program if _WinAPI_ExtractIconEx( $FileList,-1,0,0,0) > 0 Then ; permet de tester si le fichier possède une ou plusiers icone(s) Local $aIcon[3] = [64, 32, 16] For $i = 0 To UBound($aIcon) - 1 $aIcon[$i] = _WinAPI_Create32BitHICON(_WinAPI_ShellExtractIcon($FileList,0, $aIcon[$i], $aIcon[$i]), 1) Next _WinAPI_SaveHICONToFile(@ScriptDir & "\Assets\" & $reponse & ".ico", $aIcon) For $i = 0 To UBound($aIcon) - 1 _WinAPI_DestroyIcon($aIcon[$i]) Next IniWrite($filelink,$section,"icone",@ScriptDir & "\Assets\" & $reponse & ".ico"); si oui écriture dans le fichier Else $aRet = _PickIconDlg($dll_icones) If Not @error Then IniWrite($filelink,$section,"icone",$aRet[0] & "," & $aRet[1]) Else iniwrite($filelink,$section,"link","") Iniwrite($filelink,$section,"label","") Return EndIf EndIf EndSwitch $fichier_icone = stringsplit(IniRead($filelink,$aTools[$latools][4],"icone","erreur"),",") if $fichier_icone[0] > 1 Then $aTools[$latools][1] = $fichier_icone[1] $aTools[$latools][2] = $fichier_icone[2] Else $aTools[$latools][1] = IniRead($filelink,$aTools[$latools][4],"icone","erreur") $aTools[$latools][2] = "," & Number("0") EndIf $aTools[$latools][0] = $reponse $aTools[$latools][3] = IniRead($filelink,$section,"link","erreur") for $i = 0 to 4 consolewrite (@CRLF & "colone " & $i & @TAB & $aTools[$latools][$i]) Next ;GUICtrlSetBkColor($mouseId,$GUI_BKCOLOR_TRANSPARENT) GUICtrlSetImage($mouseId, $aTools[$latools][1], $aTools[$latools][2]) GUICtrlSetTip($mouseId, $aTools[$latools][3],$aTools[$latools][0]) EndIf $DropAccept = $DROPEFFECT_COPY Case DragDropEvent_IsText($wParam) If $Msg = $WM_DROP Then Position() ; needed for _WinAPI_WindowFromPoint to get the right hwnd Local $mouseId = _WinAPI_WindowFromPoint($g_tStruct) ; Find de hwnd of the control because GUIGetCursorInfo doesn't work $mouseId = _WinAPI_GetDlgCtrlID($mouseId) ; gets the Id of hwnd $hyperlink = DragDropEvent_GetText($wParam) Local $section , $latools For $i = 1 To UBound($aMyMatrix) - 1 ;consolewrite($i & " " ) If $mouseId = $aMyMatrix[$i] and $aTools[$i-1][3] = "" Then $section = $aTools[$i-1][4] $latools = $i -1 iniwrite($filelink,$section,"link",$hyperlink) ExitLoop Elseif $mouseId = $aMyMatrix[$i] and $aTools[$i-1][3] <> "" Then $section = $aTools[$i-1][4] $latools = $i -1 Local $question = msgbox(4,"", "Etes vous certain de vouloir écraser le raccourcis existant ?") if $question == 6 then iniwrite($filelink,$section,"link",$hyperlink) else Return EndIf ExitLoop EndIf Next $reponse = InputBox("Nom du lien","Donnez un titre !",StringTrimLeft($hyperlink,7)) if @error == 1 or $reponse = "" Then Return Iniwrite($filelink,$section,"label",$reponse) $aRet = _PickIconDlg($dll_icones) If Not @error Then IniWrite($filelink,$section,"icone",$aRet[0] & "," & $aRet[1]) Else iniwrite($filelink,$section,"link","") Iniwrite($filelink,$section,"label","") Return EndIf $fichier_icone = stringsplit(IniRead($filelink,$aTools[$latools][4],"icone","erreur"),",") if $fichier_icone[0] > 1 Then $aTools[$latools][1] = $fichier_icone[1] $aTools[$latools][2] = $fichier_icone[2] Else $aTools[$latools][1] = IniRead($filelink,$aTools[$latools][4],"icone","erreur") $aTools[$latools][2] = "," & Number("0") EndIf $aTools[$latools][0] = $reponse $aTools[$latools][3] = $hyperlink for $i = 0 to 4 consolewrite (@CRLF & "colone " & $i & @TAB & $aTools[$latools][$i]) Next ;GUICtrlSetBkColor($mouseId,$GUI_BKCOLOR_TRANSPARENT) GUICtrlSetImage($mouseId, $aTools[$latools][1], $aTools[$latools][2]) GUICtrlSetTip($mouseId, $aTools[$latools][3],$aTools[$latools][0]) EndIf $DropAccept = $DROPEFFECT_COPY Case Else $DropAccept = $DROPEFFECT_NONE EndSelect Return $DropAccept Case $WM_DRAGOVER Return $DropAccept Case $WM_DRAGLEAVE ToolTip("") EndSwitch EndFunc Func Test() MsgBox(0, 0, ":)", 1) EndFunc ;==>Test Func _Check_LabelForbidden($string) if $string = "Libre" then $string = 1 Return $string EndFunc Func _PickIconDlg($sFileName, $nIconIndex=0, $hWnd=0) Local $nRet, $aRetArr[2] $nRet = DllCall("shell32.dll", "int", "PickIconDlg", _ "hwnd", $hWnd, _ "wstr", $sFileName, "int", 1000, "int*", $nIconIndex) If Not $nRet[0] Then Return SetError(1, 0, -1) $aRetArr[0] = $nRet[2] $aRetArr[1] = $nRet[4] + 1 Return $aRetArr EndFunc Func Position() DllStructSetData($g_tStruct, "x", MouseGetPos(0)) DllStructSetData($g_tStruct, "y", MouseGetPos(1)) EndFunc ;==>Position #Region --- Restart Program --- Func _RestartProgram() If @Compiled = 1 Then Run(FileGetShortName(@ScriptFullPath)) Else Run(FileGetShortName(@AutoItExe) & " " & FileGetShortName(@ScriptFullPath)) EndIf Exit EndFunc; ==> _RestartProgram #EndRegion --- Restart Program ---1 point