Leaderboard
Popular Content
Showing content with the highest reputation on 09/17/2013 in all areas
-
Edit: See >post #3 for later code created in 2013 for use in AutoIt 3.3.81 and later. A simple UDF I made based on the idea of returning variable values from a script at the point of runtime closure. I manage to catch the Globals but the Locals would need more impressive code that would need to run within the functions themselves. It maybe useful for some and perhaps fun to others. It is set to dump the variables to Console so is perfect for editors that support this, such as Scite4AutoIt3. Use the latest AutoIt Beta as I used some code that requires it. Method of use: Just add this to the top of a script. Opt('OnExitFunc', '_DebugGlobalVars') Then I insert this UDF to the bottom of the script. Func _DebugGlobalVars() If @Compiled Then Return ConsoleWrite('>Func _DebugGlobalVars()' & @LF) Local $debug_end, $debug_handle_read, $debug_i, $debug_globals Local $debug_j, $debug_k, $debug_length, $debug_line Local $debug_num, $debug_out, $debug_start, $debug_array Local $debug_temp, $debug_total, $debug_var, $debug_string $debug_globals = 0; Extra Output $debug_handle_read = FileOpen(@ScriptFullPath, 0) While 1 $debug_line = FileReadLine($debug_handle_read) If @error Then ExitLoop $debug_line = StringStripWS($debug_line, 3) While StringLeft($debug_line, 1) = ';' $debug_line = FileReadLine($debug_handle_read) $debug_line = StringStripWS($debug_line, 3) WEnd If $debug_line = '' Then ContinueLoop If StringInStr($debug_line, '$debug_') Then ConsoleWrite('!>Variable Name conflict in line: ' & $debug_line & @LF) ContinueLoop EndIf If $debug_line = 'Func _DebugGlobalVars()' Then Do $debug_line = FileReadLine($debug_handle_read) $debug_line = StringStripWS($debug_line, 3) Until $debug_line = 'EndFunc' ContinueLoop EndIf StringReplace($debug_line, '$', '') $debug_num = @extended If $debug_num Then $debug_length = StringLen($debug_line) For $debug_i = 1 To $debug_num $debug_start = StringInStr($debug_line, '$', 0, $debug_i) If @error Then ContinueLoop 2 $debug_end = $debug_start + 1 For $debug_j = $debug_end To $debug_length $debug_temp = StringMid($debug_line, $debug_j, 1) Switch $debug_temp Case ')', ',', ' ', '&', ';' ExitLoop Case '.', '[', "'" ContinueLoop 2 Case ']' ExitLoop EndSwitch Next $debug_var = StringMid($debug_line, $debug_start, $debug_j - $debug_start); $debug_out = StringSplit($debug_total, ', ', 1) If Not @error Then For $debug_k = 1 To $debug_out[0] If $debug_var = $debug_out[$debug_k] Then ContinueLoop 2 Next EndIf $debug_total &= ', ' & $debug_var If StringLeft($debug_total, 2) = ', ' Then $debug_total = StringTrimLeft($debug_total, 2) EndIf $debug_string = StringTrimLeft($debug_var, 1) Switch IsDeclared($debug_string) Case -1, 0 ContinueLoop EndSwitch ConsoleWrite($debug_var & ' = ' & Eval($debug_string) & @LF) Next EndIf WEnd FileClose($debug_handle_read) If $debug_globals Then $debug_array = StringSplit($debug_total, ', ', 1) If Not @error Then ConsoleWrite('Global ') For $i = 1 To $debug_array[0] If StringRight($i, 1) = '0' Then ConsoleWrite(@LF & 'Global ') Else If StringRight($i, 1) = '9' Then ConsoleWrite($debug_array[$i]) Else ConsoleWrite($debug_array[$i] & ', ') EndIf EndIf Next EndIf EndIf ConsoleWrite('>EndFunc' & @LF) EndFunc1 point
-
Hi all, I got bored so I decided to rewrite Mike Singleton / Postern's excellent 1983 Spectrum game Snake Pit. It's a fairly faithful recreation with a couple of minor tweaks over the original. All the assets are embedded into the script so there are no extra files required. Credit to UEZ for the File to Base64 String functions and for _GDIPlus_ScaleImage and to Tom Vernooij for _ArrayRandom. The code is way to large for a code box so I'll just attach the file. Comments welcome but I probably won't be spending much time improving any of the multitude of inefficiencies. I'm not a programmer, I'm more of a fiddler so don't expect to see best practices for variable/function naming or just about anything else. Known bugs. Occasionally pressing 'S' to restart doesn't work correctly, I can't be bothered to fix it so just press 'S' again. Speed is inconsistent. I tried to dynamically adjust the sleep but just made it worse. Object of game: While $playerAlive = True AvoidSnakes() Eat Eggs($lotsOf) EatSnakesStartingFromTail() IncreaseSpeedAndStartAgain() WEnd Enjoy! SnakePit.au31 point
-
In that case it would be something like this: ;=============================================================================== #interface "IActiveDesktop" Global Const $sCLSID_ActiveDesktop = "{75048700-EF1F-11D0-9888-006097DEACF9}" Global Const $sIID_IActiveDesktop = "{F490EB00-1240-11D1-9888-006097DEACF9}" Global Const $tagIActiveDesktop = _ "ApplyChanges hresult(dword);" & _ "GetWallpaper hresult(wstr;uint;dword);" & _ "SetWallpaper hresult(wstr;dword);" & _ "GetWallpaperOptions hresult(struct*;dword);" & _ "SetWallpaperOptions hresult(struct*;dword);" & _ "GetPattern hresult(wstr;uint;dword);" & _ "SetPattern hresult(wstr;dword);" & _ "GetDesktopItemOptions hresult(struct*;dword);" & _ "SetDesktopItemOptions hresult(struct*;dword);" & _ "AddDesktopItem hresult(struct*;dword);" & _ "AddDesktopItemWithUI hresult(hwnd;struct*;dword);" & _ "ModifyDesktopItem hresult(struct*;dword);" & _ "RemoveDesktopItem hresult(struct*;dword);" & _ "GetDesktopItemCount hresult(int*;dword);" & _ "GetDesktopItem hresult(int;struct*;dword);" & _ "GetDesktopItemByID hresult(ulong_ptr;struct*;dword);" & _ "GenerateDesktopItemHtml hresult(wstr;struct*;dword);" & _ "AddUrl hresult(hwnd;wstr;struct*;dword);" & _ "GetDesktopItemBySource hresult(wstr;struct*;dword);" ;=============================================================================== Global Const $AD_APPLY_ALL = 0x00000007 ;;;;;;;;;;;;;;;;;;; Example ;;;;;;;;;;;;;;;;;;;;;;;;;;; $oActiveDesktop = ObjCreateInterface($sCLSID_ActiveDesktop, $sIID_IActiveDesktop, $tagIActiveDesktop) $sFile = FileOpenDialog("Select New Wallpaper", "", "Images (*.jpg;*.bmp;*.png;*.gif;*.whatever)") ; whatever If $sFile Then $oActiveDesktop.SetWallpaper($sFile, 0) $oActiveDesktop.ApplyChanges($AD_APPLY_ALL) EndIf ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; In that example you see declarations for CLSID, IID and Interface tag. That would normally go in some (standard) UDF and the code would be much more similar in size as delphi's. But unfortunatly AutoIt doesn't have those UDFs.1 point
-
hello world! typically i would use this to get text between brackets $string = "Bob Parker {BP}" $array = StringRegExp($string, "(?s)(?i){(.*?)}", 3) msgbox(0,"",$array[0]) but it doesnt work the same for parenthesis - i think because its seeing the parenthesis as indicators instead of literal symbols. is there somethign that would work for both? thanks1 point
-
1 point
-
The use of $path suits your task. The @scriptdir is just an example given that FileInstall can work in the script directory. You use FileSelectFolder to set a path to FileInstall the files which is suitable to do. Your use of EnvSet has no effect on anything that I can see of how you use it.1 point
-
michaelslamet, So I guess you did not see my relic >_DebugGlobalVars() from 2006. It seems to work in the beta but not 3.3.8.1. Perhaps I was ahead of my time. Dumping Global variables from a function is easy though doing Local variables is something else. The debug code running in the script may need to be in the function of choice to get the Locals variables for that function. Here is something more current with StringRegExp to help make it more efficient. #include <array.au3> OnAutoItExitRegister('_DumpGlobalVars') Global _ $string = 'This is a string with a @TAB' & @TAB & 'and it ends with @CRLF' & @CRLF, _ $array[11], _ $binary = StringToBinary($string), _ $bool = True, _ $false = False, _ $float = 12.01, _ $hex = Hex(13), _ $hwnd = WinGetHandle("[CLASS:Shell_TrayWnd]"), _ $int = 14, _ $keyword = Default, _ $number = Number(15.01), _ $ptr = Ptr(16), _ $struct = DllStructCreate('char[' & 65536 & ']'), _ $true = True Exit Func _DumpGlobalVars() Local $__content, $__string, $__variable, $__format = '%-10s%-15s%s' $__content = StringRegExpReplace(FileRead(@ScriptFullPath), '(*ANYCRLF);.*', '') $__content = StringRegExp($__content, '(?<=\$)\w+?\b', 3) If IsArray($__content) Then $__content = _ArrayUnique($__content) _ArraySort($__content) $__string = StringFormat($__format, 'TYPE', 'VARIABLE', 'VALUE') & @CRLF For $__variable In $__content If IsDeclared($__variable) = 1 Then $__string &= StringFormat($__format, VarGetType(Eval($__variable)), '$' & $__variable, Eval($__variable)) & @CRLF EndIf Next ConsoleWrite($__string & @CRLF) Else ConsoleWriteError('No variables found' & @CRLF) EndIf EndFunc It will dump all Globals to the console when the script has exited as the setting of OnAutoItExitRegister does this. This is the output from the example: TYPE VARIABLE VALUE Array $array Binary $binary 0x54686973206973206120737472696E6720776974682061204054414209616E6420697420656E64732077697468204043524C460D0A Bool $bool True Bool $false False Double $float 12.01 String $hex 0000000D Ptr $hwnd 0x0001007E Int32 $int 14 Keyword $keyword Default Double $number 15.01 Ptr $ptr 0x00000010 String $string This is a string with a @TAB and it ends with @CRLF DLLStruct $struct Bool $true True1 point
-
Func _RandomlyClickControls($WindowTitle) Local $text = WinGetClassList($WindowTitle, "") $text = StringStripWS($text, 2) Local $aText = StringRegExp($text, "\V+", 3) _ArraySort($aText) Local $aClassNN[UBound($aText)] $aClassNN[0] = $aText[0] & $iIndex For $i = 1 To UBound($aText) - 1 If $aText[$i] = $aText[$i - 1] Then $iIndex += 1 Else $iIndex = 1 EndIf $aClassNN[$i] = $aText[$i] & $iIndex Next Do $iRndNum = Random(0, UBound($aClassNN) - 1, 1) Local $aPos = ControlGetPos($WindowTitle, "", $aClassNN[$iRndNum]) MouseMove($aPos[0] + 4, $aPos[1] + 4, 10) MouseClick("left") Sleep(1000) Until _IsPressed("1B") ; Press and hold "Esc" key for over a second to exit EndFunc ;==>_RandomlyClickControls $aClassNN[$iRndNum] in the ControlGetPos function, line#18, creates the random selection of a control. All the ClassnameNN property of each control of the selected window are in the $aClassNN array, line#14. The ClassnameNN property is made up of the Class of the control and the Instance of the control. The ClassnameNN identifies each control and is used as the controlID parameter of the ControlGetPos function, line#18. So, the random control selection is made by selecting one of the elements in the $aClassNN array. This random selection is done by using a random number in the array index. This random index number is stored in the $iRndNum variable, line#17.1 point
-
_WinAPI_DrawShadowText
DatMCEyeBall reacted to UEZ for a topic
Here the GDI+ variant: ;Coded by UEZ 2013 -> This program requires AutoIt version 3.3.9.21 or higher! #AutoIt3Wrapper_Autoit3Dir=c:\Program Files (x86)\AutoIt3\Beta #include <GUIConstantsEx.au3> #include <GDIPlus.au3> #include <WindowsConstants.au3> If Not _WinAPI_DwmIsCompositionEnabled() Then MsgBox(BitOR(16, 4096), 'Error', 'Script requires Windows Vista or later with enabled Aero theme.') Exit EndIf _GDIPlus11_Startup() Global Const $GDIP_BLUREFFECT = "{633C80A4-1843-482b-9EF2-BE2834C5FDD4}" Global Const $hGUI = GUICreate("Shadow Text Beta by UEZ 2013", 640, 130, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_WINDOWEDGE)) GUISetBkColor(0x000000) Global Const $iPic = GUICtrlCreatePic("", 0, 0, 640, 130) _WinAPI_DwmExtendFrameIntoClientArea($hGUI) Global $hBmp = _GDIPlus_BitmapCreateFromScan0(640, 130) Global $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBmp) _GDIPlus_DrawShadowText($hCtxt, "AutoIt rulez!", 80, 0, 0, 0xE00000C0, "Arial", 8, 6, 0xA0000000) Global $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp) _WinAPI_DeleteObject(GUICtrlSendMsg($iPic, 0x0172, 0x0000, $hHBitmap)) GUISetState() Do Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _GDIPlus_GraphicsDispose($hCtxt) _GDIPlus_BitmapDispose($hBmp) _WinAPI_DeleteObject($hHBitmap) _GDIPlus_Shutdown() GUIDelete() Exit EndSwitch Until False Func _GDIPlus_DrawShadowText($hGraphic, $sText, $iFontSize, $iX, $iY, $iColorText = 0xFF000080, $sFont = "Arial", $iShadowX = 3, $iShadowY = 3, $iColorShadow = 0xF0000000, $iFontStyle = 0, $iBlurLevel = 10) Local Const $hFormat = _GDIPlus_StringFormatCreate() Local Const $hFamily = _GDIPlus_FontFamilyCreate($sFont) Local Const $hFont = _GDIPlus_FontCreate($hFamily, $iFontSize, $iFontStyle) Local Const $tLayout = _GDIPlus_RectFCreate() Local Const $hBrush = _GDIPlus_BrushCreateSolid($iColorShadow) Local Const $aBounds = _GDIPlus_GraphicsMeasureString($hGraphic, $sText, $hFont, $tLayout, $hFormat) Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0(Floor(DllStructGetData($aBounds[0], "width") + Abs($iShadowX)), Floor(DllStructGetData($aBounds[0], "height") + Abs($iShadowX))) Local $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetSmoothingMode($hCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY) _GDIPlus_GraphicsSetTextRenderingHint($hCtxt, $GDIP_TEXTRENDERINGHINT_ANTIALIASGRIDFIT) DllStructSetData($tLayout, "x", $iShadowX) DllStructSetData($tLayout, "y", $iShadowY) _GDIPlus_GraphicsDrawStringEx($hCtxt, $sText, $hFont, $tLayout, $hFormat, $hBrush) Local Const $tagBLURPARAMS = "float radius;bool expandEdge" Local Const $tBlur = DllStructCreate($tagBLURPARAMS) Local Const $hEffect = _GDIPlus_Blur($tBlur, $iBlurLevel) Local Const $hBitmap_Blur = _GDIPlus_BitmapCreateApplyEffect($hBitmap, $hEffect) _GDIPlus_GraphicsDispose($hCtxt) _GDIPlus_BitmapDispose($hBitmap) $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap_Blur) _GDIPlus_GraphicsSetSmoothingMode($hCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY) _GDIPlus_GraphicsSetTextRenderingHint($hCtxt, $GDIP_TEXTRENDERINGHINT_ANTIALIASGRIDFIT) _GDIPlus_BrushSetSolidColor($hBrush, $iColorText) DllStructSetData($tLayout, "x", 0) DllStructSetData($tLayout, "y", 0) _GDIPlus_GraphicsDrawStringEx($hCtxt, $sText, $hFont, $tLayout, $hFormat, $hBrush) _GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap_Blur, 0, 0) _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($hBrush) _GDIPlus_EffectDispose($hEffect) _GDIPlus_GraphicsDispose($hCtxt) _GDIPlus_BitmapDispose($hBitmap_Blur) EndFunc ;==>_GDIPlus_DrawShadowText Func _GDIPlus_Blur($tBlur, $fRadius, $bExpandEdge = False) If Not IsDllStruct($tBlur) Then Return SetError(1, @error, 0) DllStructSetData($tBlur, "radius", $fRadius) DllStructSetData($tBlur, "expandEdge", $bExpandEdge) Local $pEffect = _GDIPlus_EffectCreate($GDIP_BLUREFFECT) If @error Then Return SetError(2, @error, 0) _GDIPlus_EffectsSetParameters($pEffect, $tBlur) If @error Then Return SetError(3, @error, 0) Return $pEffect EndFunc ;==>_GDIPlus_Blur Func _GDIPlus_EffectCreate($sEffectGUID, $pEffect = 0) Local $iI, $tGUID, $pGUID, $tElem, $aElem[4], $aResult $tGUID = _WinAPI_GUIDFromString($sEffectGUID) $pGUID = DllStructGetPtr($tGUID) $tElem = DllStructCreate("uint[4]", $pGUID) For $iI = 1 To 4 $aElem[$iI - 1] = DllStructGetData($tElem, 1, $iI) Next $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateEffect", "uint", $aElem[0], "uint", $aElem[1], "uint", $aElem[2], "uint", $aElem[3], "uint*", $pEffect) If @error Then Return SetError(@error, @extended, 0) Return SetError($aResult[0], 0, $aResult[5]) EndFunc ;==>_GDIPlus_EffectCreate Func _GDIPlus_EffectsSetParameters($pEffectObject, $tEffectParameters, $iSizeAdj = 1) Local $aSize = DllCall($ghGDIPDll, "uint", "GdipGetEffectParameterSize", "ptr", $pEffectObject, "uint*", 0) Local $iSize = $aSize[2] * $iSizeAdj Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetEffectParameters", "ptr", $pEffectObject, "struct*", $tEffectParameters, "uint", $iSize) If @error Then Return SetError(@error, @extended, 0) Return SetError($aResult[0], 0, $aResult[3]) EndFunc ;==>_GDIPlus_EffectsSetParameters Func _GDIPlus_BitmapCreateApplyEffect($hBitmap, $pEffect, $pROI = 0, $tOutRect = 0, $hBmpOutput = 0) Local $aResult = DllCall($ghGDIPDll, "uint", "GdipBitmapCreateApplyEffect", _ "ptr*", $hBitmap, _ "int", 1, _ "ptr", $pEffect, _ "ptr", $pROI, _ "struct*", $tOutRect, _ "int*", $hBmpOutput, _ "int", 0, "ptr*", 0, "int*", 0) If @error Then Return SetError(@error, @extended, 0) Return SetError($aResult[0], 0, $aResult[6]) EndFunc ;==>_GDIPlus_BitmapCreateApplyEffect Func _GDIPlus_EffectDispose($pEffect) Local $aResult = DllCall($ghGDIPDll, "uint", "GdipDeleteEffect", "ptr", $pEffect) If @error Then Return SetError(@error, @extended, 0) Return SetError($aResult[0], 0, $aResult[0] = 0) EndFunc ;==>_GDIPlus_EffectDispose Requires AutoIt version 3.3.9.21 or higher and Windows Vista or later with enabled Aero theme! Br, UEZ1 point -
HelpFile is the first abettor for any function, make full use of it before asking for help1 point