Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 05/02/2020 in all areas

  1. Sure ... banned permanently! 🤐 Jos
    3 points
  2. 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.au3
    2 points
  3. 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
  4. Trong

    ImageSearchUDF

    Version 2025.5.25.5

    11,365 downloads

    High-Performance ImageSearch UDF & DLL for AutoIt This project provides a highly optimized UDF (User Defined Function) and two versions of a DLL (Dynamic-Link Library) for fast and flexible image searching on the screen using AutoIt. It serves as a powerful replacement for standard image search functions, delivering superior speed, especially on modern CPUs, by leveraging advanced SIMD instructions. ✨ Key Features Superior Speed: The modern version utilizes the AVX2 instruction set to accelerate the search speed by several factors compared to traditional methods. Two DLL Versions: Provides both a modern version (optimized for speed) and a legacy version (for Windows XP support). Multi-Image Search: Search for multiple image files in a single function call by separating paths with a pipe (|). Multi-Scale Searching: Automatically search for an image across a range of sizes (e.g., from 80% to 120% of its original size). Color Tolerance: Find images even with slight color variations by setting a tolerance value (0-255). Transparent Color Support: Specify a color in the source image to be ignored during the search. Flexible Result Handling: Find and return the first match. Find and return all matches on the screen. Limit the maximum number of results. Smart (Hybrid) DLL Loading: The UDF prioritizes an external DLL for maximum performance and automatically falls back to an embedded DLL to ensure the script always runs. Unicode Support: Works flawlessly with file paths containing Unicode characters. Thread-Safe: The DLL is designed to operate stably in multi-threaded scenarios. Debug Information: Provides an option to return a detailed debug string for easy troubleshooting. 🚀 The Two DLL Versions The project offers two DLL versions to meet different needs: 1. ImageSearch_x86.dll ImageSearch_x64.dll (Modern Version) (Attached in the same UDF folder - Because the DLL file with AVX2 support is large in size) This is the recommended version for most users. Strengths: AVX2 Support: Leverages Advanced Vector Extensions 2 on modern CPUs to process multiple pixels in parallel, resulting in extremely fast search speeds. Built with modern C++, ensuring stability and efficiency. Limitations: Not compatible with Windows XP. When to use: When you need maximum performance on Windows 7, 8, 10, 11, and newer. 2. ImageSearch_XP.dll (Legacy Version) (Embedded in UDF code) This version is created for backward compatibility. Strengths: Windows XP Compatibility: Works well on the Windows XP (SP3) operating system. Limitations: No AVX2 Support: Search speed will be significantly slower than the modern version on AVX2-supported CPUs. When to use: When your script must run in a Windows XP environment. ⚙️ How the UDF Works The ImageSearch_UDF.au3 file uses a very smart "hybrid" DLL loading mechanism: Prioritize External DLL: When the _ImageSearch function is called, the UDF first looks for ImageSearch_x86.dll and ImageSearch_x64.dll in the same directory as the script (@ScriptDir). If found, it uses this file to achieve the best performance (with AVX2 if available). Fallback to Embedded DLL: If the external DLL is not found, the UDF will automatically extract and use a legacy (non-AVX2) compatible DLL version that is embedded within it as a hex string. ➡️ This ensures that your script can always run, even if you forget to copy the DLL file. However, for the highest speed, always place the modern ImageSearch_x86.dll and ImageSearch_x64.dll next to your script. 📦 Setup Place the DLL file: Copy ImageSearch_x86.dll and ImageSearch_x64.dll (the modern version) into the same directory as your AutoIt script file. Include the UDF in your script: Use the line #include <ImageSearch_UDF.au3> in your script. 📖 API Reference The main function for performing an image search. _ImageSearch($sImageFile, [$iLeft = 0], [$iTop = 0], [$iRight = 0], [$iBottom = 0], [$iTolerance = 10], [$iTransparent = 0xFFFFFFFF], [$iMultiResults = 0], [$iCenterPOS = 1], [$iReturnDebug = 0], [$fMinScale = 1.0], [$fMaxScale = 1.0], [$fScaleStep = 0.1], [$iFindAllOccurrences = 0]) Parameters Parameter Type Default Description $sImageFile String - Path to the image file. To search for multiple images, separate paths with a pipe (` $iLeft Int 0 The left coordinate of the search area. 0 defaults to the entire screen. $iTop Int 0 The top coordinate of the search area. 0 defaults to the entire screen. $iRight Int 0 The right coordinate of the search area. 0 defaults to the entire screen. $iBottom Int 0 The bottom coordinate of the search area. 0 defaults to the entire screen. $iTolerance Int 10 Color tolerance (0-255). A higher value allows for greater color variation. $iTransparent Int 0xFFFFFFFF The color (in 0xRRGGBB format) to be ignored in the source image. 0xFFFFFFFF means no transparency. $iMultiResults Int 0 The maximum number of results to return. 0 means no limit. $iCenterPOS Bool 1 (True) If True, the returned X/Y coordinates will be the center of the found image. If False, they will be the top-left corner. $iReturnDebug Bool 0 (False) If True, the function returns a debug string instead of the results array. $fMinScale Float 1.0 The minimum scaling factor for the search (e.g., 0.8 for 80%). Must be >= 0.1. $fMaxScale Float 1.0 The maximum scaling factor for the search (e.g., 1.2 for 120%). $fScaleStep Float 0.1 The increment to use when searching between min and max scales. Must be >= 0.01. $iFindAllOccurrences Bool 0 (False) If False, the search stops after the first match. If True, it finds all possible matches. Return Value On Success: Returns a 2D array containing the coordinates of the found images. $aResult[0][0] = The number of matches found. $aResult[1] to $aResult[$aResult[0][0]] = An array for each match. $aResult[$i][0] = X coordinate $aResult[$i][1] = Y coordinate $aResult[$i][2] = Width of the found image $aResult[$i][3] = Height of the found image On Failure / No Match: Sets @error to 1 and returns 0. In Debug Mode: If $iReturnDebug is True, returns a string containing detailed information about the last search operation. 💻 Examples Example 1: Basic Search Find the first occurrence of button.png on the screen. #include <ImageSearch_UDF.au3> Local $aResult = _ImageSearch("C:\images\button.png") If @error Then MsgBox(48, "Error", "Image not found on screen.") Else Local $iCount = $aResult[0][0] Local $iX = $aResult[1][0] Local $iY = $aResult[1][1] MsgBox(64, "Success", "Found " & $iCount & " image(s). First match is at: " & $iX & ", " & $iY) MouseMove($iX, $iY, 20) ; Move mouse to the center of the found image EndIf Example 2: Advanced Search (Multiple Images, Tolerance, Scaling) Search for icon1.png or icon2.png within a specific region, with a tolerance of 20 and scaling from 90% to 110%. Find all occurrences. #include <ImageSearch_UDF.au3> Local $sImages = "icon1.png|icon2.png" Local $iTolerance = 20 Local $fMinScale = 0.9 Local $fMaxScale = 1.1 Local $fStep = 0.05 Local $aResult = _ImageSearch($sImages, 500, 300, 1200, 800, $iTolerance, 0xFFFFFFFF, 0, True, False, $fMinScale, $fMaxScale, $fStep, True) If @error Then MsgBox(48, "Error", "No matching images found in the specified region.") Else Local $iCount = $aResult[0][0] ConsoleWrite("Found " & $iCount & " total matches." & @CRLF) For $i = 1 To $iCount ConsoleWrite("Match #" & $i & ": X=" & $aResult[$i][0] & ", Y=" & $aResult[$i][1] & ", W=" & $aResult[$i][2] & ", H=" & $aResult[$i][3] & @CRLF) Next EndIf Example 3: Using Debug Mode To diagnose issues, use the $iReturnDebug parameter. #include <ImageSearch_UDF.au3> Local $2dDLLResult = _ImageSearch("image_not_exist.png", 0, 0, 0, 0, 10, 0xFFFFFFFF, 0, True, True) ConsoleWrite(">> DLL Return: " & $g_sLastDllReturn & @CRLF) ; Example output: {0}[No Match Found] | DEBUG: File=image_not_exist.png, Rect=(0,0,1920,1080), Tol=10, Trans=0xffffffff, Multi=0, Center=1, FindAll=0, AVX2=true, Scale=(1.00,1.00,0.10) SPECIAL NOTE: The function always returns a 2D array for both results and errors. Credits Author: Dao Van Trong - TRONG.PRO Source Dll on GitHub: daovantrong/ImageSearchDLL: A DLL for finding an image on the screen
    1 point
  5. 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.au3
    1 point
  6. therks

    Floating Clock Screensaver

    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 EndFunc
    1 point
  7. UEZ

    Floating Clock Screensaver

    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
  8. 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
  9. 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 ;==>_SetBitmapToCtrl
    1 point
  10. Melba23

    Daniel_FUD

    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. M23
    1 point
  11. Nine

    Advanced login form

    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
  12. 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=1436386
    1 point
  13. 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
  14. 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 WEnd
    1 point
  15. If $variableA <> $variableB Then ...The relevant docu can be found here.
    1 point
  16. 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? M23
    1 point
×
×
  • Create New...