Leaderboard
Popular Content
Showing content with the highest reputation on 01/23/2014 in all areas
-
GUI/Tray Menu with icons and colors
abberration reacted to Holger for a topic
Hi outthere here is my script-stuff to create ownerdrawn menuitems with icons and colors. It uses GUIRegisterMsg() and WM_DRAWITEM / WM_MEASUREITEM - messages proceeding. Holger Update 06.05.2008: !!! Warning: Script breaking !!! Please change the following commands to: _TrayCreateItem(Text, ...) _TrayCreateMenu(Text , ...) - Fixed: some old values (thanks to aGorilla) - Fixed: ..SetText() functions (thanks to MrCreatoR) - Added the following commands: _SetMenuIconBkGrdColor(Color) ; set icon background gradient color _SetTrayIconBkGrdColor(Color) ; set icon background gradient color New sidebar menu commands: _CreateSideMenu(MenuID) ; returns a SideMenuID/index _DeleteSideMenu(SideMenuID) ; delete a menu sidebar _SetSideMenuText(SideMenuID, Text) ; set a text for the sidebar _SetSideMenuColor(SideMenuID, Color) ; set text color _SetSideMenuBkColor(SideMenuID, Color) ; set text background color _SetSideMenuBkGradColor(SideMenuID, Color) ; set text background gradient color _SetSideMenuImage(SideMenuID, Bitmapfile [, Resourcename/number [, Expand/Compress Bitmap]]) Just take a look into the samples how to use them! At the moment there are some known issues: - missing 64bit compatibility (already in progress, to fully work with "AutoIt3_x64.exe") - moving the mouse cursor on the sidebar menu image/text also changes the current menu item selection - for sidebar menu image only bitmaps are supported at the moment (min.8bpp) Update 23.03.2008: !!! Warning: Please update all your scripts and add after _TrayIconCreate() the command _TrayIconSetState() - otherwise you will not see any tray icons!!! Also update your icon numbers like for GUI icons - Fixed: some things (thanks to nickston) - Changed: _TrayIconCreate() do not show automatically the icon - Changed: icon behaviour now more similar to GUI icons (I hope) - Added: command.txt - Removed: unicode macro History: CODEUpdate 21.03.2008: - Changed: dynamic array sizing of the saved menu items - Added: _TrayDeleteItem(menuID), _GUICtrlODMenuItemDelete($nID) - please delete menu (items) with these commands - Added: _TrayIconSetState() modes 4 and 8 for flashing and flashstopping of tray icons - Added: _SetFlashTimeOut([timeOut]) to set the flash timeout - Added: OnEvent sample Update 23.02.2008: - Fixed: GDI object overload while using bold font Update 22.02.2008: - Added: _TrayItemSetSelIcon(ItemID, IconFile, IconID) - set the icon if the item is selected - Added: _GUICtrlODMenuItemSetIcon(ItemID, IconFile, IconID) - set the icon of the item - Added: _GUICtrlODMenuItemSetSelIcon(ItemID, IconFile, IconID) - set the icon if the item is selected - Added: "ModernMenuRaw.au3" which only includes the unknown constants, should better work with 'Au3Check' now Update 12.01.2008-2: - Fixed: Missing underscore in "CreateMenuFontByName"-function (Font fallback function) (thanks to MsCreatoR and GEOSoft). - Changed: If a menuitem is disabled then the rect only is showing around the item - Added: Underscore in menutext only showing when pressing "Alt"-key Update 12.01.2008: - Changed: 'local' Dll calls to global DllOpen to speedup (some virusscanners sometimes slowdown the process cause of opening these Dll's again and again) - Added: Using of @Tab for accelerator showing/drawing Update 07.12.2007: - Changed: all stuff in only 1 ZIP file - Fixed: now works with 3.2.10.0 and 3.2.8.1 Update 03.08.2007 - Fixed: error in _TrayIconDelete() and new creation - Added: additional parameter to _TrayIconCreate(ToolTip, IconFile, IconID, Callback, Msg, hIcon) to use existing icon handles - Added: sample_Win2Tray: 'moves' all minimized windows to the tray Update 28.07.2007 - Fixed: wrong call of function CreateFont() - Thanks to SleepyExtreme for info - Changed: included samples to demonstrate using of icon clicks Update 26.07.2007 - Fixed: missing function: LoadIcon() Update 21.07.2007 - added bold item support - limited to menuitems only, menus are not supported Update 17.07.2007: - now you can also menu icons for the tray - added commands for Tray: _TrayIconCreate() _TrayCreateMenu() _TrayCreateItem() _TrayItemSetIcon() _TrayIconSetState() _TrayTip() So you can have more than 1 tray icon for 1 Autoit3-script. Update 01.07.2007: - now works with unicode (3.2.4.9) - new command: _GUICtrlODMenuItemSetText(ControlID, NewText) Update 21.08.2006: - delete 1 line in libs to work with current release 3.2.0.X (error: cannot redeclare constant...) - Thanks to Javascript_Freek for info Update 02.02.2006: - added Checked-state for normal menu items and radio menu items - added a like ModernMenuLib-script for easier create/use these menustuff (see sample in the ModernMenuLib-folder) ModernMenuLib_with_Tray.zip1 point -
The AutoItObject team is proud to announce that the first version of our AutoItObject UDF is complete and ready to use. The project page is located at [currently missing] Please, report bugs and any other issues at our [currently missing], and not here. An overview of all the functions can be found in the online documentation [currently missing] or in the offline .chm documentation file which is included with the [currently missing]. If Origo has problems providing the download, the current version will be mirrored here The UDF requires the current AutoIt version v3.3.4.0! AutoItObject 1.2.8.2.exe AutoItObject 1.2.8.2.zip Please, leave your comments and experiences here. Regards, - trancexx - ProgAndy - monoceres - Kip Our work is published under the Artistic License 2.0 A copy of the FAQ to answer your most urgent questions right away: (can also be found at the online documentation: Some helper-functions: When using the Wrapper, this are some simple methods to get a return value from the resulting array. ; #FUNCTION# ==================================================================================================================== ; Name...........: _AIOResult ; Description ...: Returns the return value of the Call to a WraperObject function ; Syntax.........: _AIOResult(Const $aResult [, $vError=0] ) ; Parameters ....: $aResult - the resulting array ; $vError - [optional] value to be returned if result is no array (default: 0) ; Return values .: Success - Returnvalue ($aResult[0]) ; Failure - $vError, @error set to 1 ; Author ........: Prog@ndy ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; ; =============================================================================================================================== Func _AIOResult(Const $aResult, $vError=0) ; Author: Prog@ndy If IsArray($aResult) Then Return $aResult[0] Return SetError(1,0,$vError) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _AIOParam ; Description ...: Returns the parameter value of the Call to a WraperObject function ; Syntax.........: _AIOParam(Const $aResult, $iParam, $vError=0) ; Parameters ....: $aResult - the resulting array ; $iParam - The parameterindex to return (0: result, 1: first parameter, 2: 2nd parameter, ...) ; $vError - [optional] value to be returned if result is no array (default: 0) ; Return values .: Success - Parameter value ; Failure - $vError, @error set to 1 ; Author ........: Prog@ndy ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; ; =============================================================================================================================== Func _AIOParam(Const $aResult, $iParam, $vError=0) ; Author: Prog@ndy If UBound($aResult)-1 < $iParam Then Return SetError(1,0,$vError) Return SetExtended($aResult[0], $aResult[$iParam]) EndFunc1 point
-
I started this JSON library back in late 2007, because I needed a way to pass structured data between Javascript HTAs and AutoIt3 scripts. I've recently worked to get it in good enough shape to share with the AutoIt community, and while it still needs a bit more polish, the core functionality should be solid. Three files are included in the attached archive: JSON.au3 – the UDF Library itself. It includes a (very large) comment section at the top, which should provide sufficient documentation on how the various data types are encoded and decoded, as well as the various Javascript-based decoding extensions allowed (single-quoted strings, comments, etc.).JSON_Translate.au3 provides example functions for the powerful "translator" functionality. Translator functions can be used for both encoding and decoding. When encoding, it allows you to recursively convert your data from its normal format into the required data structures used by the JSON UDF library. When decoding, it allows you to convert the data in the opposite direction – from the JSON UDF library's data structures to the data structures your program normally uses. To use this functionality, you'll need to write your own translator functions, but this allows you to meet the custom needs of your own programs without having to hack JSON.au3. The examples provided in this file can probably be improved, but show one way of translating AutoIt-specific data types (such as binary and hwnd) back and forth.testJSON.au3 provides some quick examples of regular and translator-enhanced usage, which also help verify that encoding and decoding are working properly. These tests may not be comprehensive.The area needing the most work is error-handling. JSON data structures can be deeply nested, and it's tricky to make sure errors "bubble up" properly in AutoIt. (Plus, I need a flowchart to keep track of all my setError() numbers!) Thanks to Douglas Crockford of JSON.org, whose 2005 Javascript code for JSON encoding and decoding provided an excellent starting point for this library. Edit: updated to 0.9.1 on 2009-10-19 substantially updated opening commentsencoding: implemented logic to return "warning" @error flags for unsupported variable types & JSON objects with non-unique key stringsother minor fixes & tweaksJSON.7z1 point
-
_LargeFileCopy UDF
hudsonhock reacted to wraithdu for a topic
Several people have had problems with their GUIs freezing when they try to copy large files using FileCopy(). This is because FileCopy() is a blocking function, and the GUI stops responding to messages from the OS during the operation. If that goes on long enough, the OS thinks it is hung and you get the (Not Responding) thing going on. Here's a function that copies large files using Windows API calls in 8MB 2 MB chunks. This keeps the GUI alive and responsive. I've added additional copy verification functionality as well (disabled by default). Take a look at my A3COPY project for a great usage example of this UDF. Update: 1/31/13 - Moved a few more functions into _FileEx. - Fixed a bug in GetDiskClusterSize function. Update: 10/8/12 - Fixed bug due to missing RtlCopyMemory and RtlCompareMemory exports in x86 kernel32.dll. Now uses RtlMoveMemory and RtlCompareMemory from ntdll.dll (sorry). Update: 10/4/12 Read NOTES at top of UDF - Reduced default buffer size to 2 MB - Added flags for copying source file attributes, all three file times individually, ACL security descriptors and ownership, and NTFS specific compression and encryption - Optimized buffer creation - Enhanced path handling to fully support UNC and network conventions ( C:... , ?C:... , srvshare... , ?UNCsrvshare... ) - Removed C runtime functions (msvcrt.dll) in favor of native kernel32 functions - Code cleanup and many optimizations in LFC and the accompanying _FileEx UDF Update: 4/15/11 - Added additional verification methods - bit by bit, and size only - The default verification method (ie iFlag 8) is now bit by bit - it is faster and less computationally intensive than MD5 hashing, it also allows the function to bail out early in the case of a failed copy operation Update: 3/9/11 SCRIPT BREAKING CHANGES - Combined some parameters into one iFlags parameter - Re-ordered some parameters based on priority - Added a parameter to specify a different read buffer size - Destination file is now opened with GENERIC_READ | GENERIC_WRITE per MSDN for better compatibility copying files across a network - No longer create destination directory structure unless specified in iFlags parameter Update: 9/20/10 - Removed tracexxx's hashing functions (sorry!) in favor of a different method which is not RAM limited - Hashing algorithm can be specified (those supported by Crypt.au3: CALG_MD2, CALG_MD4, CALG_MD5, CALG_SHA1) Update: 8/26/10 - Fix for failed verification of 0 byte files - Added check for 0 byte source in RAW functions Update: 8/22/10 - Small change to CreateFile function to avoid errors when opening SYSTEM or HIDDEN files when specifying CREATE_ALWAYS. Update: 8/10/10 - Added _LargeFileCopyUnbuffered and _LargeRawCopyUnbuffered which will copy files using unbuffered I/O. - MD5 hashing of the source file / memory block is now done on the fly from the memory buffer. This avoids an additional read of the source file later on and saves time. - Destination file MD5 hashing is now done with trancexxx's nice hashing UDF. It uses the Windows API and is really fast. Update: 7/9/2010 - Added _LargeRawCopy which will copy large memory blocks (usually from an embedded resource) to a file in the same manner as _LargeFileCopy. This function also has the verify functionality via MD5 hash. Update: 7/8/2010 - Added optional user function and variable parameters. This function, if given, will be called after each write operation with the total bytes written, total file size in bytes, and the user given variable. This is perfect for a copy-with-progess type of function call. Example #NoTrayIcon #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <_LargeFileCopy.au3> _Main() Func _Main() Local $msg, $timer, $ret Local $src = "ubuntu-10.04-desktop-i386.iso" ; <---- path to a really large file goes here, recommended 600MB+ Local $destpath = @DesktopDir & "testdir" ; <---- destination path goes here GUICreate("File Copy Test", 250, 150) GUICtrlCreateLabel("Try to interact with the GUI during file copy...", 20, 15) Local $go = GUICtrlCreateButton("Copy Large File", 50, 50, 150, 50) Local $doing = GUICtrlCreateLabel("Ready...", 20, 120, 200) GUISetState() Do $msg = GUIGetMsg() If $msg = $go Then ; create destination path DirCreate($destpath) ; internal FileCopy() function GUICtrlSetData($doing, "FileCopy()...") $timer = TimerInit() ConsoleWrite("FileCopy:" & @CRLF) $ret = FileCopy($src, $destpath, 1) ConsoleWrite("return: " & $ret & @CRLF & "error: " & @error & @CRLF & "time: " & TimerDiff($timer) & " ms" & @CRLF) ConsoleWrite("====================" & @CRLF) ; _LargeFileCopy() UDF function GUICtrlSetData($doing, "_LargeFileCopy()...") $timer = TimerInit() ConsoleWrite("_LargeFileCopy:" & @CRLF) $ret = _LargeFileCopy($src, $destpath, 1) ConsoleWrite("return: " & $ret & @CRLF & "error: " & @error & @CRLF & "time: " & TimerDiff($timer) & " ms" & @CRLF) ConsoleWrite("====================" & @CRLF) GUICtrlSetData($doing, "Ready...") EndIf Until $msg = -3 EndFuncLargeFileCopy.zip1 point -
CPU Multi-Processor Usage This is an example of getting and displaying processor usage for all processors in a system. It uses the 'undocumented' NtQuerySystemInformation function to gather processor usage information and then does calculations based on the delta of two readings. I wrote this as an alternative to using my >Performance Counters UDF - specifically, check out >Example # 4: System CPU Usage (by Processor). There is now a new interface, as well as two ways to track CPU usage. The first method tracks usage for all CPU's, and additionally produces an overall CPU usage result. The second method tracks Overall CPU usage - a combined value representing all cores as one unit. Note that this second method uses GetSystemTimes, which requires Windows XP SP1 or higher. The usage works like this for all CPU's: $aCPUsUsageTracker = _CPUsUsageTracker_Create() $iTotalCPUs = $aCPUsUsageTracker[0][0] ; Call the following repeatedly - $aCPUsUsageTracker will be updated automatically: $aPercents = _CPUsUsageTracker_GetUsage($aCPUsUsageTracker) For Overall CPU usage, either look at $aPercents[$iTotalCPUs] above, or use this interface (reliant on GetSystemTimes): $aCPUOverallTracker = _CPUOverallUsageTracker_Create() ; Call the following repeatedly - $aCPUOverallTracker will be updated automatically: $fUsage = _CPUOverallUsageTracker_GetUsage($aCPUOverallTracker) _ Need to see how CPU usage is affected? A simple tool I use to stress-test individual CPU cores is Stress Prime 2004, which can be run multiple times. P.S. All I ask is that you acknowledge me in some way if you use any of this code. updates: 2013-08-31: - Added a simple Overall and Idle CPU usage example 2013-06-18: - Changed interface for getting CPU usage. Now there's no need to juggle arrays around [obsolete version]: - fixed bound check in _CPUCalculateUsages() to look at 2nd dimension CPU_ProcessorUsage.au3 (prev downloads: ~15) ; ======================================================================================================== ; <CPU_ProcessorUsage.au3> ; ; Example of an alternative means to read individual CPU Usages for multiple CPUs, ; along with the combined overall CPU usage. (Alternative to Performance Counters) ; Readings are shown in a 'Splash' window ; ; Functions: ; _CPUGetTotalProcessorTimes() ; Gets Overall (combined CPUs) Processor Times ; _CPUGetIndividualProcessorTimes() ; Returns an array of CPU usage info for individual processors ; _CPUsUsageTracker_Create() ; Creates a CPU usage tracker for all CPUs ; _CPUsUsageTracker_GetUsage() ; Updates CPU usage tracker and returns a CPU usage array ; _CPUOverallUsageTracker_Create() ; Creates a CPU usage tracker for Overall CPU usage ; _CPUOverallUsageTracker_GetUsage(); Updates CPU usage tracker and returns CPU usage [Overall Usage] ; ; See also: ; Performance Counters UDF ; ; ; Author: Ascend4nt ; ======================================================================================================== ; -------------------- HOTKEY FUNCTION & VARIABLE -------------------- Global $bHotKeyPressed=False Func _EscPressed() $bHotKeyPressed=True EndFunc ; ============================================================================================== ; Func _CPUGetTotalProcessorTimes() ; ; Gets the total (combined CPUs) system processor times (as FILETIME) ; Note that Kernel Mode time includes Idle Mode time, so a proper calculation of usage time is ; Kernel + User - Idle ; And percentage (based on two readings): ; (Kernel_b - Kernel_a) + (User_b - User_a) - (Idle_b - Idle_a) * 100 ; / (Kernel_b - Kernal_a) + (User_b - User_a) ; ; O/S Requirements: min. Windows XP SP1+ ; ; Returns: ; Success: Array of info for total (combined CPU's) processor times: ; [0] = Idle Mode Time ; [1] = Kernel Mode Time -> NOTE This INCLUDES Idle Time ; [2] = User Mode Time ; ; Failure: "" with @error set: ; @error = 2: DLLCall error, @extended = error returned from DLLCall ; @error = 3: API call returned False - call GetLastError for more info ; ; Author: Ascend4nt ; ============================================================================================== Func _CPUGetTotalProcessorTimes() Local $aRet, $stSystemTimes $stSystemTimes = DllStructCreate("int64 IdleTime;int64 KernelTime;int64 UserTime;") $aRet = DllCall("kernel32.dll", "bool", "GetSystemTimes", "ptr", DllStructGetPtr($stSystemTimes, 1), _ "ptr", DllStructGetPtr($stSystemTimes, 2), "ptr", DllStructGetPtr($stSystemTimes, 3) ) If @error Then Return SetError(2, @error, "") If Not $aRet[0] Then Return SetError(3, 0, "") Dim $aRet[3] = [ _ DllStructGetData($stSystemTimes, 1), _ DllStructGetData($stSystemTimes, 2), _ DllStructGetData($stSystemTimes, 3) ] Return $aRet EndFunc ; ============================================================================================== ; Func _CPUGetIndividualProcessorTimes() ; ; Gets an array of system processor times (as FILETIME) ; Note that Kernel Mode time includes Idle Mode time, so a proper calculation of usage time is ; Kernel + User - Idle ; And percentage (based on two readings): ; (Kernel_b - Kernel_a) + (User_b - User_a) - (Idle_b - Idle_a) * 100 ; / (Kernel_b - Kernal_a) + (User_b - User_a) ; ; Returns: ; Success: 2 Dimensional Array of info [@extended = #of CPU's]: ; [0][0] = # of CPUs (and array elements) ; [1..n][0] = Idle Mode Time for CPU # n ; [1..n][1] = Kernel Mode Time for CPU # n -> NOTE This INCLUDES Idle Time ; [1..n][2] = User Mode Time for CPU # n ; ; Failure: "" with @error set: ; @error = 2: DLLCall error, @extended = error returned from DLLCall ; @error = 3: NTSTATUS returned error code, @extended contains error code ; @error = 4: Invalid length returned, @extended is length ; ; Author: Ascend4nt ; ============================================================================================== Func _CPUGetIndividualProcessorTimes() ; DPC = Deferred Procedure Calls Local $tagSYSTEM_PROCESSOR_TIMES = "int64 IdleTime;int64 KernelTime;int64 UserTime;int64 DpcTime;int64 InterruptTime;ulong InterruptCount;" Local $aRet, $stProcessorTimes, $stBuffer Local $i, $nTotalCPUStructs, $pStructPtr ; 256 [maximum CPU's] * 48 (structure size) = 12288 $stBuffer = DllStructCreate("byte Buffer[12288];") ; SystemProcessorTimes = 8 Local $aRet=DllCall("ntdll.dll", "long", "NtQuerySystemInformation", "int", 8, "ptr", DllStructGetPtr($stBuffer), "ulong", 12288, "ulong*", 0) If @error Then Return SetError(2, @error, "") ; NTSTATUS of something OTHER than success? If $aRet[0] Then Return SetError(3, $aRet[0], "") ; Length invalid? If $aRet[4] = 0 Or $aRet[0] > 12288 Or Mod($aRet[4], 48) <> 0 Then Return SetError(4, $aRet[4], "") $nTotalCPUStructs = $aRet[4] / 48 ;~ ConsoleWrite("Returned buffer length = " & $aRet[4] & ", len/48 (struct size) = "& $nTotalCPUStructs & @CRLF) ; We are interested in Idle, Kernel, and User Times (3) Dim $aRet[$nTotalCPUStructs + 1][3] $aRet[0][0] = $nTotalCPUStructs ; Traversal Pointer for individual CPU structs $pStructPtr = DllStructGetPtr($stBuffer) For $i = 1 To $nTotalCPUStructs $stProcessorTimes = DllStructCreate($tagSYSTEM_PROCESSOR_TIMES, $pStructPtr) $aRet[$i][0] = DllStructGetData($stProcessorTimes, "IdleTime") $aRet[$i][1] = DllStructGetData($stProcessorTimes, "KernelTime") $aRet[$i][2] = DllStructGetData($stProcessorTimes, "UserTime") ; Next CPU structure $pStructPtr += 48 Next Return SetExtended($nTotalCPUStructs, $aRet) EndFunc ; ============================================================================================== ; Func _CPUsUsageTracker_Create() ; ; Creates a CPU usage tracker array for all processors. This array should be passed ; to _CPUsUsageTracker_GetUsage() to get current usage information back. ; ; Returns: ; Success: An array used to track CPU usage [@extended = # of CPU's] ; Array 'internal' format: ; $arr[0][0] = # of CPU's ; $arr[1..n][0] = Total CPU Time (Kernel + User Mode) ; $arr[1..n][1] = Total Active CPU Time (Kernel + User - Idle) ; ; Failure: "" with @error set [reflects _CPUGetIndividualProcessorTimes codes]: ; @error = 2: DLLCall error, @extended = error returned from DLLCall ; @error = 3: NTSTATUS returned error code, @extended contains error code ; @error = 4: Invalid length returned, @extended is length ; ; Author: Ascend4nt ; ============================================================================================== Func _CPUsUsageTracker_Create() Local $nTotalCPUs, $aCPUTimes, $aCPUsUsage $aCPUTimes = _CPUGetIndividualProcessorTimes() If @error Then Return SetError(@error, @extended, "") $nTotalCPUs = @extended Dim $aCPUsUsage[$nTotalCPUs + 1][2] $aCPUsUsage[0][0] = $nTotalCPUs For $i = 1 To $nTotalCPUs ; Total $aCPUsUsage[$i][0] = $aCPUTimes[$i][1] + $aCPUTimes[$i][2] ; TotalActive (Kernel Time includes Idle time, so we need to subtract that) $aCPUsUsage[$i][1] = $aCPUTimes[$i][1] + $aCPUTimes[$i][2] - $aCPUTimes[$i][0] Next Return SetExtended($nTotalCPUs, $aCPUsUsage) EndFunc ; ============================================================================================== ; Func _CPUOverallUsageTracker_Create() ; ; Creates a CPU usage tracker array for Overall combined processors usage. ; This array should be passed to _CPUOverallUsageTracker_GetUsage() to get ; current usage information. ; ; Returns: ; Success: An array used to track Overall CPU usage ; Array 'internal' format: ; $arr[0] = Total Overall CPU Time (Kernel + User Mode) ; $arr[1] = Total Active Overall CPU Time (Kernel + User - Idle) ; ; Failure: "" with @error set [reflects _CPUGetTotalProcessorTimes codes]: ; @error = 2: DLLCall error, @extended = error returned from DLLCall ; @error = 3: API call returned False - call GetLastError for more info ; ; Author: Ascend4nt ; ============================================================================================== Func _CPUOverallUsageTracker_Create() Local $aCPUTimes, $aCPUsUsage[2] $aCPUTimes = _CPUGetTotalProcessorTimes() If @error Then Return SetError(@error, @extended, "") ; Total $aCPUsUsage[0] = $aCPUTimes[1] + $aCPUTimes[2] ; TotalActive (Kernel Time includes Idle time, so we need to subtract that) $aCPUsUsage[1] = $aCPUTimes[1] + $aCPUTimes[2] - $aCPUTimes[0] Return $aCPUsUsage EndFunc ; ============================================================================================== ; Func _CPUsUsageTracker_GetUsage(ByRef $aCPUsUsage) ; ; Updates a CPUsUsage array and returns an array of CPU Usage information for all processors. ; ; Returns: ; Success: Array of CPU Usage -> 1 for each processor + 1 for Overall [@extended = # of processors] ; [0..n] = CPU Usage (Percentage) ; [#CPUs] = CPUs Overall Usage (Percentage) ; Failure: "" with @error set to 1 for invalid parameters, or: ; @error = 2: DLLCall error, @extended = error returned from DLLCall ; @error = 3: NTSTATUS returned error code, @extended contains error code ; @error = 4: Invalid length returned, @extended is length ; ; Author: Ascend4nt ; ============================================================================================== Func _CPUsUsageTracker_GetUsage(ByRef $aCPUsUsage) If Not IsArray($aCPUsUsage) Or UBound($aCPUsUsage, 2) < 2 Then Return SetError(1, 0, "") Local $nTotalCPUs, $aUsage, $aCPUsCurInfo Local $nTotalActive, $nTotal Local $nOverallActive, $nOverallTotal $aCPUsCurInfo = _CPUsUsageTracker_Create() If @error Then Return SetError(@error, @extended, "") $nTotalCPUs = $aCPUsCurInfo[0][0] Dim $aUsage[$nTotalCPUs + 1] $nOverallActive = 0 $nOverallTotal = 0 For $i = 1 To $nTotalCPUs $nTotal = $aCPUsCurInfo[$i][0] - $aCPUsUsage[$i][0] $nTotalActive = $aCPUsCurInfo[$i][1] - $aCPUsUsage[$i][1] $aUsage[$i - 1] = Round($nTotalActive * 100 / $nTotal, 1) $nOverallActive += $nTotalActive $nOverallTotal += $nTotal Next $aUsage[$nTotalCPUs] = Round( ($nOverallActive / $nTotalCPUs) * 100 / ($nOverallTotal / $nTotalCPUs), 1) ; Replace current usage tracker info $aCPUsUsage = $aCPUsCurInfo Return SetExtended($nTotalCPUs, $aUsage) EndFunc ; ============================================================================================== ; Func _CPUOverallUsageTracker_GetUsage(ByRef $aCPUsUsage) ; ; Updates a CPUsUsage array and returns CPU Usage information [Overall processor usage] ; ; Returns: ; Success: CPU Usage (Percentage) ; Failure: 0 with @error set to 1 for invalid parameters, or: ; @error = 2: DLLCall error, @extended = error returned from DLLCall ; @error = 3: API call returned False - call GetLastError for more info ; ; Author: Ascend4nt ; ============================================================================================== Func _CPUOverallUsageTracker_GetUsage(ByRef $aCPUsUsage) If Not IsArray($aCPUsUsage) Or UBound($aCPUsUsage) < 2 Then Return SetError(1, 0, "") Local $aCPUsCurInfo, $fUsage, $nTotalActive, $nTotal $aCPUsCurInfo = _CPUOverallUsageTracker_Create() If @error Then Return SetError(@error, @extended, 0) $nTotal = $aCPUsCurInfo[0] - $aCPUsUsage[0] $nTotalActive = $aCPUsCurInfo[1] - $aCPUsUsage[1] ; Replace current usage tracker info $aCPUsUsage = $aCPUsCurInfo Return Round($nTotalActive * 100 / $nTotal, 1) EndFunc ; -------------------- MAIN PROGRAM CODE -------------------- HotKeySet("{Esc}", "_EscPressed") Local $hSplash, $sSplashText ; CPU Usage for all CPU's Local $iTotalCPUs, $aCPUsUsageTracker, $aPercents ; Overall CPU Usage Tracker ; (GetSystemTimes) ;~ Local $aCPUOverallTracker ; CPUs Usage Tracker $aCPUsUsageTracker = _CPUsUsageTracker_Create() If @error Then Exit ConsoleWrite("Error calling _CPUsUsageTracker_Create():" & @error & ", @extended = " & @extended & @CRLF) ; Overall CPU Usage tracker ;~ $aCPUOverallTracker = _CPUOverallUsageTracker_Create() ;~ If @error Then Exit ConsoleWrite("Error calling _CPUOverallUsageTracker_Create():" & @error & ", @extended = " & @extended & @CRLF) $iTotalCPUs = $aCPUsUsageTracker[0][0] ConsoleWrite("Total # CPU's: " & $iTotalCPUs & @CRLF) Sleep(250) $hSplash=SplashTextOn("CPU Usage Information [" & $iTotalCPUs & " total CPU's]", "", _ 240, 20 + ($iTotalCPUs + 1) * 35, Default, Default, 16, Default, 12) ; Start loop Do $aPercents = _CPUsUsageTracker_GetUsage($aCPUsUsageTracker) $sSplashText="" For $i=0 To $iTotalCPUs - 1 $sSplashText &= "CPU #"& $i+1 & ": " & $aPercents[$i] & " %" & @CRLF Next $sSplashText &= @CRLF &"[Overall CPU Usage] :" & $aPercents[$iTotalCPUs] & " %" & @CRLF ; Alternative, if all we wanted was Overall CPU Usage: ;~ $sSplashText &= @CRLF &"[Overall CPU Usage] :" & _CPUOverallUsageTracker_GetUsage($aCPUOverallTracker) & " %" & @CRLF $sSplashText &= @CRLF & "[Esc] exits" ControlSetText($hSplash, "", "[CLASS:Static; INSTANCE:1]", $sSplashText) Sleep(500) Until $bHotKeyPressed _ Overall CPU Usage (and Idle calculation) example: ; ======================================================================================================== ; <CPU_ProcessorUsageOverall.au3> ; ; Example of reading combined overall CPU usage and deducing Idle CPU usage as well ; Readings are shown in a 'Splash' window ; ; Functions: ; _CPUGetTotalProcessorTimes() ; Gets Overall (combined CPUs) Processor Times ; _CPUOverallUsageTracker_Create() ; Creates a CPU usage tracker for Overall CPU usage ; _CPUOverallUsageTracker_GetUsage(); Updates CPU usage tracker and returns CPU usage [Overall Usage] ; ; External Functions: ; _CPUGetIndividualProcessorTimes() ; Returns an array of CPU usage info for individual processors ; _CPUsUsageTracker_Create() ; Creates a CPU usage tracker for all CPUs ; _CPUsUsageTracker_GetUsage() ; Updates CPU usage tracker and returns a CPU usage array ; ; See also: ; <CPU_ProcessorUsage.au3> ; Individual CPU processor usage example ; Performance Counters UDF ; ; ; Author: Ascend4nt ; ======================================================================================================== ; --- UDF's --- ; ============================================================================================== ; Func _CPUGetTotalProcessorTimes() ; ; Gets the total (combined CPUs) system processor times (as FILETIME) ; Note that Kernel Mode time includes Idle Mode time, so a proper calculation of usage time is ; Kernel + User - Idle ; And percentage (based on two readings): ; (Kernel_b - Kernel_a) + (User_b - User_a) - (Idle_b - Idle_a) * 100 ; / (Kernel_b - Kernal_a) + (User_b - User_a) ; ; O/S Requirements: min. Windows XP SP1+ ; ; Returns: ; Success: Array of info for total (combined CPU's) processor times: ; [0] = Idle Mode Time ; [1] = Kernel Mode Time -> NOTE This INCLUDES Idle Time ; [2] = User Mode Time ; ; Failure: "" with @error set: ; @error = 2: DLLCall error, @extended = error returned from DLLCall ; @error = 3: API call returned False - call GetLastError for more info ; ; Author: Ascend4nt ; ============================================================================================== Func _CPUGetTotalProcessorTimes() Local $aRet, $aTimes $aRet = DllCall("kernel32.dll", "bool", "GetSystemTimes", "uint64*", 0, "uint64*", 0, "uint64*", 0) If @error Then Return SetError(2, @error, "") If Not $aRet[0] Then Return SetError(3, 0, "") Dim $aTimes[3] = [ $aRet[1], $aRet[2], $aRet[3] ] Return $aTimes EndFunc ; ============================================================================================== ; Func _CPUOverallUsageTracker_Create() ; ; Creates a CPU usage tracker array for Overall combined processors usage. ; This array should be passed to _CPUOverallUsageTracker_GetUsage() to get ; current usage information. ; ; Returns: ; Success: An array used to track Overall CPU usage ; Array 'internal' format: ; $arr[0] = Total Overall CPU Time (Kernel + User Mode) ; $arr[1] = Total Active Overall CPU Time (Kernel + User - Idle) ; ; Failure: "" with @error set [reflects _CPUGetTotalProcessorTimes codes]: ; @error = 2: DLLCall error, @extended = error returned from DLLCall ; @error = 3: API call returned False - call GetLastError for more info ; ; Author: Ascend4nt ; ============================================================================================== Func _CPUOverallUsageTracker_Create() Local $aCPUTimes, $aCPUsUsage[2] $aCPUTimes = _CPUGetTotalProcessorTimes() If @error Then Return SetError(@error, @extended, "") ; Total $aCPUsUsage[0] = $aCPUTimes[1] + $aCPUTimes[2] ; TotalActive (Kernel Time includes Idle time, so we need to subtract that) $aCPUsUsage[1] = $aCPUTimes[1] + $aCPUTimes[2] - $aCPUTimes[0] Return $aCPUsUsage EndFunc ; ============================================================================================== ; Func _CPUOverallUsageTracker_GetUsage(ByRef $aCPUsUsage) ; ; Updates a CPUsUsage array and returns CPU Usage information [Overall processor usage] ; ; Returns: ; Success: CPU Usage (Percentage) ; Failure: 0 with @error set to 1 for invalid parameters, or: ; @error = 2: DLLCall error, @extended = error returned from DLLCall ; @error = 3: API call returned False - call GetLastError for more info ; ; Author: Ascend4nt ; ============================================================================================== Func _CPUOverallUsageTracker_GetUsage(ByRef $aCPUsUsage) If Not IsArray($aCPUsUsage) Or UBound($aCPUsUsage) < 2 Then Return SetError(1, 0, "") Local $aCPUsCurInfo, $fUsage, $nTotalActive, $nTotal $aCPUsCurInfo = _CPUOverallUsageTracker_Create() If @error Then Return SetError(@error, @extended, 0) $nTotal = $aCPUsCurInfo[0] - $aCPUsUsage[0] $nTotalActive = $aCPUsCurInfo[1] - $aCPUsUsage[1] ; Replace current usage tracker info $aCPUsUsage = $aCPUsCurInfo Return Round($nTotalActive * 100 / $nTotal, 1) EndFunc ; -------------------- HOTKEY FUNCTION & VARIABLE -------------------- Global $bHotKeyPressed=False Func _EscPressed() $bHotKeyPressed=True EndFunc ; -------------------- MAIN PROGRAM CODE -------------------- HotKeySet("{Esc}", "_EscPressed") Local $hSplash, $sSplashText ; Overall CPU Usage Tracker ; (GetSystemTimes) Local $aCPUOverallTracker, $fPercent ; Overall CPU Usage tracker $aCPUOverallTracker = _CPUOverallUsageTracker_Create() If @error Then Exit ConsoleWrite("Error calling _CPUOverallUsageTracker_Create():" & @error & ", @extended = " & @extended & @CRLF) Sleep(250) $hSplash=SplashTextOn("CPU [Overall] Usage Information", "", _ 240, 100, Default, Default, 16, Default, 12) ; Start loop Do $fPercent = _CPUOverallUsageTracker_GetUsage($aCPUOverallTracker) $sSplashText="" $sSplashText &= "[Overall CPU Usage] :" & $fPercent & " %" & @CRLF $sSplashText &= "[Idle] : " & (100 - $fPercent) & " %" & @CRLF $sSplashText &= @CRLF & "[Esc] exits" ControlSetText($hSplash, "", "[CLASS:Static; INSTANCE:1]", $sSplashText) Sleep(500) Until $bHotKeyPressed CPU_ProcessorUsageOverall.au31 point
-
batch file to AutoIT
lexicon reacted to JLogan3o13 for a topic
Try this: Runwait(@ComSpec & ' /k SetACL.exe -on "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg" -ot reg -actn ace -ace "n:users;p:full"')1 point -
I wrote an arraybinarysearch that works with 2D arrays, it's basically just the normal _ABS with the option to search on a specific "column" of the array. Much like how ArraySearch works, but binary.1 point
-
Multiple if thens changing how the script runs... simultaneously
DatMCEyeBall reacted to Melba23 for a topic
Jekuto, Insulting Moderators who ask you not to bump is one thing - insulting them a second time in the same thread is just not on. You are banned for a week - use this time to consider how you will behave when and if you return, because continuing as you are will result in your permanent removal from the community. M23 P.S. And do learn to use paragraphs - the "block of text" approach makes it difficult to fully appreciate the stupidity of the content.1 point -
Deleting Multi Directories with wildcard?
guinness reacted to goodmanjl531 for a topic
I just saw this and i was hoping to see what was your solution for this I need to delete folders and everything inside them that all have C:WindowsTempslu*.tmp any ideas? Thanks!!1 point -
Jekuto, We do not work like that here - we help you get your scripts running correctly. Think of the old saying: "Give a man a fish, you feed him for a day; give a man a net and you feed him forever". We try to be net makers and repairers, not fishmongers. M231 point
-
garbb, This code still flickers a bit, but a lot less than your original on my machine. I have also changed the code to limit the text rewriting as much as possible: #include <GUIConstantsEx.au3> #include <GuiEdit.au3> #include <WindowsConstants.au3> #include <date.au3> #include <array.au3> #include <GuiListBox.au3> #include <ScrollBarsConstants.au3> Opt("GUIOnEventMode", 1) Opt("GUIResizeMode", $GUI_DOCKAUTO) $gui_width = 1085 $gui_height = 483 $logcharlimit = 15000 ; Max size of edit $logcharbuffer = 500 ; Buffer to hold 2 x longest expected line $Form1 = GUICreate("TEST", $gui_width, $gui_height, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_TABSTOP)) $aiwe = GUICtrlCreateEdit("", 0, 0, $gui_width, $gui_height, BitOR($GUI_SS_DEFAULT_EDIT, $ES_READONLY)) _GUICtrlEdit_SetLimitText($aiwe, $logcharlimit) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM) GUISetState(@SW_SHOW) GUISetOnEvent($GUI_EVENT_CLOSE, "closebuttonfunc") Func closebuttonfunc() Exit EndFunc ;==>closebuttonfunc While 1 Sleep(100) logout('TEST OF A LONG LINE TEST OF A LONG LINE TEST OF A LONG LINE TEST OF A LONG LINE TEST OF A LONG LINE TEST OF A LONG LINE TEST OF A LONG LINE TEST OF A LONG LINE TEST OF A LONG LINE TEST OF A LONG LINE TEST OF A LONG LINE TEST OF A LONG LINE ') WEnd Func logout($msg) $systime = _Date_Time_GetSystemTime() $systime = _Date_Time_SystemTimeToTzSpecificLocalTime(DllStructGetPtr($systime)) $darray = _Date_Time_SystemTimeToArray($systime) $datetime = StringFormat("%04d/%02d/%02d %02d:%02d:%02d.%03d", $darray[2], $darray[0], $darray[1], $darray[3], $darray[4], $darray[5], $darray[6]) _GUICtrlEdit_BeginUpdate($aiwe) ; Get line count $iLines_Count = _GUICtrlEdit_GetLineCount($aiwe) ; Check position of first char of last line is not inside buffer If _GUICtrlEdit_LineIndex($aiwe, $iLines_Count - 1) > $logcharlimit - $logcharbuffer Then ; Move down lines until we get to a value greater then the buffer For $i = 1 To $iLines_Count - 1 $iCurrLine_Index = _GUICtrlEdit_LineIndex($aiwe, $i) If $iCurrLine_Index > $logcharbuffer Then ; Select and delete lines to that point _GUICtrlEdit_SetSel($aiwe, 0, $iCurrLine_Index - 1) _GUICtrlEdit_ReplaceSel($aiwe, "", False) ; No point in looking further ExitLoop EndIf Next EndIf ; Text is now smaller by at least twice the buffer size so add new text _GUICtrlEdit_AppendText($aiwe, $datetime & " " & $msg & @CRLF) _GUICtrlEdit_EndUpdate($aiwe) ; Select the last character and scroll it into view _GUICtrlEdit_SetSel($aiwe, -1, -1) _GUICtrlEdit_Scroll($aiwe, $SB_SCROLLCARET) EndFunc ;==>logout As all code instructions need to be interpreted, updating every 100 ms without any flickering is asking a lot of any AutoIt GUI - especially when the majority of the GUI is text that needs to be redrawn! M231 point
-
Yes, compile for x86 only and go away with that.1 point
-
Cubex
FlashpointBlack reacted to Melba23 for a topic
And the unimaginatively named CubexSoftware is automatically banned as well. When we say "permanently banned" we mean it. M231 point -
Update the Excel UDF that comes with AutoIt
FlashpointBlack reacted to water for a topic
I have modified _Excel_RangeWrite for the next Beta like this: Func _Excel_RangeWrite($oWorkbook, $vWorksheet, $vValue, $vRange = Default, $bValue = Default, $bForceFunc = Default) If Not IsObj($oWorkbook) Or ObjName($oWorkbook, 1) <> "_Workbook" Then Return SetError(1, 0, 0) If Not IsObj($vWorksheet) Then If $vWorksheet = Default Then $vWorksheet = $oWorkbook.ActiveSheet Else $vWorksheet = $oWorkbook.WorkSheets.Item($vWorksheet) EndIf If @error Or Not IsObj($vWorksheet) Then Return SetError(2, @error, 0) ElseIf ObjName($vWorksheet, 1) <> "_Worksheet" Then Return SetError(2, @error, 0) EndIf If $vRange = Default Then $vRange = "A1" If $bValue = Default Then $bValue = True If $bForceFunc = Default Then $bForceFunc = False If Not IsObj($vRange) Then $vRange = $vWorksheet.Range($vRange) If @error Or Not IsObj($vRange) Then Return SetError(3, @error, 0) EndIf If Not IsArray($vValue) Then If $bValue Then $vRange.Value = $vValue Else $vRange.Formula = $vValue EndIf If @error Then Return SetError(4, @error, 0) Else If $vRange.Columns.Count = 1 And $vRange.Rows.Count = 1 Then If UBound($vValue, 0) = 1 Then $vRange = $vRange.Resize(UBound($vValue, 1), 1) Else $vRange = $vRange.Resize(UBound($vValue, 1), UBound($vValue, 2)) EndIf EndIf ; ========================== ; Transpose has an undocument limit on the number of cells or rows it can transpose. This limit increases with the Excel version ; Limits: ; Excel 97 - 5461 cells ; Excel 2000 - 5461 cells ; Excel 2003 - ? ; Excel 2007 - 65536 rows ? ; Excel 2010 - ? ; Example: If $oExcel.Version = 14 And $vRange.Columns.Count * $vRange.Rows.Count > 1000000 Then $bForceFunc = True If $bForceFunc Then If UBound($vValue, 0) = 1 Then ; _ArrayTranspose only works for 2D arrays so we do it ourselfs for 1D arrays Local $aTemp[1][UBound($vValue, 1)] For $z = 0 To UBound($vValue, 1) - 1 $aTemp[0][$z] = $vValue[$z] Next $vValue = $aTemp Else _ArrayTranspose($vValue) EndIf If $bValue Then $vRange.Value = $vValue Else $vRange.Formula = $vValue EndIf If @error Then Return SetError(4, @error, 0) Else Local $oExcel = $oWorkbook.Parent If $bValue Then $vRange.Value = $oExcel.Transpose($vValue) Else $vRange.Formula = $oExcel.Transpose($vValue) EndIf If @error Then Return SetError(4, @error, 0) EndIf EndIf Return $vRange EndFunc ;==>_Excel_RangeWrite Does this work for you?1 point -
autoit 3.3.10.0 is HUGE
FlashpointBlack reacted to jchd for a topic
I also carry something that gets bigger and bigger and no woman complains about it (yet). Seriously, Win 7 is significantly bigger than Win 3.11 as well.1 point -
I wrote a helper function to get specific element in nested array/object returned from Jsmn_Decode() more easily. Here is the code and example: #Include "JSMN.au3" Local $Json = '{"key1" : "value1", "key2" : [true, ["a", "b"], {"key3", "obj_in_array"}]}' Local $Obj = Jsmn_Decode($Json) Jsmn_Get_ShowResult($Obj, '["key1"]') Jsmn_Get_ShowResult($Obj, '["key2"][0]') Jsmn_Get_ShowResult($Obj, '["key2"][1][0]') Jsmn_Get_ShowResult($Obj, '["key2"][2]["key3"]') Local $Json = '{"strange key []" : "uses \\uXXXX for unsupported char in the key", "key_nospace_1" : {"key_nospace_2" : "don''t need \" if the key has no space"} }' Local $Obj = Jsmn_Decode($Json) Jsmn_Get_ShowResult($Obj, '["strange key [\u005D"]') Jsmn_Get_ShowResult($Obj, '[key_nospace_1][key_nospace_2]') Jsmn_Get_ShowResult($Obj, '[error1]') Jsmn_Get_ShowResult($Obj, '[error2') Func Jsmn_Get_ShowResult($Var, $Key) Local $Ret = Jsmn_Get($Var, $Key) If @Error Then Switch @error Case 1 ConsoleWrite("Error 1: key not exists" & @LF) Case 2 ConsoleWrite("Error 2: syntax error" & @LF) EndSwitch Else ConsoleWrite($Key & " => " & VarGetType($Ret) & ": " & $Ret & @LF) EndIf EndFunc Func Jsmn_Get($Var, $Key) If Not $Key Then Return $Var Local $Match = StringRegExp($Key, "(^\[([^\]]+)\])", 3) If IsArray($Match) Then Local $Index = Jsmn_Decode($Match[1]) $Key = StringTrimLeft($Key, StringLen($Match[0])) If IsString($Index) And Jsmn_IsObject($Var) And Jsmn_ObjExists($Var, $Index) Then Local $Ret = Jsmn_Get(Jsmn_ObjGet($Var, $Index), $Key) Return SetError(@Error, 0, $Ret) ElseIf IsNumber($Index) And IsArray($Var) And $Index >= 0 And $Index < UBound($Var) Then Local $Ret = Jsmn_Get($Var[$Index], $Key) Return SetError(@Error, 0, $Ret) Else Return SetError(1, 0, "") EndIf EndIf Return SetError(2, 0, "") EndFunc1 point
-
Count number of folders
arthalita01 reacted to Rick for a topic
Another way.............. change it as you wish.. $Path = @DeskTopdir $search = FileFindFirstFile( $Path & "\*.*") $Total=0 While 1 $file = FileFindNextFile($search) If @error Then ExitLoop if Stringinstr(FileGetAttrib($Path & "\" & $file),"D") then MsgBox(0,"",$file) $Total=$Total + 1 endif WEnd FileClose($search) MsgBox(0,"","Total folders in " & $Path & " : " & $Total)1 point