Leaderboard
Popular Content
Showing content with the highest reputation on 01/07/2013 in all areas
-
OnAutoItErrorRegister - Handle AutoIt critical errors
GoogleDude reacted to MrCreatoR for a topic
AutoIt Version: 3.3.10.2+ UDF Version: 2.0 Description: This library allows to register function for AutoIt critical errors. Usually it's syntax errors, or array-related errors. By default the UDF shows custom debug dialog, although it is not possible to perform any real debugging, but we can for example display the error message, restart application, send bug report, or just close the application. Example #1 - Displaying built-in dialog when error is received: #NoTrayIcon #AutoIt3Wrapper_Run_Before=%autoitdir%\AutoIt3.exe /AutoIt3ExecuteLine "FileClose(FileOpen('%scriptdir%\OAER_RAW_SRC.tmp', 2))" #AutoIt3Wrapper_Run_After=%autoitdir%\AutoIt3.exe /AutoIt3ExecuteLine "FileDelete('%scriptdir%\OAER_RAW_SRC.tmp')" #include <GUIConstantsEx.au3> #include 'OnAutoItErrorRegister.au3' _OnAutoItErrorRegister('', '', 'My App Error', False, False) GUICreate('OnAutoItErrorRegister Example', 350, 200) GUICtrlCreateLabel('This script is just an example.' & @CRLF & @CRLF & 'It will produce a syntax error in', 25, 40, 300, 50) GUICtrlCreateLabel('5', 185, 50, 50, 40) GUICtrlSetColor(-1, 0xF20000) GUICtrlSetFont(-1, 30, 800, 0, 'Tahoma') GUICtrlCreateLabel('seconds.', 220, 67, 300, 50) GUICtrlCreateLabel('The result shown as a CUSTOM error message, you can change it!', 25, 120, 350, 20) $iUnRegister_Bttn = GUICtrlCreateButton('UnRegister AutoItError handler', 25, 140, 200, 22) GUICtrlCreateLabel('Copyright jennico, G.Sandler (MrCreatoR) © 2008 - 2015', 25, 170, 350, 80) GUICtrlSetColor(-1, 0x808080) GUICtrlSetFont(-1, 8.5, 800, 6) GUISetState() Dim $iTimer For $i = 3 To 1 Step -1 GUICtrlSetData(4, $i) $iTimer = TimerInit() While TimerDiff($iTimer) < 1000 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $iUnRegister_Bttn _OnAutoItErrorUnRegister() EndSwitch WEnd Next ;We deliberately make a syntax mistake and call the error! If Random(1, 5, 1) = 3 Then MsgBox(0, '', ) Else _NotExistingFunc() EndIf Example #2 - Call user defined function when receiving error (script restart): #NoTrayIcon #AutoIt3Wrapper_Run_AU3Check=n ;!!! This must be used to ensure that raw source file is generated before compilation (because $bSetErrLine is True) #AutoIt3Wrapper_Run_Before=%autoitdir%\AutoIt3.exe "%in%" /BC_Strip #AutoIt3Wrapper_Run_After=%autoitdir%\AutoIt3.exe /AutoIt3ExecuteLine "FileDelete('%scriptdir%\OAER_RAW_SRC.tmp')" #pragma compile(Stripper, False) #include 'OnAutoItErrorRegister.au3' _OnAutoItErrorRegister('_MyErrorHandler', '', '', False, True) ;We deliberately make an array bounding error and call the error! Dim $aArr[1] MsgBox(0, '', $aArr[1]) Func _MyErrorHandler($sScriptPath, $iScriptLine, $sErrDesc, $vParams, $hBitmap) ;Restart the application Local $sMessage = StringFormat('SCRIPT FILE:\n%s\n\nSCRIPT ERROR LINE:\n%s\n\nERROR DESCRIPTION:\n%s', $sScriptPath, $iScriptLine, $sErrDesc) If StringInStr($CmdLineRaw, '/ErrorStdOut') Then If FileExists(@WindowsDir & "\Media\chord.wav") Then SoundPlay(@WindowsDir & "\Media\chord.wav") Else DllCall('user32.dll', 'int', 'MessageBeep', 'int', 0x00000010) EndIf EndIf If MsgBox(BitOR($MB_SYSTEMMODAL, $MB_YESNO), 'Crash recieved!', 'Restart application?' & @CRLF & @CRLF & $sMessage) <> 6 Then Return EndIf Local $sRunLine = @AutoItExe & ' "' & @ScriptFullPath & '"' If @Compiled Then $sRunLine = @ScriptFullPath EndIf Run($sRunLine, @ScriptDir) EndFunc Download: OnAutoItErrorRegister.zip (Counter: ) Screenshot: ChangeLog: Initial idea by jennico: Author(s): G.Sandler (MrCreatoR), jennico Notes: The UDF can not handle crashes that triggered by memory leaks, such as DllCall crashes, "Recursion level has been exceeded..." (when using hook method ($bUseStdOut = False)).When using StdOut method ($bUseStdOut = True), CUI not supported, and additional process executed to allow monitor for errors.After using _OnAutoItErrorUnRegister when $bUseStdOut = True, standard AutoIt error message will not be displayed on following syntax error.To use the "Send bug report" feature, there is need to fill related parameters (variables) under the «User Variables» section in UDF file (check the comments of these variables), or just build your own user function.[If $bSetErrLine is True...] Script must be executed before compilation (after any change in it), or use '#AutoIt3Wrapper_Run_Before=%autoitdir%\AutoIt3.exe "%in%" /BC_Strip' in your main script. Do NOT use Au3Stripper when compiling the main script if you want correct error line detection for compiled script. To get correct code line for compiled script, the script is transformed to raw source (merging includes) and FileInstall'ed when it's needed (on error), therefore, the script is available in temp dir for few moments (when error is triggered), although it's crypted, but developer should ensure that his script is more protected. [If $bSetErrLine is False...] Use supplied GetErrLineCode.au3 to get proper error line code by line number from error that was triggered in compiled script.1 point -
is there a more appropriate forum for beginners?
FireFox reacted to JLogan3o13 for a topic
HAAAAAAAAAAhahahaahahahaahahahahahahahahaahahahahah!!!!!1 point -
Delete array
jackraymund reacted to trancexx for a topic
@jackraymund, just reassign the $array variable. $array = 0 ; <- array no more ...guiness likely misunderstood you.1 point -
Delete array
jackraymund reacted to guinness for a topic
Well I don't get an error with your code or the one below. Therefore you have either an old version of AutoIt or are failing to mention some important details. Global $aArray[2] = [0, 1] MsgBox(4096, '', $aArray[1] & ', ' & (IsArray($aArray) == 1))1 point -
Unicode Compatible Title Case This topic has come up quite a lot lately and the following code is really an experiment. Problems associated with proper case are not all possible to resolve. Differentiating between words and acronyms, or identifying common exceptions such as Scottish names beginning Mac or Mc, is very hard. MC is also a Roman numeral. The function does not attempt any of these things. Instead it avoids altering anything which may already be correct. It will not touch abbreviations such as BBC or website URLs and it also caters for various types of hyphenation and apostrophies. You have the option to ignore small word exceptions which are not capitalized in standard British English. After you have run the example try using the function on the actual code itself. Mainly the comments will be capitalized and the code will remain mainly untouched and still run, because pre-existing capitals are presumed to be correct. I wrote all the comments in lower case on purpose so you could try this. Rules and Guidelines #include-once #include <Array.au3> #include <String.au3> Example() Func Example() Local $sExample = _ "the great rock 'n roll swindle" & @LF & _ "old McDonnald had a farm" & @LF & _ "download AutoIt from autoitscript.com." & @LF & _ "download win-1252 from autoitscript.com/forum/topic/135167-win-1252-extended-keyboard/" & @LF & _ "from the 14th to the 21st century" & @LF & _ "BBC iTunes II III IV" & @LF & _ "la época de los árabes" & @LF & _ "on (and on) and on" & @LF & _ "on top of old smokey" & @LF & _ "she's got x-ray vision" & @LF & _ "one,two,three,four" & @LF & _ "werner von bruin" & @LF & _ "paco de lucía y camarón de la isla" ConsoleWrite(_TitleCase($sExample, Default, Default, True) & @LF) EndFunc ;==> Example() Func _TitleCase($sText, $bAP_Exceptions = True, $bIgnoreCaps = True, $bInternational = False, $bIgnoreURL = True) If Not StringLen($sText) Then Return SetError(1, 0, $sText) ; nothing to parse If $bAP_Exceptions = Default Then $bAP_Exceptions = True If $bIgnoreCaps = Default Then $bIgnoreCaps = True If $bInternational = Default Then $bInternational = False If $bIgnoreURL = Default Then $bIgnoreURL = True Local $sWSLeft = "", $sWSRight = "", $sCurrChar For $i = 1 To StringLen($sText) $sCurrChar = StringMid($sText, $i, 1) If StringRegExp($sCurrChar, "\s") Then $sWSLeft &= $sCurrChar ; get leading WS Else ExitLoop EndIf Next For $i = StringLen($sText) To 1 Step -1 $sCurrChar = StringMid($sText, $i, 1) If StringRegExp($sCurrChar, "\s") Then $sWSRight = $sCurrChar & $sWSRight ; get trailing WS Else ExitLoop EndIf Next $sText = StringStripWS($sText, 3) ; remove leading and trailing WS Local $sNewStr = "", $sRegExp = "[0-9]|_", $bExceptions = False If $bIgnoreURL Then $sRegExp &= "|\\|/|(\.\w)" If $bIgnoreCaps Then $sRegExp &= "|[A-Z]" Else $sText = StringLower($sText) EndIf If StringRegExp($sText, $sRegExp) Then ; exceptions may be case sensitive, or include abbreviations $bExceptions = True Local $aArray = StringRegExp($sText, "\A\S+|(\s+\S+)|\s+\z", 3), _ ; find any WS characters followed by any none WS characters $aSubs = _GetMultiSubs($sText, 1) If @error Then Return SetError(2, 0, $sText) ; no suitable delimiter available For $i = 0 To UBound($aArray) -1 $aArray[$i] = StringStripWS($aArray[$i], 1) If Not StringInStr($sNewStr, $aSubs[0] & $aArray[$i], 1) Then $sNewStr &= $aSubs[0] & $aArray[$i] ; get unique exceptions Next $aArray = StringSplit($sNewStr, $aSubs[0], 3) ; overwrite the original array with an array of unique matches $aArray[0] = UBound($aArray) -1 ; get the number of unique matches _ArraySortByLen($aArray, 1, 1) ; reverse order the elements by length. If @error Then Return SetError(3, 0, $sText) ; failure to arrange by element length Local $aIgnore[UBound($aArray) -1], $iCount = 0 ; don't touch - web stuff, or words containing underscore, capitals or numbers For $i = 1 To $aArray[0] If StringRegExp($aArray[$i], $sRegExp) Then $aIgnore[$iCount] = $aArray[$i] ; string to replace $iCount += 1 EndIf Next $aArray = 0 ; no longer needed ReDim $aIgnore[$iCount] $aSubs = _GetMultiSubs($sText, $iCount) If @error Then Return SetError(2, 0, "") ; insufficient substitutes strings available For $i = 0 To $iCount -1 $aSubs[$i] = " " & $aSubs[$i] & " " ; add padding to the replacements $sText = StringReplace($sText, $aIgnore[$i], $aSubs[$i], 0, 1) ; replace all the exceptions Next EndIf Local $CapsNext = 1, $sHyphens = ChrW(8211) & ChrW(8212) & ChrW(173) & "-'" ; en dash, em dash, soft hyphen, hyphen and apostrophe $sNewStr = "" For $i = 1 To StringLen($sText) ; modified code from JCHD $sCurrChar = StringMid($sText, $i, 1) If StringIsAlpha($sCurrChar) Then If $CapsNext Then $sCurrChar = StringUpper($sCurrChar) $CapsNext = 0 EndIf ElseIf StringInStr($sHyphens, $sCurrChar) Then ; changes to the original - hyphenation and apostrophe $CapsNext = 0 Else $CapsNext = 1 EndIf $sNewStr &= $sCurrChar Next If $bAP_Exceptions Then Local $aConj[24] = _ ["A","An","And","As","At","But","By","For", _ "From","In","Into","Nor","Of","On","Onto","Or", _ "Per","So","The","To","Up","Via","With","Yet"] For $i = 0 To 23 $sNewStr = StringReplace($sNewStr, " " & $aConj[$i] & " ", " " & StringLower($aConj[$i]) & " ") $sNewStr = StringReplace($sNewStr, "(" & $aConj[$i] & " ", "(" & StringLower($aConj[$i]) & " ") $sNewStr = StringReplace($sNewStr, " " & $aConj[$i] & ")", " " & StringLower($aConj[$i]) & ")") Next EndIf If $bInternational Then Local $aPartName[20] = _ [" Af "," Av "," Da "," De "," Del "," Der "," Di ", _ " E "," En "," Et "," Het "," La "," Las "," Lo ", _ " Los "," Und "," Van De "," Van Der "," Von "," Y "] For $i = 0 To 19 $sNewStr = StringReplace($sNewStr, $aPartName[$i], StringLower($aPartName[$i])) Next EndIf If $bExceptions Then For $i = $iCount -1 To 0 Step -1 ; put all the exceptions back in the new string $sNewStr = StringReplace($sNewStr, $aSubs[$i], $aIgnore[$i]) Next EndIf $sNewStr = $sWSLeft & $sNewStr & $sWSRight Return $sNewStr EndFunc ;==> _TitleCase() Func _GetMultiSubs($sTest, $iSubs) If Not IsString($sTest) Then Return SetError(1, 0, 0) ; Invalid Input String. If Not IsInt($iSubs) Or $iSubs < 1 Then Return SetError(2, 0, 0) ; Invalid number of substitute strings ; NOTE: The returned order of substitutes may be important. ; Extra padding may be needed to avoid substitutes coming into contact with other control characters. Local $aSubs[$iSubs], $aAscII[31], $iCount = 0, $sChar ; Using Control Characters only. ; First try one character For $i = 1 To 31 $sChar = Chr($i) If Not StringInStr($sTest, $sChar, 1) Then $aSubs[$iCount] = $sChar $iCount +=1 If $iCount = $iSubs Then Return $aSubs EndIf $aAscII[$i - 1] = $sChar ; Needed for the next stage. Next ; That failed - so we try two characters. Local $aDoubleChar = _ArrayCombinations($aAscII, 2, "") For $i = 1 To $aDoubleChar[0] $sChar = $aDoubleChar[$i] If Not StringInStr($sTest, $sChar, 1) Then $aSubs[$iCount] = $sChar $iCount +=1 If $iCount = $iSubs Then Return $aSubs EndIf Next ; That failed - so we try the reverse patterns. ReDim $aDoubleChar[931] $aDoubleChar[0] = 930 For $i = 466 To $aDoubleChar[0] $sChar = _StringReverse($aDoubleChar[$i -465]) If Not StringInStr($sTest, $sChar, 1) Then $aSubs[$iCount] = $sChar $iCount +=1 If $iCount = $iSubs Then Return $aSubs EndIf $aDoubleChar[$i] = $sChar ; Needed for the next stage. Next ; That failed - so we try three characters. For $i = 1 To $aDoubleChar[0] For $j = 0 To 30 $sChar = $aDoubleChar[$i] & $aAscII[$j] If Not StringInStr($sTest, $sChar, 1) Then $aSubs[$iCount] = $sChar $iCount +=1 If $iCount = $iSubs Then Return $aSubs EndIf Next Next ; That failed - so we try four characters. For $i = 1 To $aDoubleChar[0] For $j = 1 To $aDoubleChar[0] $sChar = $aDoubleChar[$i] & $aDoubleChar[$j] If Not StringInStr($sTest, $sChar, 1) Then $aSubs[$iCount] = $sChar $iCount +=1 If $iCount = $iSubs Then Return $aSubs EndIf Next Next ; That failed - so we try five characters. For $i = 1 To $aDoubleChar[0] For $j = 1 To $aDoubleChar[0] For $k = 0 To 30 $sChar = $aDoubleChar[$i] & $aDoubleChar[$j] & $aAscII[$k] If Not StringInStr($sTest, $sChar, 1) Then $aSubs[$iCount] = $sChar $iCount +=1 If $iCount = $iSubs Then Return $aSubs EndIf Next Next Next Return SetError (2, 0, "") ; Not enough substitutions available EndFunc ; _GetMultiSubs() Func _ArraySortByLen(ByRef $aArray, $iDescending =0, $iStart =0, $iEnd =0) If Not IsArray($aArray) Or UBound($aArray, 0) > 1 Then Return SetError(1, 0, 0) ; Not a 1D array If Not IsInt($iStart) Or Not IsInt($iEnd) Then Return SetError(5, 0, 0) ; Parameters need to be integers. Local $iBound = UBound($aArray) Local $aElementLen[$iBound][2] $iBound -=1 For $i = 0 To $iBound $aElementLen[$i][0] = StringLen($aArray[$i]) ; Get the length of the element $aElementLen[$i][1] = $aArray[$i] ; The element to sort Next _ArraySort($aElementLen, $iDescending, $iStart, $iEnd) If @error Then Return SetError(@error, 0, 0) ; See _ArraySort() for error codes 2 to 4. For $i = 0 To $iBound $aArray[$i] = $aElementLen[$i][1] Next Return 1 EndFunc ;==> _ArraySortByLen() See also: Edit Code Updated1 point
-
1 point
-
s!mpL3 LAN Messenger version 2.9.7.4 1. Server now using UDP port 60000 (breaks compatibility with older versions). 2. Server syntax changes (breaks compatibility with older versions). 3. Various bug fixes when connections change while connected or disconnected (msgboxes). 4. Specific settings not being greyed out as supposed to in Preferences GUI (previously Settings). 5. About GUI - re-designed and Updater implemented. License Agreement added. 6. Preferences GUI - completely re-designed to accommodate extra settings, become less crowded and look better. Some settings have been removed for now and will be re-implemented in the future if needed. Also added the ability to mute/unmute sounds. 7. Various UI tweaks - OS aware Notifications, moved some settings to the main window, under a new menu called View. Added some new features like the option for the main window and/or conversation windows to appear in the taskbar. 8. Status - Your status is visible to others. The tray icon also corresponds to your status and it shows to others next to your name in the Treeview. You can change your status by clicking the icon next to your Username before connecting (cycle through) or by choosing the one you want by right-clicking the tray icon. 9. Updater version 1.3.1.3, now gets information about the latest s!mpL3 LAN Messenger and displays it after updating.1 point
-
[SOLVED] Is there any _ArrayFindAll replacement that support wildcard?
michaelslamet reacted to PhoenixXL for a topic
#include <Array.au3> Local $aTest_Array[3] = ['Testing`_Temp.jpg', 'JOHN.jpeg', 'Boshe.jpeg'] Local $Ret_Array $Ret_Array = _ArrayFindAllEx($aTest_Array, '*_Temp.jp?g|*h?.jp?g', True, 'Test*.jp?g|b*.jpeg', False) _ArrayDisplay($Ret_Array, @extended & ' Match') #cs Wildcards * - Zero or more character + - One or more character ? - No or one character #ce ; #FUNCTION# ==================================================================================================================== ; Name ..........: _ArrayFindAllEx ; Description ...: Similar to _ArrayFindAll with Include, Exclude masks ; Syntax ........: _ArrayFindAllEx(Const Byref $aArray, $sIncludeMask[, $fIncSenstive = True[, $sExcludeMask = ''[, ; $fExcSenstive = True]]]) ; Parameters ....: $aArray - [in/out and const] The Array to search for the values. ; $sIncludeMask - A string value. ; $fIncSenstive - [optional] A boolean value. Default is True. ; $sExcludeMask - [optional] A string value. Default is ''. ; $fExcSenstive - [optional] A boolean value. Default is True. ; Return values .: Sucess - Returns the array of the Index of the found values ; - @extended is set to the number of items found ; Failure - Returns '' and sets @error to 1 ; Author ........: Phoenix XL ; Modified ......: ; Remarks .......: ; Related .......: _ArrayFindAll ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _ArrayFindAllEx(ByRef Const $aArray, $sIncludeMask, $fIncSenstive = True, $sExcludeMask = '', $fExcSenstive = True) ;Set Sensitivity Values If $fIncSenstive Then $fIncSenstive = '' Else $fIncSenstive = '(?i)' EndIf If $fExcSenstive Then $fExcSenstive = '' Else $fExcSenstive = '(?i)' EndIf ;Make the Include Mask Pattern $sIncludeMask = StringRegExpReplace($sIncludeMask, '(?s)([^\w|])', '[\1]') $sIncludeMask = StringRegExpReplace($sIncludeMask, '(?s)(\[\?\])', '.?') $sIncludeMask = StringRegExpReplace($sIncludeMask, '(?s)(\[\+\])', '.+') $sIncludeMask = $fIncSenstive & '(?s)\A(' & StringRegExpReplace($sIncludeMask, '(?s)(\[\*\])', '.*') & ')\z' Local $aRet[1] ;Debug Out Include Mask Patterns ConsoleWrite($sIncludeMask & @CR) ;Get the to-include Strings For $i = 0 To UBound($aArray) - 1 If StringRegExp($aArray[$i], $sIncludeMask) Then _ArrayAdd($aRet, $i) Next _ArrayDelete($aRet, 0) If Not IsArray($aRet) Then Return 0 If Not $sExcludeMask Then Return SetExtended( UBound( $aRet ), $aRet ) ;Make the Exclude Mask Pattern $sExcludeMask = StringRegExpReplace($sExcludeMask, '(?s)([^\w|])', '[\1]') $sExcludeMask = StringRegExpReplace($sExcludeMask, '(?s)(\[\?\])', '.?') $sExcludeMask = StringRegExpReplace($sExcludeMask, '(?s)(\[\+\])', '.+') $sExcludeMask = $fExcSenstive & '(?s)\A(' & StringRegExpReplace($sExcludeMask, '(?s)(\[\*\])', '.*') & ')\z' ;Debug Out Exclude Mask Patterns ConsoleWrite($sExcludeMask & @CR) Local $nDeleted = 0 ;Delete the to-exclude strings For $i = 0 To UBound($aRet) - 1 If StringRegExp($aArray[$aRet[$i - $nDeleted]], $sExcludeMask) Then $nDeleted += Number(_ArrayDelete($aRet, $i - $nDeleted) > 0) Next ;Done Return SetError(Not IsArray($aRet), UBound($aRet), $aRet) EndFunc ;==>_ArrayFindAllExThumbs up if it helped1 point -
Found this in my collection: ;another fast hack by UEZ 2011 #include <GDIPlus.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) _GDIPlus_Startup() Global Const $SC_DRAGMOVE = 0xF012 Global Const $W = -1 Global Const $H = 200 Global Const $hGUI = GUICreate("GDI+ Test by UEZ 2011", $W, $H, -1, -1, $WS_POPUP, $WS_EX_LAYERED) Global Const $hGUI_Child = GUICreate("", $W, $H, 0, 0, $WS_POPUP, $WS_EX_MDICHILD + $WS_EX_LAYERED + $WS_EX_TOOLWINDOW, $hGUI) GUISetBkColor(0xABCDEF, $hGUI_Child) GUISwitch($hGUI_Child) Global Const $idButton = GUICtrlCreateButton("Exit", 40, 20, 100, 40) GUICtrlSetOnEvent(-1, "_Exit") Global Const $idLabel = GUICtrlCreateLabel("TEST LABEL HERE!!!", 110, 140, 180, 20) GUICtrlSetFont(-1, 14, 400, 0, "Times New Roman", 3) GUICtrlSetColor(-1, 0xF0F0FF) GUICtrlSetBkColor(-1, -2) _WinAPI_SetLayeredWindowAttributes($hGUI_Child, 0xABCDEF, 0xFF) GUISetState(@SW_SHOW, $hGUI_Child) GUISetState(@SW_SHOW, $hGUI) _SetGuiRoundCorners($hGUI, 40, False, True, True, False) Global Const $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) Global Const $hBitmap = _CreateCustomBk($hGUI, 0x550555) Global Const $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap) _CreateCustomGroupPic($hContext, 100, 100, 200, 75, 0xff0000) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $W, $H) SetTransparentBitmap($hGUI, $hBitmap, 0xD0) GUISetOnEvent(-3, "_Exit") GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN") While Sleep(2 ^ 16) WEnd Func _Exit() _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_GraphicsDispose($hContext) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() GUIDelete($hGUI_Child) GUIDelete($hGUI) Exit EndFunc ;==>_Exit Func _CreateCustomBk($hGUI, $hexColor, $alpha = "0xAA") Local $iWidth = _WinAPI_GetClientWidth($hGUI) Local $iHeight = _WinAPI_GetClientHeight($hGUI) Local $oBitmap = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight) Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($oBitmap) _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2) Local $hBrush = _GDIPlus_BrushCreateSolid($alpha & Hex($hexColor, 6)) _GDIPlus_GraphicsFillRect($hGraphics, 0, 0, $iWidth, $iHeight, $hBrush) _GDIPlus_GraphicsFillRect($hGraphics, 2, 2, $iWidth - 6, $iHeight - 6, $hBrush) _GDIPlus_BrushSetSolidColor($hBrush, 0x22FFFFFF) Local $iTimes = Round($iWidth / 50) Local $aPoints[5][2] $aPoints[0][0] = 4 $aPoints[1][1] = $iHeight $aPoints[2][1] = $iHeight $aPoints[4][1] = 0 $aPoints[3][1] = 0 For $i = 0 To $iTimes Local $Random1 = Random(0, $iWidth, 1) Local $Random2 = Random(30, 50, 1) $aPoints[1][0] = $Random1 $aPoints[2][0] = $Random1 + $Random2 $aPoints[4][0] = $aPoints[1][0] + 50 $aPoints[3][0] = $aPoints[2][0] + 50 _GDIPlus_GraphicsFillPolygon($hGraphics, $aPoints, $hBrush) $aPoints[1][0] -= $Random2 / 10 $aPoints[2][0] = $Random1 + $Random2 - ($Random2 / 10 * 2) $aPoints[3][0] = $aPoints[2][0] + 50 $aPoints[4][0] = $aPoints[1][0] + 50 _GDIPlus_GraphicsFillPolygon($hGraphics, $aPoints, $hBrush) Next _GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hGraphics) Return $oBitmap EndFunc ;==>_CreateCustomBk Func _CreateCustomGroupPic($hGraphics, $ix, $iy, $Width, $iHeight, $hexColor, $alpha = "0x55") _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2) Local $hBrush = _GDIPlus_BrushCreateSolid($alpha & Hex($hexColor, 6)) _GDIPlus_GraphicsFillRect($hGraphics, $ix, $iy, $Width, $iHeight, $hBrush) _GDIPlus_GraphicsFillRect($hGraphics, 2, 2, $Width - 4, $iHeight - 4, $hBrush) _GDIPlus_BrushDispose($hBrush) EndFunc ;==>_CreateCustomGroupPic Func _SetGuiRoundCorners($hGUI, $iEllipse, $iLeftUp = True, $iLeftDown = True, $iRightUp = True, $iRightDown = True) Local $hCornerRgn Local $aGuiSize = WinGetPos($hGUI) Local $hRgn = _WinAPI_CreateRoundRectRgn(0, 0, $aGuiSize[2], $aGuiSize[3], $iEllipse, $iEllipse) If $iLeftUp = False Then $hCornerRgn = _WinAPI_CreateRectRgn(0, 0, $aGuiSize[2] / 2, $aGuiSize[3] / 2) _WinAPI_CombineRgn($hRgn, $hRgn, $hCornerRgn, $RGN_OR) _WinAPI_DeleteObject($hCornerRgn) EndIf If $iLeftDown = False Then $hCornerRgn = _WinAPI_CreateRectRgn(0, $aGuiSize[3] / 2, $aGuiSize[2] / 2, $aGuiSize[3]) _WinAPI_CombineRgn($hRgn, $hRgn, $hCornerRgn, $RGN_OR) _WinAPI_DeleteObject($hCornerRgn) EndIf If $iRightUp = False Then $hCornerRgn = _WinAPI_CreateRectRgn($aGuiSize[2] / 2, 0, $aGuiSize[2], $aGuiSize[3] / 2) _WinAPI_CombineRgn($hRgn, $hRgn, $hCornerRgn, $RGN_OR) _WinAPI_DeleteObject($hCornerRgn) EndIf If $iRightDown = False Then $hCornerRgn = _WinAPI_CreateRectRgn($aGuiSize[2] / 2, $aGuiSize[3] / 2, $aGuiSize[2] - 1, $aGuiSize[3] - 1) _WinAPI_CombineRgn($hRgn, $hRgn, $hCornerRgn, $RGN_OR) _WinAPI_DeleteObject($hCornerRgn) EndIf _WinAPI_SetWindowRgn($hGUI, $hRgn) EndFunc ;==>_SetGuiRoundCorners Func SetTransparentBitmap($hGUI, $hImage, $iOpacity = 0xFF) Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend $hScrDC = _WinAPI_GetDC(0) $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC) $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap) $tSize = DllStructCreate($tagSIZE) $pSize = DllStructGetPtr($tSize) DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth($hImage)) DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage)) $tSource = DllStructCreate($tagPOINT) $pSource = DllStructGetPtr($tSource) $tBlend = DllStructCreate($tagBLENDFUNCTION) $pBlend = DllStructGetPtr($tBlend) DllStructSetData($tBlend, "Alpha", $iOpacity) DllStructSetData($tBlend, "Format", 1) _WinAPI_UpdateLayeredWindow($hGUI, $hMemDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA) _WinAPI_ReleaseDC(0, $hScrDC) _WinAPI_SelectObject($hMemDC, $hOld) _WinAPI_DeleteObject($hBitmap) _WinAPI_DeleteDC($hMemDC) EndFunc ;==>SetTransparentBitmap Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0) Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0) If @error Then Return SetError(@error, @extended, 0) Return $aResult[6] EndFunc ;==>_GDIPlus_BitmapCreateFromScan0 Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam) _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0) EndFunc ;==>_WM_LBUTTONDOWN Screenshot: Br, UEZ1 point
-
Image Processing in AU3 - IMAGEMAGICK I saw someone mentioning IMAGEMAGICK in the support site, and I remembered it has a huge number on command line options. The later version has as well an COM object, that exposes all cmd line options via the object. IMAGEMAGICK - COM Object Perfect for AU3 wouldn't you say. There are about 200 cmd line options. IMAGEMAGICK - Command line Options This will get you all started. Dim $img Dim $ret ; Initialize error handler $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") $img = ObjCreate("ImageMagickObject.MagickImage.1") $ret = $img.Convert("C:Tempbill_meets_gorilla_screen.jpg", _ "-resize", "320x200", _ "-sepia-tone", "70%", _ "-format", "gif", _ "C:Tempbill_meets_gorilla_screen_NEW.gif") Func MyErrFunc() $HexNumber=hex($oMyError.number,8) Msgbox(0,"COM Error Test","We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & $HexNumber & @CRLF & _ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oMyError.helpcontext _ ) SetError(1) ; to check for after this function returns Endfunc Const $ERROR_SUCCESS = 0 Dim $img Dim $info Dim $msgs Dim $elem Dim $sMsgs ; Initialize error handler $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; This is the simplest sample I could come up with. It creates ; the ImageMagick COM object and then sends a copy of the IM ; logo out to a JPEG image files on disk. ; $img = ObjCreate("ImageMagickObject.MagickImage.1") ; ; The methods for the IM COM object are identical to utility ; command line utilities. You have convert, composite, identify, ; mogrify, and montage. We did not bother with animate, and ; display since they have no purpose in this context. ; ; The argument list is exactly the same as the utility programs ; as a list of strings. In fact you should just be able to ; copy and past - do simple editing and it will work. See the ; other samples for more elaborate command sequences and the ; documentation for the utility programs for more details. ; $sMsgs = $img.Convert("logo:","-format","%m,%h,%w","logo.jpg") ; ; By default - the string returned is the height, width, and the ; type of the image that was output. You can control this using ; the -format "xxxxxx" command as documented by identify. ; MsgBox (0,"info: ","Return = " & $sMsgs) Func MyErrFunc() $HexNumber=hex($oMyError.number,8) Msgbox(0,"COM Error Test","We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & $HexNumber & @CRLF & _ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oMyError.helpcontext _ ) SetError(1) ; to check for after this function returns Endfunc Enjoy !! ptrex1 point