Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 10/31/2012 in all areas

  1. Function Reference _AutoItErrorTrap.au3 UDF to intercept the error window of AutoIt, showing more details about the error, including ability to save and send by email! (Detection and treatment of errors in the AutoIt scripts!) Sintax: ; Adding the directives below, will cause your program be compiled with the indexing of the original lines shown in SciTE: #AutoIt3Wrapper_Run_Before=ShowOriginalLine.exe %in% #AutoIt3Wrapper_Run_After=ShowOriginalLine.exe %in% ;Or you can use the program "ShowOriginalLine.exe" directly and choose the script you want to add support to show the original lines! #include "_AutoItErrorTrap.au3" ; _AutoItErrorTrap ([sTitle [, sText [, fUseCallBack]]]) _AutoItErrorTrap()Supports: ;Error detection in your AutoIt script and local #Includes! ;According to the AutoIt Help, the definition for "local Includes" is: ;------------------------------------------------------------------------------ ;If "..." is used, the filename is taken to be relative to the current script. ;------------------------------------------------------------------------------ ;This means that for you to have your UDF or other external module with support to show the original lines, one should use as follows: #include "[path] filename" ; See the AutoIt help for more details.Downloads: Version: 0.11 _AutoItErrorTrap_(RedirectLink).html Note: The error detection is performed in the same executable, does not requiring opening two .exes for this action! Works with CUI too. Usage example is included! (You need to compile first, but it also work with non compiled scripts using context menu [Run Script...]) Sample: More sample: Fixes: #ShowLine_Off $hForm = GUICreate("My GUI menu", 480, 360) $iFileMenu = GUICtrlCreateMenu("&File") $iFileItem = GUICtrlCreateMenuItem("Open", $iFileMenu) GUICtrlSetState(-1, $GUI_DEFBUTTON) $iHelpMenu = GUICtrlCreateMenu("?") GUICtrlCreateMenuItem("Save", $iFileMenu) GUICtrlSetState(-1, $GUI_DISABLE) #ShowLine_OnWithout them the rows above would be as follows: $__iLineNumber=1 & " - " & '$hForm = GUICreate("My GUI menu", 480, 360)...' $hForm = GUICreate("My GUI menu", 480, 360) $__iLineNumber=3 & " - " & '$iFileMenu = GUICtrlCreateMenu("&File")' $iFileMenu = GUICtrlCreateMenu("&File") $__iLineNumber=4 & " - " & '$iFileItem = GUICtrlCreateMenuItem("Ope...' $iFileItem = GUICtrlCreateMenuItem("Open", $iFileMenu) $__iLineNumber=5 & " - " & 'GUICtrlSetState(-1, $GUI_DEFBUTTON)' GUICtrlSetState(-1, $GUI_DEFBUTTON) $__iLineNumber=6 & " - " & '$iHelpMenu = GUICtrlCreateMenu("?")' $iHelpMenu = GUICtrlCreateMenu("?") $__iLineNumber=7 & " - " & 'GUICtrlCreateMenuItem("Save", $iFileMenu)' GUICtrlCreateMenuItem("Save", $iFileMenu) $__iLineNumber=8 & " - " & 'GUICtrlSetState(-1, $GUI_DISABLE)' GUICtrlSetState(-1, $GUI_DISABLE) And the directive #ShowOriginalLine_Param with the following options: /SV or /SkipAllVars ; Skip all Variables to show original line numbers. /SG or /SkipGlobalVars ; Skip Global Variables to show original line numbers. /SL or /SkipLocalVars ; Skip Local Variables to show original line numbers.29/10/2012 -> *Adding the directives below, will cause your program be compiled with the indexing of the original lines shown in SciTE: #AutoIt3Wrapper_Run_Before=ShowOriginalLine.exe %in% #AutoIt3Wrapper_Run_After=ShowOriginalLine.exe %in%*Or you can use the program ShowOriginalLine.exe directly and choose the script you want to add support to show the original lines!*It was added #region Translations with the variables available for translation! 0.10.2312.2600b 25/10/2012 -> Added support for viewing the last screen before the error! Now the window can expand and retract again...Change the hook CALLWNDRETPROC to CALLWNDPROC (better...). Added a help button [?] In the main window and minor changes in the code. 0.10.2312.2600b 23/10/2012 -> *Added support to display the original line numbers in the scripts compiled! Thanks to @FireFox for this tip! $hAET_GETERROR = StringRegExpReplace($hAET_GETERROR, "d+[0-9]", Eval("__iLineNumber") & @CRLF)*Additional information suggested by @ricky03, thank you!*Some bugs were fixed and the file ShowOriginalLineNumbers.au3 was added in zip file. 0.10.2112.2600b 21/10/2012 -> Bugs were fixed and a few functions have been rewritten!0.10.1912.2600b 19/10/2012 -> The UDF was almost completely rewritten, now no longer need to include _AdlibEnhance.au3.The detection of error is instant and does not consume more CPU. Interface compatibility with Windows XP 0.10.1812.2600b 18/10/2012 -> Improvements such as icons on the buttons and added a button to save the error information!0.10.1712.2600b 17/10/2012 -> First release!Regards, João Carlos.
    1 point
  2. JScript

    Question about Regex...

    Hello guys! I have a doubt that for many can be quite simple to solve, but unfortunately I do not understand almost nothing of regex! I wanted to know how to identify only the character _ at the end of the line indicating that it continues in the next line... Example: MsgBox(4096, "Title _ v1", "This program is free software: you can redistribute it and/or modify" & _ 'it under the terms of the GNU General Public License " _"' & _ ; Only comment! "as published by the Free Software Foundation, either version 3" & _ "of the License, or (at your option) any later version.") If anyone can help me I'll be very grateful! Edit: Another example: $aRtl = DllCall("ntdll.dll", "int", "RtlCompressBuffer", _ "ushort", 2, _ ;------> CompressFormat "ptr", $pInput, _ ;---> ptrSrceBuffer "dword", $iSize, _ ;--> SrceBufferSize "ptr", $pBuffer, _ ;--> ptrDestBuffer "dword", $iBufLen, _ ;> DestBufferSize "dword", 4096, _ ;----> ChunkSize "dword*", 0, _ ;------> CompressedSize "ptr", $pWrkSp) ;-----> WorkspaceBuffer thankful, JS
    1 point
  3. In this example from the help file (GUICtrlCreateListViewItem) it does work: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> Example() Func Example() Local $listview, $button, $item1, $item2, $item3, $msg GUICreate("listview items", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES) GUISetBkColor(0x00E0FFFF) ; will change background color $listview = GUICtrlCreateListView("col1 |col2|col3 ", 10, 10, 200, 150);,$LVS_SORTDESCENDING) $button = GUICtrlCreateButton("Value?", 75, 170, 70, 20) $item1 = GUICtrlCreateListViewItem("item2|col22|col23", $listview) $item2 = GUICtrlCreateListViewItem("............item1|col12|col13", $listview) $item3 = GUICtrlCreateListViewItem("item3|col32|col33", $listview) GUICtrlCreateInput("", 20, 200, 150) GUICtrlSetState(-1, $GUI_DROPACCEPTED) ; to allow drag and dropping GUISetState() Local $hLV = GUICtrlGetHandle( $listview ) MsgBox( 0,"", _GUICtrlListView_GetItemParam($hLV, 0) ) ; <---------------------------------------- GUICtrlSetData($item2, "|ITEM1") GUICtrlSetData($item3, "||COL33") GUICtrlDelete($item1) Do $msg = GUIGetMsg() Select Case $msg = $button MsgBox(0, "listview item", GUICtrlRead(GUICtrlRead($listview)), 2) Case $msg = $listview MsgBox(0, "listview", "clicked=" & GUICtrlGetState($listview), 2) EndSelect Until $msg = $GUI_EVENT_CLOSE EndFunc ;==>Example Lars.
    1 point
  4. Mechaflash

    Send Mail

    May I recommend a loud speaker for a life threatening emergency as opposed to an email for one? XD
    1 point
  5. Hi, I was asked to look at this thread as it mentions "login". As it is only a simple dialog box that needs to be automated and is not a "forum or site auto-login" I am happy for the thread to continue. ogloed, I suggest you use the Window Info tool (Your_AutoIt_PathAutoIt3Au3Info.exe) to get the information on that dialog GUI and controls and then look at ControlSend/Click in the Help file. You will find the <Using AutoIt - Window Titles and Text (Advanced)> page of the Help file (scroll down to the bottom) useful as well so that you know what it is you need to put in the various parameters of those functions. M23
    1 point
  6. JScript

    Question about Regex...

    @PhoenixXL Very nice, thank you!!! @Varian Of all the tests I did was his example was what went right but as was said in the post above, I believe that may fail in some cases, although it has not failed with me! @jchd You hit the point... I thank everyone for their efforts in helping me! JS
    1 point
  7. jchd

    Question about Regex...

    Detecting AutoIt statement continuation requires parsing from the left hand and implies actual parsing of the syntax. Ad hoc patterns can do it in a restricted number of cases, but certainly not in all cases. I don't believe a simple regexp can be produced to this effect and, should one ever pop up, it would be fairly complex and unmaintainable. This is a job for a lexer.
    1 point
  8. Varian

    Question about Regex...

    This captures each line that ends with an underscore or ends with an underscore & a comment; This returns the entire matched line up to the underscore #include <Array.au3> Local $iString $iString &= 'MsgBox(4096, "Title _ v1", "This program is free software: you can redistribute it and/or modify" & _' & @LF $iString &= ' "it under the terms of the GNU General Public License " _" & _ ; Only comment!' & @LF $iString &= ' "as published by the Free Software Foundation, either version 3" & _' & @LF $iString &= ' "of the License, or (at your option) any later version.")' & @LF $iString &= '$aRtl = DllCall("ntdll.dll", "int", "RtlCompressBuffer", _' & @LF $iString &= ' "ushort", 2, _ ;------> CompressFormat' & @LF $iString &= ' "ptr", $pInput, _ ;---> ptrSrceBuffer' & @LF $iString &= ' "dword", $iSize, _ ;--> SrceBufferSize' & @LF $iString &= ' "ptr", $pBuffer, _ ;--> ptrDestBuffer' & @LF $iString &= ' "dword", $iBufLen, _ ;> DestBufferSize' & @LF $iString &= ' "dword", 4096, _ ;----> ChunkSize' & @LF $iString &= ' "dword*", 0, _ ;------> CompressedSize' & @LF $iString &= ' "ptr", $pWrkSp) ;-----> WorkspaceBuffer' & @LF $iString &= '_ ; Only comment!' MsgBox(262208, 'Original String', $iString) RegEx($iString) Func RegEx($nString) Local $nPattern = "(?m)(^.*_)(?:s*$|s*;.*s*$)" ConsoleWrite($nPattern & @CR) Local $nRegex = StringRegExp($nString, $nPattern, 3) If @error Then Exit @extended _ArrayDisplay($nRegex) EndFunc ;==>RegEx
    1 point
  9. jchd

    StringRegExp General Help

    You're over-complicating the pattern. "([^"]*)" will do in that precise case.
    1 point
  10. This might helpFunc MatchSingleScores($nString) Local $nPattern = "['" & '"]' & ".*" & "['" & '"]' ;~ ConsoleWrite($nPattern & @CR) ;Remove String enclosed in Quotes Local $nRegEx = StringRegExpReplace($nString, $nPattern, '') If @error Then Exit @extended ;Remove Comments $nPattern = ";.*" $nRegEx = StringRegExpReplace($nRegEx, $nPattern, '') ;Return Match Return StringRegExp($nRegEx,' _') EndFunc ;==>ReplaceScores If MatchSingleScores(' "Hello there" _ ;This is a comment' & @CRLF _ & ' "This is the Second Line"') Then Exit ConsoleWrite('Underscore is There!'&@CR)=0 Exit ConsoleWrite('No Match Found')=0
    1 point
  11. PhoenixXL

    Recursive vs Iterative

    Iteration Wins Global $nReset = 1000 Local $Timer = TimerInit() _Recursion() ConsoleWrite('Recursion TimerDiff:' & TimerDiff($Timer) & @CR) $Timer = TimerInit() _Iteration() ConsoleWrite('Iteration TimerDiff:' & TimerDiff($Timer)) ;Recursion Func _Recursion() Static $nStart = 0 For $n = 0 To 1000 ;Anything Next $nStart += 1 If $nStart < $nReset Then Return _Recursion() Return 1 EndFunc ;==>_Recursion ;Iteration Func _Iteration() Local $nStart = 0 While $nStart < $nReset For $n = 0 To 1000 ;Anything Next $nStart += 1 WEnd Return 1 EndFunc ;==>_Iteration
    1 point
  12. Bert

    Question about Regex...

    have you thought of trying the RegEx tool that is part of the help file? Look for the Tutorial - Regular Expression in the help file and at the bottom is the script button for the tool.
    1 point
  13. czardas

    Question about Regex...

    This isn't quite working and I don't know why. I decided to post my attemps anyway, in case it turns out to be useful and that I might also learn something. #include <Array.au3> $sString = "This program is free software: you can redistribute it and/or modify & _" & @CRLF & _ 'it under the terms of the GNU General Public License " _" & _ ; Only comment!' & @CRLF & _ ; Only comment! "as published by the Free Software Foundation, either version 3 & _" & @CRLF & _ "of the License, or (at your option) any later version." $regExp = "(&h+_h*(;.*)?)" $aArray = StringRegExp($sString, $regExp, 3) _ArrayDisplay($aArray) Anyway I believe it is customary to strip away all comments before parsing. I would just concatenate strings ending with underscore using StringReplace. Edit I believe the above RegExp approach is not suitable in most circumstances. It is inefficient and my example (besides being broken) does not cater for matches found within strings. There may be simpler ways than using RegExp, depending on what you want to achieve.
    1 point
  14. Unit testing is a basic requirement of any development that want to be stable and guarantee non-regression. AutoIt was missing a unit testing framework at the moment where I wrote this. Micro is a very simple unit testing framework with a focus on being easy to use. Features: Tests aggregation into test suites.Various assertion methods are available.Output can be easily customizedReport the percentage success and number of failure and successesProject page Best regards.
    1 point
  15. Do you know what's the difference between integer and double-precision number? Local $iInteger = 10 Local $fDouble = 2 * $iInteger / 2 ConsoleWrite("Integer, value = " & $iInteger & ", Hex representation = " & Hex($iInteger) & @CRLF) ConsoleWrite("Double, value = " & $fDouble & ", Hex representation = " & Hex($fDouble) & @CRLF) You are seeing just that. Both numbers are 10, but former is integer and latter is not. Your mathematical operation changed the type of the variable. If you want your number to be integer then you have to Int() it. Hex() shows binary representation of the number which is exactly how it's stored in memory of your computer.
    1 point
  16. UEZ

    Watermarking an image

    Try this: ;coded by UEZ #include <GDIPlus.au3> _GDIPlus_Startup() $sIn = StringReplace(@AutoItExe, "autoit3.exe", "Examples\GUI\msoobe.jpg") ;this will not work when script is compiled $sOut = @ScriptDir & "\Watermarked.jpg" FileDelete($sOut) $r = _GDIPlus_WatermarkImage($sIn, $sOut, "Watermarked by UEZ", 50, 50, 2, "Arial", 64, 0, 100) _GDIPlus_Shutdown() If $r Then ShellExecute($sOut) Exit ;====================================================================================== ; Function Name: _GDIPlus_WatermarkImage ; Description: adds a text to an image ; ; Parameters: $sBitmapFile: image file to load ; $sSave: filename for saved image -> if no extension (jpg, bmp, png, gif, tif) is given the default is png image format ; $sText: text string to draw onto the image ; $iX: x position of the text on the image ; $iY: y position of the text on the image ; ;Optional: $iPos: possition text to one of 9 possitions on the image. If set $iX and $iY will be ignored! ; 0: turned off ; 1: upper left, 2: upper mid, 3: upper right ; 4: mid left, 5: center, 6: mid right ; 7: buttom left, 8: buttom mid, 9: buttom right ; $sFontName: font name to use, default is Arial ; $iFontSize: size of the font, default is 16 ; $fAngle: angle of the text -> 0° - 359° ; $iAdjY: adjust y position of the text when $iPos is selected ; $iAdjX: adjust x position of the text when $iPos is selected ; $iFontColor: color of the text ; $fAlpha: alpha channel of the text -> 0.0 (transparent) - 1.0 (opaque) ; $iJPGQuality: JPG save quality -> 0 (worst) - 100 (best) ; ; Requirement(s): GDIPlus.au3 ; Return Value(s): Success: 1 or the handle of the bitmap (don't forget to dispose it when done!) ; Error: ; Error codes: 1: image file to load not found ; 2: unable to create bitmap from loaded image ; 3: unable to save watermarked image ; ; Remark: don't forget to start _GDIPlus_Startup() / _GDIPlus_Shutdown() ; ; Author(s): UEZ ; Version: v1.00 Build 2012-10-31 Beta ;======================================================================================= Func _GDIPlus_WatermarkImage($sBitmapFile, $sSave, $sText, $iX, $iY, $iPos = 0, $sFontName = "Arial", $iFontSize = 16, $fAngle = 0, $iAdjY = 0, $iAdjX = 0, $iFontColor = 0xFFFFFF, $fAlpha = 0.04, $iJPGQuality = 90, $bLineBreak = True) If Not FileExists($sBitmapFile) Then Return SetError(1, 0, 0) Local $hBitmap = _GDIPlus_BitmapCreateFromFile($sBitmapFile) If Not $hBitmap Then Return SetError(2, 0, 0) If $fAlpha < 0 Then $fAlpha = 0 If $fAlpha > 1 Then $fAlpha = 1 Local $iW = _GDIPlus_ImageGetWidth($hBitmap) , $iH = _GDIPlus_ImageGetHeight($hBitmap) Local $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) Local $hBrush = _GDIPlus_BrushCreateSolid(BitShift(Int($fAlpha * 0xFF), -24) + $iFontColor) Local $hFormat = _GDIPlus_StringFormatCreate() Local $hFamily = _GDIPlus_FontFamilyCreate($sFontName) Local $hFont = _GDIPlus_FontCreate($hFamily, $iFontSize, 0) Local $tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0) Local $aMeasure = _GDIPlus_GraphicsMeasureString($hCtxt, $sText, $hFont, $tLayout, $hFormat) Local $iWTxt = Ceiling(DllStructGetData($aMeasure[0], "width") ) Local $iHTxt = Ceiling(DllStructGetData($aMeasure[0], "height")) If Not $fAngle Then _GDIPlus_GraphicsSetSmoothingMode($hCtxt, 2) DllCall($ghGDIPDll, "uint", "GdipSetTextRenderingHint", "handle", $hCtxt, "int", 4) If $bLineBreak And $iWTxt > $iW Then DllStructSetData($tLayout, "width", $iW) DllStructSetData($tLayout, "height", 0) $aMeasure = _GDIPlus_GraphicsMeasureString($hCtxt, $sText, $hFont, $tLayout, $hFormat) $iWTxt = Ceiling(DllStructGetData($aMeasure[0], "width") ) $iHTxt = Ceiling(DllStructGetData($aMeasure[0], "height")) EndIf If Not Int($iPos) Or Int($iPos) > 9 Then DllStructSetData($tLayout, "x", $iX) DllStructSetData($tLayout, "y", $iY) _GDIPlus_GraphicsDrawStringEx($hCtxt, $sText, $hFont, $tLayout, $hFormat, $hBrush) Else DllStructSetData($tLayout, "x", $iAdjX) DllStructSetData($tLayout, "width", $iW) Switch $iPos Case 1 To 3 DllStructSetData($tLayout, "y", $iAdjY) _GDIPlus_StringFormatSetAlign($hFormat, $iPos - 1) Case 4 To 6 DllStructSetData($tLayout, "y", ($iH - $iHTxt) / 2 + $iAdjY) _GDIPlus_StringFormatSetAlign($hFormat, $iPos - 4) Case 7 To 9 DllStructSetData($tLayout, "y", $iH - $iHTxt + $iAdjY) _GDIPlus_StringFormatSetAlign($hFormat, $iPos - 7) EndSwitch _GDIPlus_GraphicsDrawStringEx($hCtxt, $sText, $hFont, $tLayout, $hFormat, $hBrush) EndIf Else Local $iQ $fAngle = Mod($fAngle, 360) $iW = Int(DllStructGetData($aMeasure[0], "width") * 2) $iH = Int(DllStructGetData($aMeasure[0], "height") * 2) If $iW > $iH Then $iQ = $iW Else $iQ = $iH EndIf Local $hBitmap_Rot = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iQ, "int", $iQ, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0) $hBitmap_Rot = $hBitmap_Rot[6] Local $hCtxt_Rot = _GDIPlus_ImageGetGraphicsContext($hBitmap_Rot) _GDIPlus_GraphicsSetSmoothingMode($hCtxt_Rot, 2) DllCall($ghGDIPDll, "uint", "GdipSetTextRenderingHint", "handle", $hCtxt_Rot, "int", 4) Local $hMatrix = _GDIPlus_MatrixCreate() _GDIPlus_MatrixTranslate($hMatrix, $iQ / 2, $iQ / 2) _GDIPlus_MatrixRotate($hMatrix, $fAngle, False) _GDIPlus_MatrixTranslate($hMatrix, -$iQ / 2, -$iQ / 2) _GDIPlus_GraphicsSetTransform($hCtxt_Rot, $hMatrix) DllStructSetData($tLayout, "x", $iQ / 2) DllStructSetData($tLayout, "y", $iQ / 2) _GDIPlus_GraphicsDrawStringEx($hCtxt_Rot, $sText, $hFont, $tLayout, $hFormat, $hBrush) _GDIPlus_GraphicsDrawImageRect($hCtxt, $hBitmap_Rot, $iX - $iQ / 2, $iY - $iQ / 2, $iQ, $iQ) _GDIPlus_MatrixDispose($hMatrix) _GDIPlus_GraphicsDispose($hCtxt_Rot) _GDIPlus_BitmapDispose($hBitmap_Rot) EndIf _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hCtxt) $tLayout = 0 If $sSave <> "" Then Local $bRes If StringRight($sSave, 4) = ".jpg" Then Local Const $sCLSID = _GDIPlus_EncodersGetCLSID("JPG") Local $tParams = _GDIPlus_ParamInit(1) Local $tData = DllStructCreate("int Quality") If $iJPGQuality < 0 Then $iJPGQuality = 0 If $iJPGQuality > 100 Then $iJPGQuality = 100 DllStructSetData($tData, "Quality", $iJPGQuality) Local $pData = DllStructGetPtr($tData) _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData) Local Const $pParams = DllStructGetPtr($tParams) $bRes = _GDIPlus_ImageSaveToFileEx($hBitmap, $sSave, $sCLSID, $pParams) $tData = 0 $tParams = 0 Else StringRegExp($sSave, ".*.(gif|png|bmp|tif)", 1) If @error Then If StringRight($sSave, 1) = "." Then $sSave &= "png" Else $sSave &= ".png" EndIf EndIf $bRes = _GDIPlus_ImageSaveToFile($hBitmap, $sSave) EndIf _GDIPlus_BitmapDispose($hBitmap) If Not $bRes Then Return SetError(3, 0, 0) Return 1 EndIf Return $hBitmap EndFunc Edit1: forgot 2 lines which are added now Edit2: added some more features Edit3: the backslashes were gone - added again Br, UEZ
    1 point
×
×
  • Create New...