Leaderboard
Popular Content
Showing content with the highest reputation on 05/02/2020 in all areas
-
Sure ... banned permanently! 🤐 Jos3 points
-
After seeing a number of threads talking about how to exchange efficiently messages between processes (Inter Process Communication), I decided to create a framework using Windows Messages WM_COPYDATA. What is new with this UDF you ask ? Well it will depends how familiar you are with IPC. One thing is sure, the simplicity of use and the fabulous speed are amazing. This is based on a Clients-Server approach. You can have an unlimited number of clients talking with a single server. You will have to define the protocol of communication between them, but the code you have to create is incredibly low. The UDF proposes 2 simple message properties of communication. The first (called data) is based on a number. You can decide what value 1,2,3, etc. means between your client and server. Server will react upon the value of the data field. Second, there is a string field where you can inscribe additional information on request, and where the server will respond to client request (if necessary). Here are the functions that I have wrapped around this : Func _WCD_CreateServer Func _WCD_CreateClient Func _WCD_GetServerHandle Func _WCD_IsServerAvailable Func _WCD_Send Func _WCD_WM_COPYDATA_CLIENT_HANDLER Func _WCD_Client_GetResponse Func _WCD_WM_COPYDATA_SERVER_HANDLER Func _WCD_Server_PeekRequest Func _WCD_Server_GetRequest Func _WCD_Server_IsRequestAvail Here an example of the server : #include <Constants.au3> #include <GUIConstants.au3> #include "WCD_IPC.au3" Opt ("MustDeclareVars", 1) $_WCD_Verbose = False ; make it True if you want to follow the convos. False is by default. Local $hServer = _WCD_CreateServer () Local $aReq, $iData While True If _WCD_Server_IsRequestAvail () Then $aReq = _WCD_Server_GetRequest () $iData = @extended Switch $iData Case 1 ; who are you _WCD_Send($hServer, $aReq[0], $iData, @ComputerName) Case 2 Switch Number($aReq[1]) Case 1 _WCD_Send($hServer, $aReq[0], $iData, @IPAddress1) Case 2 _WCD_Send($hServer, $aReq[0], $iData, @IPAddress2) Case 3 _WCD_Send($hServer, $aReq[0], $iData, @IPAddress3) Case 4 _WCD_Send($hServer, $aReq[0], $iData, @IPAddress4) Case Else _WCD_Send($hServer, $aReq[0], $iData, "Invalid parameter") EndSwitch EndSwitch EndIf Sleep (100) WEnd And the client : #include <Constants.au3> #include <GUIConstants.au3> #include "WCD_IPC.au3" Opt ("MustDeclareVars", 1) $_WCD_Verbose = True ; as for the server, you can decide to make client verbose or not Global $hWnd = _WCD_CreateClient ("Test WCD Client") Global $hWndServer = _WCD_GetServerHandle () _WCD_Send($hWnd, $hWndServer, 1) ; simple request - who are you ? Local $sString = WaitForResponse () ConsoleWrite ($sString & @CRLF) _WCD_Send($hWnd, $hWndServer, 2, "5") ; adding text to a more complex request $sString = WaitForResponse () ConsoleWrite ($sString & @CRLF) Func WaitForResponse () Local $sResp While _WCD_IsServerAvailable () $sResp = _WCD_Client_GetResponse () If $sResp <> "" Then Return $sResp Sleep (100) WEnd EndFunc As always, let me know if you got issues, comments, suggestions. I will be glad to answer. Version 2020-06-27 * Allows processes with different levels of privilege to communicate with each other WCD_IPC.au32 points
-
Script becomes way slower after a msgbox - (Moved)
argumentum and one other reacted to Jon for a topic
Was getting confused reading these it seems that there are two things going on here. A slowdown in general with Win10 and PeekMessage. And another that is nothing to do with Win10 and just a general slowdown with OnEventModes? I just had a look at the GuiOnEvent code and there is the allocation of a string structure each call which when I remove it seems to completely remove the delay so I'll look at fixing that.2 points -
Version v3.5
11,600 downloads
ImageSearch UDF v3.5 - AutoIt Wrapper for ImageSearchDLL Advanced image search library for AutoIt with cache system and SIMD optimization. Overview ImageSearchDLL UDF is a high-performance image search library for AutoIt that enables you to find images on screen or within other images. Built with C++14 and optimized with SIMD instructions (AVX512/AVX2/SSE2), it provides fast and accurate image matching capabilities. Features High Performance: SIMD optimization (AVX512/AVX2/SSE2) for fast searching Multi-Monitor Support: Full support for multi-monitor setups with negative coordinates DPI Awareness: Thread-local DPI awareness without affecting AutoIt GUI Cache System: Persistent cache for 30-50% speed boost on repeated searches Image Scaling: Search for images at different scales (0.1x to 5.0x) Screen Capture: Direct screen capture with DPI-aware coordinates Mouse Automation: Precise mouse movement and clicking with multi-monitor support Requirements AutoIt: Version 3.3.16.1 or higher Windows: XP SP3 to Windows 11 Architecture: x86 or x64 (automatic detection) DLL: ImageSearchDLL v3.5 (included) Installation Download the UDF package Place ImageSearchDLL_UDF.au3 in your script directory Ensure the appropriate DLL is in the same directory: ImageSearchDLL_x64.dll for 64-bit AutoIt ImageSearchDLL_x86.dll for 32-bit AutoIt Not required in embedded version! (But need to install Visual C++ Redistributable 2015-2022) Include the UDF in your script: #include "ImageSearchDLL_UDF.au3" Quick Start Basic Image Search #include "ImageSearchDLL_UDF.au3" ; Search for a button on screen Local $aResult = _ImageSearch("button.png") If $aResult[0] > 0 Then ConsoleWrite("Found at: " & $aResult[1][0] & ", " & $aResult[1][1] & @CRLF) MouseClick("left", $aResult[1][0], $aResult[1][1]) Else ConsoleWrite("Image not found" & @CRLF) EndIf Wait for Image and Click ; Wait up to 5 seconds for button to appear, then click it If _ImageSearch_WaitClick(5000, "button.png") Then MsgBox(0, "Success", "Button clicked!") Else MsgBox(0, "Failed", "Button not found within 5 seconds") EndIf Screen Capture ; Capture a region and save as PNG _ImageSearch_ScreenCapture_SaveImage(@ScriptDir & "\screenshot.png", 100, 100, 600, 400) ; Capture full screen _ImageSearch_ScreenCapture_SaveImage(@ScriptDir & "\fullscreen.png") API Reference Startup & Configuration _ImageSearch_Startup() Initializes the ImageSearch library by loading the appropriate DLL. Returns: Success: 1 (DLL loaded successfully) Failure: 0 and sets @error Remarks: Must be called before using any search functions Automatically called on script start DLL v3.5+ uses thread-local DPI awareness and won't affect AutoIt GUI _ImageSearch_Shutdown() Closes the DLL and cleans up resources. _ImageSearch_SetDllPath($sPath) Sets a custom DLL path (must be called before _ImageSearch_Startup). Parameters: $sPath - Full path to the DLL file Returns: Success: 1 Failure: 0 (file not found) Core Search Functions _ImageSearch($sImagePath [, $iLeft, $iTop, $iRight, $iBottom [, $iScreen [, $iTolerance [, $iResults [, $iCenterPOS [, $fMinScale [, $fMaxScale [, $fScaleStep [, $iReturnDebug [, $iUseCache]]]]]]]]) Searches for an image within a specified screen area. Parameters: $sImagePath - Image file path(s), multiple separated by "|" $iLeft, $iTop, $iRight, $iBottom - Search region (0 = entire screen) $iScreen - Monitor index (-1 = virtual screen, 0 = primary, 1+ = specific monitor) $iTolerance - Color tolerance 0-255 (default: 10) $iResults - Max results 1-1024 (default: 1) $iCenterPOS - Return center (1) or top-left (0) coordinates (default: 1) $fMinScale, $fMaxScale - Scale range 0.1-5.0 (default: 1.0) $fScaleStep - Scale step (default: 0.1) $iReturnDebug - Debug mode (default: 0) $iUseCache - Enable cache (default: 1) Returns: Success: Array of found positions [count][X, Y, Width, Height] Failure: Empty array with @error set Example: ; Search for multiple images with scaling Local $aResult = _ImageSearch("icon1.png|icon2.png", 0, 0, 800, 600, -1, 10, 5, 1, 0.8, 1.2, 0.1) If $aResult[0] > 0 Then For $i = 1 To $aResult[0] ConsoleWrite("Match " & $i & " at: " & $aResult[$i][0] & ", " & $aResult[$i][1] & @CRLF) Next EndIf _ImageSearch_InImage($sSourceImage, $sTargetImage [, $iTolerance [, $iResults [, $iCenterPOS [, $fMinScale [, $fMaxScale [, $fScaleStep [, $iReturnDebug [, $iUseCache]]]]]]]]) Searches for a target image within a source image (file-to-file search). Parameters: $sSourceImage - Path to source image file $sTargetImage - Path to target image file(s), multiple separated by "|" Other parameters same as _ImageSearch Returns: Same as _ImageSearch Remarks: Useful for pre-processing images or testing without screen capture Example: $aResult = _ImageSearch_InImage("screenshot.png", "button.png", 20) _ImageSearch_hBitmap($hBitmapSource, $hBitmapTarget [, $iTolerance [, $iLeft [, $iTop [, $iRight [, $iBottom [, $iResults [, $iCenterPOS [, $fMinScale [, $fMaxScale [, $fScaleStep [, $iReturnDebug [, $iUseCache]]]]]]]]]]]]) Searches for a target bitmap within a source bitmap (memory-to-memory search). Parameters: $hBitmapSource - Handle to source bitmap (HBITMAP) $hBitmapTarget - Handle to target bitmap (HBITMAP) Other parameters same as _ImageSearch Returns: Same as _ImageSearch Remarks: Fastest method for repeated searches (no disk I/O) Bitmaps must be created with GDI/GDI+ functions Screen Capture Functions _ImageSearch_CaptureScreen([$iLeft, $iTop, $iRight, $iBottom [, $iScreen]]) Capture screen region and return as HBITMAP handle. Parameters: $iLeft, $iTop, $iRight, $iBottom - Capture region (default: 0 = full screen) $iScreen - Monitor index (default: -1 = virtual screen) Returns: Success: HBITMAP handle (must DeleteObject when done) Failure: 0 and sets @error Example: $hBitmap = _ImageSearch_CaptureScreen(0, 0, 800, 600) ; ... use $hBitmap ... _WinAPI_DeleteObject($hBitmap) _ImageSearch_ScreenCapture_SaveImage($sImageFile [, $iLeft [, $iTop [, $iRight [, $iBottom [, $iScreen]]]]]) Captures a screen region and saves it directly to an image file in one call. Parameters: $sImageFile - Output file path (extension determines format: .bmp, .png, .jpg/.jpeg) $iLeft, $iTop, $iRight, $iBottom - Capture region (default: 0 = full screen) $iScreen - Monitor index (default: 0 = primary screen) Returns: Success: True (1) Failure: False (0) and sets @error Remarks: Automatically detects format from file extension ~2x faster than separate capture + save operations JPEG quality is fixed at 100% (highest quality) Uses DPI-aware capture (accurate on all DPI scales) Example: ; Capture full primary screen to PNG _ImageSearch_ScreenCapture_SaveImage(@ScriptDir & "\screenshot.png") ; Capture region on monitor 2 to JPEG _ImageSearch_ScreenCapture_SaveImage(@ScriptDir & "\region.jpg", 100, 100, 600, 400, 2) _ImageSearch_hBitmapLoad($sImageFile [, $iAlpha [, $iRed [, $iGreen [, $iBlue]]]]) Load image file and convert to HBITMAP handle. Parameters: $sImageFile - Path to image file $iAlpha, $iRed, $iGreen, $iBlue - Background color components 0-255 (default: 0 = transparent) Returns: Success: HBITMAP handle (must DeleteObject when done) Failure: 0 and sets @error Example: $hBitmap = _ImageSearch_hBitmapLoad("image.png", 255, 255, 255, 255) ; White background ; ... use $hBitmap ... _WinAPI_DeleteObject($hBitmap) Mouse Functions _ImageSearch_MouseMove($iX, $iY [, $iSpeed [, $iScreen]]) Moves mouse cursor to coordinates (supports negative coordinates on multi-monitor). Parameters: $iX, $iY - Target coordinates (-1 = keep current position) $iSpeed - Speed 0-100 (0=instant, default: 0) $iScreen - Monitor index (default: -1 = virtual screen) Returns: 1 on success, 0 on failure _ImageSearch_MouseClick([$sButton [, $iX [, $iY [, $iClicks [, $iSpeed [, $iScreen]]]]]]) Clicks mouse at coordinates (screen or current position). Parameters: $sButton - Button: "left", "right", "middle" (default: "left") $iX, $iY - Coordinates (-1 = current position) $iClicks - Number of clicks (default: 1) $iSpeed - Speed 0-100 (0=instant, default: 0) $iScreen - Monitor index (default: -1 = virtual screen) Returns: 1 on success, 0 on failure _ImageSearch_MouseClickWin($sTitle, $sText, $iX, $iY [, $sButton [, $iClicks [, $iSpeed]]]) Clicks mouse in a window. Parameters: $sTitle - Window title/class/handle $sText - Window text $iX, $iY - Relative coordinates in window $sButton - Button (default: "left") $iClicks - Number of clicks (default: 1) $iSpeed - Speed 0-100 (default: 0) Returns: 1 on success, 0 on failure Wait & Click Functions _ImageSearch_Wait($iTimeout, $sImagePath [, $iLeft [, $iTop [, $iRight [, $iBottom [, $iScreen [, $iTolerance [, $iResults [, $iCenterPOS [, $fMinScale [, $fMaxScale [, $fScaleStep [, $iReturnDebug [, $iUseCache [, $iMaxAttempts]]]]]]]]]]]]]) Waits for an image to appear on screen with timeout and optional max attempts limit. Parameters: $iTimeout - Timeout in milliseconds (0 = wait forever) $sImagePath - Image file path(s), multiple separated by "|" $iMaxAttempts - Max number of search attempts (0 = unlimited, default: 0) Other parameters same as _ImageSearch Returns: Success: 2D Array (same as _ImageSearch) Timeout: Empty array with [0][0] = 0 Example: ; Wait 5 seconds for button (unlimited attempts) $aResult = _ImageSearch_Wait(5000, "button.png") If $aResult[0] > 0 Then MouseClick("left", $aResult[1][0], $aResult[1][1]) Else MsgBox(0, "Timeout", "Button not found") EndIf _ImageSearch_WaitClick($iTimeout, $sImagePath [, $sButton [, $iClicks [, $iLeft [, $iTop [, $iRight [, $iBottom [, $iScreen [, $iTolerance [, $iResults [, $iCenterPOS [, $fMinScale [, $fMaxScale [, $fScaleStep [, $iReturnDebug [, $iUseCache]]]]]]]]]]]]]) Waits for an image and clicks it when found. Parameters: $iTimeout - Timeout in milliseconds (0 = wait forever) $sImagePath - Image file path(s) $sButton - Mouse button: "left", "right", "middle" (default: "left") $iClicks - Number of clicks (default: 1) Other parameters same as _ImageSearch Returns: Success: 1 (image found and clicked) Timeout: 0 (image not found) Monitor Functions _ImageSearch_Monitor_GetList() Gets a list of all connected display monitors and their properties. Returns: Success: The number of monitors found. @extended contains a detailed log. Failure: 0 and sets @error Remarks: Populates the global $g_aMonitorList Called automatically by _ImageSearch_Startup _ImageSearch_Monitor_ToVirtual($iMonitor, $iX, $iY) Converts local monitor coordinates to virtual screen coordinates. Parameters: $iMonitor - The 1-based index of the monitor $iX, $iY - Coordinates relative to the monitor's top-left corner Returns: Success: A 2-element array [$vX, $vY] containing virtual screen coordinates Failure: 0 and sets @error _ImageSearch_Monitor_FromVirtual($iMonitor, $iX, $iY) Converts virtual screen coordinates to local monitor coordinates. Parameters: $iMonitor - The 1-based index of the monitor $iX, $iY - Virtual screen coordinates Returns: Success: A 2-element array [$lX, $lY] containing local monitor coordinates Failure: 0 and sets @error _ImageSearch_Monitor_Current() Detects which monitor contains the current mouse cursor position. Returns: Success: Monitor index (1-based) where the cursor is located Failure: 0 and sets @error _ImageSearch_Monitor_GetAtPosition([$iX [, $iY]]) Returns detailed information string about the monitor at specified position. Parameters: $iX, $iY - Coordinates (default: -1 = use mouse cursor position) Returns: Success: String describing the monitor (e.g., "Monitor 2: 1920x1080 (Primary)") Failure: Error message string Window Coordinate Functions _ImageSearch_Window_ToScreen($hWnd, $iX, $iY [, $bClientArea]) Converts window-relative coordinates to screen (virtual desktop) coordinates. Parameters: $hWnd - Window handle or title $iX, $iY - Coordinates relative to window $bClientArea - True = relative to client area, False = relative to window (default: True) Returns: Success: A 2-element array [$screenX, $screenY] containing screen coordinates Failure: 0 and sets @error _ImageSearch_Window_FromScreen($hWnd, $iScreenX, $iScreenY [, $bClientArea]) Converts screen (virtual desktop) coordinates to window-relative coordinates. Parameters: $hWnd - Window handle or title $iScreenX, $iScreenY - Screen coordinates $bClientArea - True = relative to client area, False = relative to window (default: True) Returns: Success: A 2-element array [$winX, $winY] containing window-relative coordinates Failure: 0 and sets @error Cache & Info Functions _ImageSearch_WarmUpCache($sImagePaths [, $bEnableCache]) Pre-loads images into cache for faster subsequent searches. Parameters: $sImagePaths - Pipe-separated list of images to preload $bEnableCache - Enable persistent cache (default: True) Returns: Success: Number of images cached Failure: 0 Example: _ImageSearch_WarmUpCache("btn1.png|btn2.png|icon.png") _ImageSearch_ClearCache() Clears the internal bitmap and location cache. Remarks: Useful for freeing memory or forcing re-scan after image updates Clears both in-memory cache and persistent disk cache _ImageSearch_GetDllInfo([$bForceRefresh]) Gets comprehensive DLL information in INI format. Parameters: $bForceRefresh - Force refresh of cached info (default: True) Returns: Multi-line string in INI format with sections: [DLL] - DLL name, version, architecture, author [OS] - OS name, version, build, platform [CPU] - Threads, SSE2, AVX2, AVX512 support [SCREEN] - Virtual screen, scale, monitors with individual resolutions [CACHE] - Location cache, bitmap cache, pool size _ImageSearch_GetInfo() Gets formatted DLL and system information for display. Returns: Formatted string with DLL info, cache status, and screen information _ImageSearch_GetDllValue($sSection, $sKey) Quick accessor to read any value from cached DLL Info. Parameters: $sSection - Section name (DLL, OS, CPU, SCREEN, CACHE) $sKey - Key name Returns: Value string or "" if not found Example: $sVersion = _ImageSearch_GetDllValue("DLL", "Version") $sOSName = _ImageSearch_GetDllValue("OS", "Name") $iThreads = _ImageSearch_GetDllValue("CPU", "Threads") _ImageSearch_GetLastResult() Gets the raw DLL return string from the last search. Returns: Raw result string (e.g., "{2}[100|200|32|32,150|250|32|32]") Remarks: Useful for debugging or custom parsing _ImageSearch_GetScale([$iScreen]) Gets the DPI scale factor for a specific monitor as a decimal number. Parameters: $iScreen - Monitor index (0 = Primary, 1+ = specific monitor number) Returns: Scale factor as number (e.g., 1.0, 1.25, 1.5) or 0 if not found Example: $fScale = _ImageSearch_GetScale(0) ; Get primary monitor scale (e.g., 1.25) $fScale = _ImageSearch_GetScale(2) ; Get monitor 2 scale Examples Advanced Search with Multiple Images and Scaling #include "ImageSearchDLL_UDF.au3" ; Search for multiple UI elements with different scales Local $sImages = "button_ok.png|button_cancel.png|icon_settings.png" Local $aResult = _ImageSearch($sImages, 0, 0, 1920, 1080, -1, 15, 10, 1, 0.8, 1.3, 0.1, 0, 1) If $aResult[0] > 0 Then ConsoleWrite("Found " & $aResult[0] & " matches:" & @CRLF) For $i = 1 To $aResult[0] ConsoleWrite(" Match " & $i & ": X=" & $aResult[$i][0] & ", Y=" & $aResult[$i][1] & ", W=" & $aResult[$i][2] & ", H=" & $aResult[$i][3] & @CRLF) Next Else ConsoleWrite("No matches found" & @CRLF) EndIf Multi-Monitor Screen Capture #include "ImageSearchDLL_UDF.au3" ; Get monitor information _ImageSearch_Monitor_GetList() ConsoleWrite("Detected " & $g_aMonitorList[0][0] & " monitors" & @CRLF) ; Capture each monitor separately For $i = 1 To $g_aMonitorList[0][0] Local $sFile = @ScriptDir & "\monitor_" & $i & ".png" _ImageSearch_ScreenCapture_SaveImage($sFile, 0, 0, 0, 0, $i) ConsoleWrite("Captured monitor " & $i & " to: " & $sFile & @CRLF) Next ; Capture entire virtual desktop _ImageSearch_ScreenCapture_SaveImage(@ScriptDir & "\virtual_desktop.png", 0, 0, 0, 0, -1) Automated UI Testing #include "ImageSearchDLL_UDF.au3" ; Pre-load images for better performance _ImageSearch_WarmUpCache("login_button.png|username_field.png|password_field.png") ; Wait for login screen and interact If _ImageSearch_WaitClick(10000, "login_button.png") Then ConsoleWrite("Login button clicked" & @CRLF) ; Find username field and click Local $aUsername = _ImageSearch_Wait(5000, "username_field.png") If $aUsername[0] > 0 Then MouseClick("left", $aUsername[1][0], $aUsername[1][1]) Send("myusername") ; Find password field and click Local $aPassword = _ImageSearch_Wait(5000, "password_field.png") If $aPassword[0] > 0 Then MouseClick("left", $aPassword[1][0], $aPassword[1][1]) Send("mypassword") Send("{ENTER}") EndIf EndIf Else MsgBox(0, "Error", "Login screen not found within 10 seconds") EndIf Error Codes Code Constant Description -1 $IMGSE_INVALID_PATH Invalid file path -2 $IMGSE_FAILED_TO_LOAD_IMAGE Failed to load image -3 $IMGSE_FAILED_TO_GET_SCREEN_DC Failed to get screen device context -4 $IMGSE_INVALID_SEARCH_REGION Invalid search region -5 $IMGSE_INVALID_PARAMETERS Invalid parameters -6 $IMGSE_INVALID_SOURCE_BITMAP Invalid source bitmap -7 $IMGSE_INVALID_TARGET_BITMAP Invalid target bitmap -9 $IMGSE_RESULT_TOO_LARGE Result too large -10 $IMGSE_INVALID_MONITOR Invalid monitor Performance Tips Use Cache: Enable cache for repeated searches to get 30-50% speed boost Pre-load Images: Use _ImageSearch_WarmUpCache() during initialization Limit Search Area: Specify search regions instead of full screen when possible Optimize Tolerance: Use appropriate tolerance values (5-15 for most cases) Use Appropriate Scale Range: Limit scale range to what you actually need Monitor Selection: Use specific monitor index for faster searches on multi-monitor setups Image Format: BMP files load faster than PNG/JPG but are larger Memory Management: Always call _WinAPI_DeleteObject() for HBITMAP handles Changelog Version 3.5 Added thread-local DPI awareness (no GUI resize issues) Enhanced multi-monitor support with individual monitor scales Improved cache system with persistent disk cache Added _ImageSearch_ScreenCapture_SaveImage() for direct file saving Performance optimizations with SIMD instructions Better error handling and debugging information License This project is licensed under the MIT License - see the LICENSE file for details. Author Dao Van Trong - TRONG.PRO Thank you for using ImageSearch UDF! 🚀 ☕ Support My Work Enjoy my work? Buy me a 🍻 or tip via ❤️ PayPal Happy Automating! 🚀 ___________________________1 point -
This is an update or derivative work of Beege 's Scrolling Line Graph UDF https://www.autoitscript.com/forum/topic/109599-scrolling-line-graph-udf I noticed a few issues for my use case with the UDF one being that adding a sample required updating the waveform High CPU usage went hand in hand with that requirement Another issue was just how long updating took to complete I've hopefully rectified that with this version There are a few changes (only 1 line per graph for instance) The addition of a function AddSample (uses graphics paths to speed up drawing samples on update) Gridlines are only generated once A sample finished line can be added UpdateGraph allows you to compress the discarded portion of the graph (it looks kinda cool but uses more CPU) Lower Cpu usage Uses real Control Ids - it is a label control underneath so you get click events and can display text when control is disabled Example (Waveform.au3) Example 2 (peak.au3) UDF Updated: Previous Downloads [38 / 38/ 0] SSLG.au3 waveform.au3 Peak.au31 point
-
It seems there are not many screensavers here in the examples forum. Thought maybe I could share mine. I'll admit some of the code is sloppy, global vars declared in functions, etc. But I started writing it almost 10 years ago and I just don't have the motivation to clean it up and rewrite from scratch. 😅 Maybe some day.. but for now, here's the code: ; Big thanks to UEZ (AutoIt forums) for his help with the GDI programming. #NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=FloatingClock.ico #AutoIt3Wrapper_Outfile=FloatingClock.scr #AutoIt3Wrapper_Compression=4 #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_Res_Fileversion=1.0.1.3 #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=n #AutoIt3Wrapper_Run_Before=IF "%fileversion%" NEQ "" COPY "%in%" "%scriptdir%\%scriptfile% (v%fileversion%).au3" #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GUIConstants.au3> #include <EditConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Math.au3> #Include <GDIPlus.au3> #include <Misc.au3> #include <Color.au3> #include <WinAPIProc.au3> #include <WinAPISys.au3> Global $IS_PREVIEW = False Global $TARGET_SPEED = 0.2, $DRIFT_SPEED = 100, $VELOC_DECAY = 1.01, $PROX_RADIUS = 100 Global $TIME_STRING[8], $TEXT_WIDTH, $TEXT_HEIGHT Global Enum $TP_X, $TP_Y, $TP_W, $TP_H, $TP_CHAR, $TP_UB Global $TIME_PIECES[8][$TP_UB] Global Enum $TG_X, $TG_Y, $TG_XVEL, $TG_YVEL, $TG_UB Global $TARGET_FOLLOW[$TG_UB], $TARGET_RANDOM[2] Global $CANVAS_X = _WinAPI_GetSystemMetrics($SM_XVIRTUALSCREEN) Global $CANVAS_Y = _WinAPI_GetSystemMetrics($SM_YVIRTUALSCREEN) Global $CANVAS_WIDTH = _WinAPI_GetSystemMetrics($SM_CXVIRTUALSCREEN) Global $CANVAS_HEIGHT = _WinAPI_GetSystemMetrics($SM_CYVIRTUALSCREEN) Global Enum $SET_REGKEY, $SET_ANTIALIAS, $SET_REFRESH, $SET_RAINBOW, $SET_STATIC, $SET_24HOUR, $SET_UB Global $SETTINGS[$SET_UB] = [ 'HKCU\Software\therkSoft\FloatingClock' ] If @Compiled Then If $CmdLine[0] Then Switch StringLeft($CmdLine[1], 2) Case '/p' If $CmdLine[0] > 1 Then _PreviewSaver($CmdLine[2]) ElseIf StringTrimLeft($CmdLine[1], 3) Then _PreviewSaver(StringTrimLeft($CmdLine[1], 3)) Else Exit EndIf Case '/s' _Singleton('FloatingClock.main') _MainSaver() Case Else _Config() EndSwitch Else _Config() EndIf Else _Config() GUIDelete() Sleep(500) _MainSaver() EndIf Func _Config() _LoadSettings() Local $iStaticColorSel Local $hGUIConfig = GUICreate('Floating Clock Config', 210, 160, Default, Default, BitOR($WS_CAPTION, $WS_POPUP, $WS_SYSMENU)) GUICtrlCreateGroup('Text color:', 5, 5, 200, 50) Local $ra_RainbowColor = GUICtrlCreateRadio('Rainbow', 25, 25, 70, 20) If $SETTINGS[$SET_RAINBOW] Then GUICtrlSetState(-1, $GUI_CHECKED) Local $ra_StaticColor = GUICtrlCreateRadio('Static: ', 100, 25, 50, 20) If Not $SETTINGS[$SET_RAINBOW] Then GUICtrlSetState(-1, $GUI_CHECKED) Local $bt_StaticColor = GUICtrlCreateButton('', 150, 25, 30, 20) GUICtrlSetBkColor(-1, $SETTINGS[$SET_STATIC]) Local $ch_AntiAlias = GUICtrlCreateCheckbox('Anti-alias text', 5, 60, 100, 20) If $SETTINGS[$SET_ANTIALIAS] Then GUICtrlSetState(-1, $GUI_CHECKED) Local $ch_24Hour = GUICtrlCreateCheckbox('24 hour clock', 105, 60, 100, 20) If $SETTINGS[$SET_24HOUR] Then GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlCreateLabel('Animation refresh rate:', 5, 85, 110, 20, $SS_CENTERIMAGE) Local $in_Refresh = GUICtrlCreateInput($SETTINGS[$SET_REFRESH], 115, 85, 30, 20, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER, $ES_RIGHT)) GUICtrlCreateLabel(' (ms)', 145, 85, 25, 20, $SS_CENTERIMAGE) Local $bt_OK = GUICtrlCreateButton('OK', 80, 115, 60, 25) GUICtrlSetState(-1, $GUI_DEFBUTTON) Local $bt_Cancel = GUICtrlCreateButton('Cancel', 145, 115, 60, 25) GUICtrlCreateLabel(' Version: ' & FileGetVersion(@ScriptFullPath) & ' ', 0, 145, 210, 15, BitOR($SS_SUNKEN, $SS_CENTERIMAGE, 0)) GUICtrlSetFont(-1, 7) GUISetState() While 1 Local $iGM = GUIGetMsg() Switch $iGM Case $bt_StaticColor ControlClick($hGUIConfig, '', $ra_StaticColor) $iStaticColorSel = _ChooseColor(2, $SETTINGS[$SET_STATIC], 2, $hGUIConfig) If $iStaticColorSel <> -1 Then $SETTINGS[$SET_STATIC] = $iStaticColorSel GUICtrlSetBkColor($bt_StaticColor, $SETTINGS[$SET_STATIC]) EndIf Case $bt_OK $SETTINGS[$SET_REFRESH] = Int(GUICtrlRead($in_Refresh)) If $SETTINGS[$SET_REFRESH] < 0 Then $SETTINGS[$SET_REFRESH] = 1 $SETTINGS[$SET_ANTIALIAS] = 0 If BitAND(GUICtrlRead($ch_AntiAlias), $GUI_CHECKED) Then $SETTINGS[$SET_ANTIALIAS] = 1 $SETTINGS[$SET_RAINBOW] = 0 If BitAND(GUICtrlRead($ra_RainbowColor), $GUI_CHECKED) Then $SETTINGS[$SET_RAINBOW] = 1 $SETTINGS[$SET_24HOUR] = 0 If BitAND(GUICtrlRead($ch_24Hour), $GUI_CHECKED) Then $SETTINGS[$SET_24HOUR] = 1 RegWrite($SETTINGS[$SET_REGKEY], 'Refresh', 'REG_DWORD', $SETTINGS[$SET_REFRESH]) RegWrite($SETTINGS[$SET_REGKEY], 'AntiAlias', 'REG_DWORD', $SETTINGS[$SET_ANTIALIAS]) RegWrite($SETTINGS[$SET_REGKEY], 'Rainbow', 'REG_DWORD', $SETTINGS[$SET_RAINBOW]) RegWrite($SETTINGS[$SET_REGKEY], 'Static', 'REG_DWORD', $SETTINGS[$SET_STATIC]) RegWrite($SETTINGS[$SET_REGKEY], '24Hour', 'REG_DWORD', $SETTINGS[$SET_24HOUR]) ExitLoop Case $bt_Cancel, $GUI_EVENT_CLOSE Exit EndSwitch WEnd EndFunc Func _PreviewSaver($iHandle) While WinExists('[CLASS:AutoIt v3 GUI; TITLE:FloatingClock.preview]') WinClose('[last]') WEnd _LoadSettings() Global $hWndCanvas = HWnd($iHandle) Local $aWinPos = WinGetPos($hWndCanvas) If @error Then Exit $CANVAS_WIDTH = $aWinPos[2] $CANVAS_HEIGHT = $aWinPos[3] $PROX_RADIUS = 10 Global $IS_PREVIEW = $hWndCanvas _Setup() AdlibRegister('_DrawingProcess', $SETTINGS[$SET_REFRESH]) GUICreate('FloatingClock.preview', 400, 100) Local $iParentProc = _WinAPI_GetParentProcess(@AutoItPID), $aChildProcs While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch $aChildProcs = _WinAPI_EnumChildProcess($iParentProc) If Not @error And $aChildProcs[0][0] > 1 Then Exit WEnd EndFunc Func _MainSaver() _LoadSettings() Global $hWndCanvas = GUICreate('', $CANVAS_WIDTH, $CANVAS_HEIGHT, $CANVAS_X, $CANVAS_Y, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) GUISetCursor(16, 1) _Setup() Sleep(500) GUISetState(@SW_SHOW) AdlibRegister('_DrawingProcess', $SETTINGS[$SET_REFRESH]) While 1 Sleep(10000) WEnd EndFunc Func _Setup() _GDIPlus_Startup() Global Const $hDC = _WinAPI_GetWindowDC($hWndCanvas) Global Const $hDC_backbuffer = _WinAPI_CreateCompatibleDC($hDC) Global Const $hBitmap_backbuffer = _WinAPI_CreateCompatibleBitmap($hDC, $CANVAS_WIDTH, $CANVAS_HEIGHT) Global Const $DC_obj = _WinAPI_SelectObject($hDC_backbuffer, $hBitmap_backbuffer) Global Const $hBackbuffer = _GDIPlus_GraphicsCreateFromHDC($hDC_backbuffer) If $SETTINGS[$SET_ANTIALIAS] Then _GDIPlus_GraphicsSetTextRenderingHint($hBackbuffer, 4) ; Anti-alias font? Global Const $hBrush_Clear = _GDIPlus_BrushCreateSolid(0xFF000000) Global Const $hBrush_Draw = _GDIPlus_BrushCreateSolid(BitOR(0xFF000000, $SETTINGS[$SET_STATIC])) Global Const $hPen_Draw = _GDIPlus_PenCreate(0xFFFFFFFF) Global Const $hFormat = _GDIPlus_StringFormatCreate(0x4004) _GDIPlus_StringFormatSetAlign($hFormat, 0) Global Const $hFamily = _GDIPlus_FontFamilyCreate('Arial') Global Const $hFont = _GDIPlus_FontCreate($hFamily, $CANVAS_HEIGHT / 8, 0) Global Const $tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0) OnAutoItExitRegister('_Exit') Local $colon = _GDIPlus_GraphicsMeasureString($hBackbuffer, ':', $hFont, $tLayout, $hFormat) $TEXT_HEIGHT = DllStructGetData($colon[0], 'Height') $colon = DllStructGetData($colon[0], 'Width') Local $num = _GDIPlus_GraphicsMeasureString($hBackbuffer, '8', $hFont, $tLayout, $hFormat) $num = DllStructGetData($num[0], 'Width') $TEXT_WIDTH = ($colon * 2 + $num * 5) * 0.6 + $num $TARGET_FOLLOW[$TG_X] = Random(0, $CANVAS_WIDTH - $TEXT_WIDTH, 1) $TARGET_FOLLOW[$TG_Y] = Random(0, $CANVAS_HEIGHT - $TEXT_HEIGHT, 1) $TARGET_FOLLOW[$TG_X] = ($CANVAS_WIDTH - $TEXT_WIDTH) / 2 $TARGET_FOLLOW[$TG_Y] = ($CANVAS_HEIGHT - $TEXT_HEIGHT) / 2 For $i = 0 To 7 $TIME_PIECES[$i][$TP_X] = ($CANVAS_WIDTH - $num) / 2 $TIME_PIECES[$i][$TP_Y] = ($CANVAS_HEIGHT - $TEXT_HEIGHT) / 2 Next _TargetRandomize() _GDIPlus_GraphicsFillRect($hBackbuffer, 0, 0, $CANVAS_WIDTH, $CANVAS_HEIGHT, $hBrush_Clear) EndFunc Func _DrawingProcess() If Not $IS_PREVIEW Then If _WinAPI_GetIdleTime() < 500 Then _Exit() Else If Not WinExists($IS_PREVIEW) Then _Exit() EndIf _TargetFollowing() _TimePieceMove() _WinAPI_BitBlt($hDC, 0, 0, $CANVAS_WIDTH, $CANVAS_HEIGHT, $hDC_backbuffer, 0, 0, $SRCCOPY) ; Copy buffer to main EndFunc Func _TargetRandomize() Global $TARGET_RANDOM[2] = [ Random(0, $CANVAS_WIDTH - $TEXT_WIDTH, 1), Random(0, $CANVAS_HEIGHT - $TEXT_HEIGHT, 1) ] EndFunc Func _TargetFollowing() Local $xDiff = $TARGET_RANDOM[$TG_X] - $TARGET_FOLLOW[$TG_X] Local $yDiff = $TARGET_RANDOM[$TG_Y] - $TARGET_FOLLOW[$TG_Y] If Sqrt($xDiff ^ 2 + $yDiff ^ 2) < $PROX_RADIUS Then _TargetRandomize() EndIf $TARGET_FOLLOW[$TG_XVEL] += $xDiff * $TARGET_SPEED /1000 $TARGET_FOLLOW[$TG_YVEL] += $yDiff * $TARGET_SPEED /1000 If ($xDiff < 0 And $TARGET_FOLLOW[$TG_XVEL] > 0) Or ($xDiff > 0 And $TARGET_FOLLOW[$TG_XVEL] < 0) Then $TARGET_FOLLOW[$TG_XVEL] /= $VELOC_DECAY EndIf If ($yDiff < 0 And $TARGET_FOLLOW[$TG_YVEL] > 0) Or ($yDiff > 0 And $TARGET_FOLLOW[$TG_YVEL] < 0) Then $TARGET_FOLLOW[$TG_YVEL] /= $VELOC_DECAY EndIf $TARGET_FOLLOW[$TG_X] += $TARGET_FOLLOW[$TG_XVEL] $TARGET_FOLLOW[$TG_Y] += $TARGET_FOLLOW[$TG_YVEL] If $TARGET_FOLLOW[$TG_X] > $CANVAS_WIDTH - $TEXT_WIDTH And $TARGET_FOLLOW[$TG_XVEL] > 0 Then $TARGET_FOLLOW[$TG_XVEL] *= -1 $TARGET_FOLLOW[$TG_X] = $CANVAS_WIDTH - $TEXT_WIDTH ElseIf $TARGET_FOLLOW[$TG_X] < 0 And $TARGET_FOLLOW[$TG_XVEL] < 0 Then $TARGET_FOLLOW[$TG_XVEL] *= -1 $TARGET_FOLLOW[$TG_X] = 0 EndIf If $TARGET_FOLLOW[$TG_Y] > $CANVAS_HEIGHT - $TEXT_HEIGHT And $TARGET_FOLLOW[$TG_YVEL] > 0 Then $TARGET_FOLLOW[$TG_YVEL] *= -1 $TARGET_FOLLOW[$TG_Y] = $CANVAS_HEIGHT - $TEXT_HEIGHT ElseIf $TARGET_FOLLOW[$TG_Y] < 0 And $TARGET_FOLLOW[$TG_YVEL] < 0 Then $TARGET_FOLLOW[$TG_YVEL] *= -1 $TARGET_FOLLOW[$TG_Y] = 0 EndIf EndFunc Func _TimePieceMove() Local $iHour = Int(@HOUR) If Not $SETTINGS[$SET_24HOUR] Then If $iHour = 0 Then $iHour = 12 If $iHour > 12 Then $iHour -= 12 EndIf Local $sTimeString = StringFormat('%2s:%02d:%02d', $iHour, @MIN, @SEC) $TIME_STRING = StringSplit($sTimeString, '', 2) If UBound($TIME_STRING) <> 8 Then AdlibUnRegister('_DrawingProcess') MsgBox(0x42010, 'Error parsing time string.', '$sTimeString = "' & $sTimeString & '" (' & StringLen($sTimeString) & ')') Exit EndIf ; Clear previous drawing For $idx = 0 To 7 _GDIPlus_GraphicsFillRect($hBackbuffer, $TIME_PIECES[$idx][$TP_X], $TIME_PIECES[$idx][$TP_Y], $TIME_PIECES[$idx][$TP_W], $TIME_PIECES[$idx][$TP_H], $hBrush_Clear) Next _StringPlace(0, $TARGET_FOLLOW[$TG_X], $TARGET_FOLLOW[$TG_Y]) For $i = 1 To 7 _StringPlace($i, $TIME_PIECES[$i-1][$TP_X] + $TIME_PIECES[$i-1][$TP_W] * 0.6, $TIME_PIECES[$i-1][$TP_Y]) Next EndFunc Func _StringPlace($idx, $x, $y) Local $aHSL[3] = [ 240, 240, 240 ] If $TIME_STRING[$idx] = ' ' Then $TIME_STRING[$idx] = '' $TIME_PIECES[$idx][$TP_CHAR] = $TIME_STRING[$idx] Local $aMeasure = _GDIPlus_GraphicsMeasureString($hBackbuffer, $TIME_PIECES[$idx][$TP_CHAR], $hFont, $tLayout, $hFormat) $TIME_PIECES[$idx][$TP_W] = DllStructGetData($aMeasure[0], 'Width') $TIME_PIECES[$idx][$TP_H] = DllStructGetData($aMeasure[0], 'Height') $TIME_PIECES[$idx][$TP_X] += ($x - $TIME_PIECES[$idx][$TP_X]) * $DRIFT_SPEED /1000 $TIME_PIECES[$idx][$TP_Y] += ($y - $TIME_PIECES[$idx][$TP_Y]) * $DRIFT_SPEED /1000 DllStructSetData($aMeasure[0], 'x', $TIME_PIECES[$idx][$TP_X]) DllStructSetData($aMeasure[0], 'y', $TIME_PIECES[$idx][$TP_Y]) If $SETTINGS[$SET_RAINBOW] Then $aHSL[0] = $TIME_PIECES[$idx][$TP_X] / $CANVAS_WIDTH * 480 $aHSL[2] = 200 - ($TIME_PIECES[$idx][$TP_Y] / $CANVAS_HEIGHT * 160) ; Range: 200-40 top-bottom Local $iBrushColor = _ColorSetRGB(_ColorConvertHSLtoRGB($aHSL)) _GDIPlus_BrushSetSolidColor($hBrush_Draw, 0xFF000000 + $iBrushColor) EndIf _GDIPlus_GraphicsDrawStringEx($hBackbuffer, $TIME_PIECES[$idx][$TP_CHAR], $hFont, $aMeasure[0], $hFormat, $hBrush_Draw) Return $aMeasure[0] EndFunc Func _LoadSettings() $SETTINGS[$SET_ANTIALIAS] = RegRead($SETTINGS[$SET_REGKEY], 'AntiAlias') If @error Then $SETTINGS[$SET_ANTIALIAS] = 1 $SETTINGS[$SET_REFRESH] = RegRead($SETTINGS[$SET_REGKEY], 'Refresh') If @error Then $SETTINGS[$SET_REFRESH] = 10 $SETTINGS[$SET_RAINBOW] = RegRead($SETTINGS[$SET_REGKEY], 'Rainbow') If @error Then $SETTINGS[$SET_RAINBOW] = 1 $SETTINGS[$SET_STATIC] = RegRead($SETTINGS[$SET_REGKEY], 'Static') If @error Then $SETTINGS[$SET_STATIC] = 0xffffff $SETTINGS[$SET_24HOUR] = RegRead($SETTINGS[$SET_REGKEY], '24Hour') If @error Then $SETTINGS[$SET_24HOUR] = 1 EndFunc Func _Exit() _GDIPlus_GraphicsFillRect($hBackbuffer, 0, 0, $CANVAS_WIDTH, $CANVAS_HEIGHT, $hBrush_Clear) _WinAPI_BitBlt($hDC, 0, 0, $CANVAS_WIDTH, $CANVAS_HEIGHT, $hDC_backbuffer, 0, 0, $SRCCOPY) ; Copy buffer to main AdlibUnRegister('_DrawingProcess') _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($hBrush_Draw) _GDIPlus_GraphicsDispose($hBackbuffer) _WinAPI_SelectObject($hDC, $DC_obj) _WinAPI_DeleteDC($hDC_backbuffer) _WinAPI_DeleteObject($hBitmap_backbuffer) _WinAPI_ReleaseDC($hWndCanvas, $hDC) _GDIPlus_Shutdown() Exit EndFunc1 point
-
It can be that _WinAPI_GetSystemMetrics() is not dpi aware. Then you will get wrong values. Currently I cannot test multi monitor with different dpi settings.1 point
-
Floating Clock Screensaver
argumentum reacted to therks for a topic
So I did encounter a problem, @UEZ. When triggered manually everything worked fine, but when triggered by the system AutoIt can't find the "Program Manager" window. So I grabbed the dimensions using _WinAPI_GetSystemMetrics instead.1 point -
Script becomes way slower after a msgbox - (Moved)
argumentum reacted to Nine for a topic
The display is not performed correctly : #include <GUIConstants.au3> #include <WindowsConstants.au3> #include <GDIPlus.au3> #include <WinAPI.au3> HotKeySet("{END}", "Quit") OnAutoItExitRegister("CleanUp") Global $hImage, $GFC, $iInd = 0 Global $hGUI = GUICreate("", 400, 500, -1, -1, $WS_POPUP, $WS_EX_LAYERED + $WS_EX_TOPMOST) GUISetBkColor(0x00FFFF) Global $IMG_Ctrl = GUICtrlCreatePic("", 10, 10, -1, -1, -1, $GUI_WS_EX_PARENTDRAG) _WinAPI_SetLayeredWindowAttributes($hGUI, 0x00FFFF) GifInit() AdlibRegister (_Draw_Timer, 80) GUISetState(@SW_SHOW) While 1 If GUIGetMsg() = $GUI_EVENT_CLOSE Then Quit() WEnd Func _Draw_Timer() If $iInd = $GFC Then $iInd = 0 GifDrawFrame($iInd) $iInd += 1 EndFunc ;==>_Draw_Timer Func Quit() Exit EndFunc ;==>Quit Func CleanUp() _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() EndFunc ;==>CleanUp Func GifInit() _GDIPlus_Startup() $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\xmas tree.gif") $GFC = _GDIPlus_ImageGetFrameCount($hImage, $GDIP_FRAMEDIMENSION_TIME) EndFunc ;==>GifInit Func GifDrawFrame($i) _GDIPlus_ImageSelectActiveFrame($hImage, $GDIP_FRAMEDIMENSION_TIME, $i) Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) _SetBitmapToCtrl($IMG_Ctrl, $hBitmap) _WinAPI_DeleteObject($hBitmap) EndFunc ;==>GifDrawFrame Func _SetBitmapToCtrl($CtrlId, $hBitmap) Local $hWnd = GUICtrlGetHandle($CtrlId) If $hWnd = 0 Then Return SetError(1, 0, 0) Local $hPrev = _SendMessage($hWnd, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap) If @error Then Return SetError(2, 0, 0) If $hPrev Then _WinAPI_DeleteObject($hPrev) Return 1 EndFunc ;==>_SetBitmapToCtrl1 point -
This (now ex)member has gained an unfortunate reputation on other fora of asking for help via PM and attaching a script which, when run, tries to steal your account information/credentials, etc for a whole list of applications before sending them to the OP. If you have received a PM from this (ex)member asking for help with a script DO NOT RUN IT - just delete the PM and/or the downloaded script ASAP. M231 point
-
With my code, I see the changes occurring in the fields. If you want to set value like you did, you need to fire events : $oObject.fireEvent("OnChange") $oObject.fireEvent("OnClick")1 point
-
Assign variable to object property with string expression
FrancescoDiMuro reacted to Gianni for a topic
A simpler way, if it's okay for you to set a property value by passing "strings" to a function instead of using a single string in an Execute () statement, then you can use a "magic" way provided by a magical girl, @trancexx, published at this link: here I simply wrapped his magic potion within this function: Func _SetProperty($oObj, $sProperty, $vData) ; by Trancexx ; https://www.autoitscript.com/forum/topic/200129-set-object-properties-with-propertyname-and-value-taken-from-an-array/?do=findComment&comment=1436379 ; Some constants used in code Const $tagIUnknown = "QueryInterface hresult(ptr;ptr*);" & _ "AddRef dword();" & _ "Release dword();" Const $tagIDispatch = $tagIUnknown & _ "GetTypeInfoCount hresult(dword*);" & _ "GetTypeInfo hresult(dword;dword;ptr*);" & _ "GetIDsOfNames hresult(struct*;struct*;dword;dword;struct*);" & _ "Invoke hresult(uint;struct*;dword;word;struct*;struct*;ptr;uint*);" Const $DISPID_PROPERTYPUT = -3 Const $DISPATCH_PROPERTYPUT = 4 Const $LOCALE_SYSTEM_DEFAULT = 0x800 Const $tIID_NULL = DllStructCreate("byte[16]") Const $tagDISPPARAMS = "ptr rgvarg;ptr rgdispidNamedArgs;uint cArgs;uint cNamedArgs;" Const $VT_I4 = 3 Const $tVARIANT = "word vt;word r1;word r2;word r3;ptr data; ptr" Const $sIID_IDispatch = "{00020400-0000-0000-C000-000000000046}" ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ; Superposed object on top of the original one Local $oObjMy = ObjCreateInterface($oObj, $sIID_IDispatch, $tagIDispatch, False) ; Collect ID number of the function/property/method, whatever $tDisp = DllStructCreate("dword") $tName = DllStructCreate("ptr") $tN = DllStructCreate("wchar[" & StringLen($sProperty) + 1 & "]") DllStructSetData($tN, 1, $sProperty) DllStructSetData($tName, 1, DllStructGetPtr($tN)) $oObjMy.GetIDsOfNames($tIID_NULL, $tName, 1, $LOCALE_SYSTEM_DEFAULT, $tDisp) ; Tadaaa! $iDispId = DllStructGetData($tDisp, 1) ; Now build disp parameters $tDISPPARAMS = DllStructCreate($tagDISPPARAMS) $tDISPPARAMS.cNamedArgs = 1 $tDispidNamed = DllStructCreate("uint") DllStructSetData($tDispidNamed, 1, $DISPID_PROPERTYPUT) $tDISPPARAMS.rgdispidNamedArgs = DllStructGetPtr($tDispidNamed) $tDISPPARAMS.cArgs = 1 $tVar = DllStructCreate($tVARIANT) $tDISPPARAMS.rgvarg = DllStructGetPtr($tVar) ; Set desired value $tVar.vt = $VT_I4 $tVar.data = $vData ; And call it $iRet = $oObjMy.Invoke($iDispId, $tIID_NULL, 0x800, $DISPATCH_PROPERTYPUT, $tDISPPARAMS, 0, 0, 0) Return (Hex($iRet, 8)) ; ConsoleWrite(">>> Returned hresult = " & Hex($iRet, 8) & @CRLF) ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< EndFunc ;==>_SetProperty here an example of use: https://www.autoitscript.com/forum/topic/200129-set-object-properties-with-propertyname-and-value-taken-from-an-array/?do=findComment&comment=14363861 point -
Since I have this extra post here I'll go into some of the details As you recall (or maybe you have no idea) Begee's original code only updated one point on each graph redraw This lead to some pretty high CPU usage if you wanted to add lots of points My idea was to allow adding multiple points before redrawing the graph.......1 point
-
GUI checkbox and button
GoogleGonnaSaveUs reacted to InunoTaishou for a topic
Use GUICtrlRead to get the state of the checkbox and execute the respective function is they are checked #include <GUIConstants.au3> Global $frmMain = GUICreate("Test", 300, 200) Global $inpInput = GUICtrlCreateInput("", 10, 10, 280, 20) Global $chkMsgBox = GUICtrlCreateCheckbox("MsgBox('', '', 'Inputbox')", 10, 35, 280) Global $chkShellExecute = GUICtrlCreateCheckbox("ShellExecute('Inputbox')", 10, 55, 280) Global $btnRun = GUICtrlCreateButton("Run Test", 10, 80, 280, 20) Global $bExecuteMsgBox = False Global $bExecuteShell = False GUISetState(@SW_SHOW, $frmMain) ; Option 1 While (1) Switch (GUIGetMsg()) Case $GUI_EVENT_CLOSE Exit Case $btnRun Local $sData = GUICtrlRead($inpInput) If ($bExecuteShell) Then ShellExecute($sData) If ($bExecuteMsgBox) Then MsgBox("", "", $sData) Case $chkMsgBox $bExecuteMsgBox = Not $bExecuteMsgBox Case $bExecuteShell $bExecuteShell = Not $bExecuteShell EndSwitch WEnd ; Option 2 While (1) Switch (GUIGetMsg()) Case $GUI_EVENT_CLOSE Exit Case $btnRun Local $sData = GUICtrlRead($inpInput) If (GUICtrlRead($chkShellExecute) = $GUI_CHECKED) Then ShellExecute($sData) If (GUICtrlRead($chkMsgBox) = $GUI_CHECKED) Then MsgBox("", "", $sData) EndSwitch WEnd1 point -
Does AutoIT have != or NOTEQUAL logical operator
GoogleGonnaSaveUs reacted to water for a topic
If $variableA <> $variableB Then ...The relevant docu can be found here.1 point -
Best Way to Save GUI Control Settings
GoogleGonnaSaveUs reacted to Melba23 for a topic
grasshopper3, You could do it like this: #include <GUIConstantsEx.au3> Global $aControlID[4] ; Set this to match the number of controls Global $sIniFile = @ScriptDir & "\Test.ini" $hGUI = GUICreate("Test", 500, 500) ; Create the control $hInput_A = GUICtrlCreateInput("", 10, 10, 200, 20) ; And save the ControlID in the Array $aControlID[0] = $hInput_A $hInput_B = GUICtrlCreateInput("", 10, 50, 200, 20) $aControlID[1] = $hInput_B $hInput_C = GUICtrlCreateInput("", 10, 90, 200, 20) $aControlID[2] = $hInput_C $hInput_D = GUICtrlCreateInput("", 10, 130, 200, 20) $aControlID[3] = $hInput_D ; Loop through the array to set the saved values For $i = 0 To 3 GUICtrlSetData($aControlID[$i], IniRead($sIniFile, "Data", $i, "Not found")) Next GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ; Loop through the array to save the current values For $i = 0 To 3 IniWrite($sIniFile, "Data", $i, GUICtrlRead($aControlID[$i])) Next Exit EndSwitch WEnd You coudl also put the ControlIDs directly into the array as the controls are created, but then you would have to remember which array element was which control. I think the code above is the best compromise - you get nice easy to use variables in your script and an array to loop through when needed. All clear? M231 point