Jump to content

Leaderboard

Popular Content

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

  1. 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
  2. Since there are WAY to many posts on how to SRE something I thought I would create a nice little tester. This thing does SRE and SRER. Loads files to test. Gets internet content to test. And more! Here it is: SRETesterV2.1.au3 Prev DL - 211 Enjoy!
    1 point
  3. Hi, Here is a suggestion for you: show the non compiled script line number. I have succeed to do it, but there's a problem : you have to treat the non compiled file before compiling it with the following script : #include <File.au3> Local $sScriptPath = FileOpenDialog("select au3", @ScriptDir, "AutoIt3 Script (*.au3)", 3) If @error Then Exit -1 Local $aLines, $sOutPut = "Global $__iLineNumber=0" & @CRLF Local $blSkipNextLine = False _FileReadToArray($sScriptPath, $aLines) For $iLine = 1 To $aLines[0] If $blSkipNextLine Then $blSkipNextLine = False Else $sOutPut &= "$__iLineNumber=" & $iLine & @CRLF EndIf $sOutPut &= $aLines[$iLine] & @CRLF If StringRight($aLines[$iLine], 2) = " _" Then $blSkipNextLine = True EndIf Next FileWrite($sScriptPath & "_.au3", $sOutPut)You have to add the variable $__iLineNumber in your debug window of course. This can be improved, It's only an idea. Proof : Br, FireFox.
    1 point
  4. This is a "feature" that was introduced by us when the Horizontal scrollbar is automatically updated by a LUA script. Comment line 30 in SciTEstartup.LUA and you will see it is gone: --~ LoadLuaFile("AutoHScroll.lua") Jos
    1 point
  5. Nice! Is there any way to call the function with different parameters every time? the way it it right now, the parameters are stored when _Adlib_Register() is called. ; #FUNCTION# ==================================================================================================================== ; Name...........: _Adlib_SetParams ; Description ...: Pauses the Enhanced Adlib functionality for defined function. ; Syntax.........: _Adlib_Pause( "Function", "Params" ) ; Parameters ....: Function - The name of the adlib function to pause. ; Params - The new parameter(s). ; Return values .: Success - Return 1 ; Failure - Return 0 ; Author ........: darthWhatever ; Modified.......: ; Remarks .......: ; Related .......: _Adlib_Resume, _Adlib_Register, _Adlib_UnRegister, _Adlib_SetTimer ; Link ..........; ; Example .......; _Adlib_SetParams( "MyFunction", "NewParam1|NewParam2" ) ; =============================================================================================================================== Func _Adlib_SetParams($sFuncName, $sParams) Local $iIndex = __ADB_GetIndex($sFuncName) If Not $iIndex Then Return 0 $avADB_CALLS[$iIndex][1] = $sParams Return 1 EndFunc ;==>_Adlib_SetParams
    1 point
  6. SmOke_N

    GDIPlus Snippets

    I know there are snippet threads, but I'd like this one to be specific. I've see quite a few neat GDI+ code snippets (UEZ and Progandy come to mind first) to manipulate, create, etc, and I thought it'd be neat to be able to find them under one thread. I'm going to reserve the next 3 posts because I'm unsure at the moment if it's the "Quote" or "Spoiler" bbcode tags that has the 10 limit. You can link or post the snippets you find or create and I'll title them and put them in the threads for everyone to find. ( Going to have to remember to edit with regular editor! ) Some of these may not have titles, so I may create my own, if the author(s) want(s) a different one, let me know. _GDIPlus_WaterMark.au3 - Author: UEZ - Added: 2012-10-13 - Updated: _GDIPlus_BMPFromMemory – Author UEZ – Added: 2012-10-14 – Updated: Example – Needle Movement (4bit example provided, link to 32bit found in code) – Author: UEZ - Added: 2012-10-14 – Updated:
    1 point
  7. You need to convert the GDI+ bitmap to a WinAPI bitmap format. #include <SQLite.au3> #include <SQLite.dll.au3> #include <GUIConstantsEx.au3> #include <GDIPlus.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Memory.au3> Global Const $IMAGE_BITMAP = 0 ; Needed for GUICtrlSendMsg. Global Const $STM_SETIMAGE = 0x0172 ; Needed for GUICtrlSendMsg. Local $hGUI, $hBMP, $hBitmap, $hGraphic Local $hQuery, $item Local $filename Local $x = 100, $y = 100 _SQLite_Startup() _SQLite_Open() ; open Database in Memory If @error Then MsgBox(16, "SQLite Error", "Can't Load Database!") Exit -1 EndIf _SQLite_Exec(-1, "CREATE TABLE IF NOT EXISTS DBTest (IMAGE BLOB);") $hGUI = GUICreate("GUI", 400, 300) $GUIImage = GUICtrlCreatePic("", 40, 40, $x, $y, BitOR($GUI_SS_DEFAULT_PIC, $SS_CENTERIMAGE, $SS_SUNKEN, $WS_BORDER), BitOR($WS_EX_CLIENTEDGE, $WS_EX_STATICEDGE)) ;$button1 = GUICtrlCreateButton("1",10,10) ;$button2 = GUICtrlCreateButton("2",50,10) ;GUISetState() GUISetState(@SW_SHOW) Local $filename = FileOpenDialog("Select image", @ScriptDir, "Image (*.jpg;*.bmp)", 3) _GDIPlus_Startup() Global $hBitmap = _GDIPlus_ScaleImage($filename, $x, $y) Global $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) Global $bImage = _GDIPlus_SaveImage2BinaryString($hBitmap) ;~ MsgBox(0, "Binary", $bImage) _WinAPI_DeleteObject(GUICtrlSendMsg($GUIImage, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap)) ; Does not seems to work ;_WinAPI_DeleteObject(GUICtrlSendMsg($GUIImage, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap)) ; Also tried this with no luck _WinAPI_DeleteObject($hHBitmap) _GDIPlus_Shutdown() ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd _SQLite_Close() _SQLite_Shutdown() Exit Func _GDIPlus_SaveImage2BinaryString($hBitmap, $iQuality = 50, $bSave = False, $sFilename = "Converted.jpg") ;coded by Andreik, modified by UEZ Local $sImgCLSID = _GDIPlus_EncodersGetCLSID("jpg") Local $tGUID = _WinAPI_GUIDFromString($sImgCLSID) Local $pEncoder = DllStructGetPtr($tGUID) Local $tParams = _GDIPlus_ParamInit(1) Local $tData = DllStructCreate("int Quality") DllStructSetData($tData, "Quality", $iQuality) ;quality 0-100 Local $pData = DllStructGetPtr($tData) _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData) Local $pParams = DllStructGetPtr($tParams) Local $hStream = DllCall("ole32.dll", "uint", "CreateStreamOnHGlobal", "ptr", 0, "bool", True, "ptr*", 0) ;http://msdn.microsoft.com/en-us/library/ms864401.aspx If @error Then Return SetError(1, 0, 0) $hStream = $hStream[3] DllCall($ghGDIPDll, "uint", "GdipSaveImageToStream", "ptr", $hBitmap, "ptr", $hStream, "ptr", $pEncoder, "ptr", $pParams) _GDIPlus_BitmapDispose($hBitmap) Local $hMemory = DllCall("ole32.dll", "uint", "GetHGlobalFromStream", "ptr", $hStream, "ptr*", 0) ;http://msdn.microsoft.com/en-us/library/aa911736.aspx If @error Then Return SetError(2, 0, 0) $hMemory = $hMemory[2] Local $iMemSize = _MemGlobalSize($hMemory) Local $pMem = _MemGlobalLock($hMemory) $tData = DllStructCreate("byte[" & $iMemSize & "]", $pMem) Local $bData = DllStructGetData($tData, 1) Local $tVARIANT = DllStructCreate("word vt;word r1;word r2;word r3;ptr data;ptr") Local $aCall = DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $hStream, "dword", 8 + 8 * @AutoItX64, "dword", 4, "dword", 23, "dword", 0, "ptr", 0, "ptr", 0, "ptr", DllStructGetPtr($tVARIANT)) ;http://msdn.microsoft.com/en-us/library/windows/desktop/ms221473(v=vs.85).aspx _MemGlobalFree($hMemory) If $bSave Then Local $hFile = FileOpen(@ScriptDir & "" & $sFilename, 18) FileWrite($hFile, $bData) FileClose($hFile) EndIf Return $bData EndFunc ;==>_GDIPlus_SaveImage2BinaryString Func _GDIPlus_ScaleImage($sFile, $iW, $iH, $iInterpolationMode = 7) ;coded by UEZ 2012 If Not FileExists($sFile) Then Return SetError(1, 0, 0) Local $hImage = _GDIPlus_ImageLoadFromFile($sFile) If @error Then Return SetError(2, 0, 0) Local $hBitmap = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iW, "int", $iH, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0) If @error Then Return SetError(3, 0, 0) $hBitmap = $hBitmap[6] Local $hBmpCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) DllCall($ghGDIPDll, "uint", "GdipSetInterpolationMode", "handle", $hBmpCtxt, "int", $iInterpolationMode) _GDIPlus_GraphicsDrawImageRect($hBmpCtxt, $hImage, 0, 0, $iW, $iH) _GDIPlus_ImageDispose($hImage) _GDIPlus_GraphicsDispose($hBmpCtxt) Return $hBitmap EndFunc ;==>_GDIPlus_ScaleImage Br, UEZ
    1 point
  8. Another example as I'm feeling kind today. Just copy the _WM_COPYDATA functions from the post I provided before as I want a central place where I can update them in the future. #include <GUIConstantsEx.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> ; This is for the UDF functions, do not touch! Global Enum $__hInterCommunicationGUI, $__iInterCommunicationControlID, $__sInterCommunicationIDString, $__sInterCommunicationData, $__iInterCommunicationMax Global $__vInterCommunicationAPI[$__iInterCommunicationMax] ; Internal array for the WM_COPYDATA functions. If Not @Compiled Then Exit MsgBox(4096, '', 'Compile this example before running.') EndIf ; Create a unique ID _WM_COPYDATA_SetID('myCustomID') Example() Func Example() ; Start the intercommunication process. Local $iControlID = _WM_COPYDATA_Start() If @error Then ; If it already exists i.e. there is another instance of the program running then exit. If Not _WM_COPYDATA_Send($CmdLineRaw) Then ; Send $CmdLineRaw if there is process already running. This may be blank but send it anyway. MsgBox(4096, '2nd Instance: ' & @AutoItPID, 'Seems there was an @error, but more than likely $CmdLineRaw was blank.') EndIf Exit EndIf ; You can add your GUI code here. Local $hGUI = GUICreate('') Local $iClose = GUICtrlCreateButton('Close', 310, 370, 85, 25) GUISetState(@SW_SHOW, $hGUI) ; If this is the first instance then just continue. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $iClose ExitLoop Case $iControlID ; If the WM_COPYDATA message is interecepted then show the optimise function. This is the commandline from the second instance. _Optimise() EndSwitch WEnd ; Start the intercommunication process. _WM_COPYDATA_Shutdown() GUIDelete($hGUI) EndFunc ;==>Example Func _Optimise() Return MsgBox(4096, '1st Instance: ' & @AutoItPID, _WM_COPYDATA_GetData()) ; Get the WM_COPYDATA file. EndFunc ;==>_Optimise
    1 point
  9. My example (WM_COPYDATA) did you try it? Compile the code, run the executable and then send command parameters to the executable filepath e.g. if the executable is called Example.exe and located in root of C: then C:Example.exe "C:FilePath.au3" and you will see the first instance display the commandline. How simple is that? Or instead just drop a file onto the executable icon to pass the commandline to the first instance.
    1 point
  10. Okay, I found a solution. The secret is that, a 32-bit executable running on a 64 bit system, can access the files in the 64-bit System32 folder via a special secret folder named "Sysnative". Here's my code again, modified, this time it works in AutoIt on 32 and 64. If @OSArch == "X64" Then $WindowsActualTrueSystemFolder = @WindowsDir & "sysnative" Else $WindowsActualTrueSystemFolder = @SystemDir EndIf $OutputHandle = Run($WindowsActualTrueSystemFolder & "" & "netsh.exe mbn show readyinfo int=*", "", @SW_HIDE, $STDOUT_CHILD) While 1 $RunResults = $RunResults & StdoutRead($OutputHandle) If @error Then ExitLoop WEnd MsgBox (0, "Output", $RunResults)
    1 point
  11. My personal favourite is by GreenCan EDIT: But there are quite a few ways much simpler than that, not least communication through a file like txt, ini or xml etc...
    1 point
  12. You can try to use these 2 functions to scale the image, save it as a binary string (JPG) and store it in the DB. #include <GDIPlus.au3> #include <Memory.au3> _GDIPlus_Startup() Global $sFile = StringReplace(@AutoItExe, "autoit3.exe", "ExamplesGUImsoobe.jpg") Global $hBitmap = _GDIPlus_ScaleImage($sFile, 102, 76) Global $bImage = _GDIPlus_SaveImage2Binary($hBitmap) MsgBox(0, "Binary", $bImage) _GDIPlus_Shutdown() Func _GDIPlus_SaveImage2Binary($hBitmap, $iQuality = 50) ;coded by Andreik, modified by UEZ Local $sImgCLSID = _GDIPlus_EncodersGetCLSID("jpg") Local $tGUID = _WinAPI_GUIDFromString($sImgCLSID) Local $pEncoder = DllStructGetPtr($tGUID) Local $tParams = _GDIPlus_ParamInit (1) Local $tData = DllStructCreate("int Quality") DllStructSetData($tData, "Quality", $iQuality) ;quality 0-100 Local $pData = DllStructGetPtr($tData) _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData) Local $pParams = DllStructGetPtr($tParams) Local $hStream = DllCall("ole32.dll", "uint", "CreateStreamOnHGlobal", "ptr", 0, "bool", True, "ptr*", 0) ;http://msdn.microsoft.com/en-us/library/ms864401.aspx $hStream = $hStream[3] DllCall($ghGDIPDll, "uint", "GdipSaveImageToStream", "ptr", $hBitmap, "ptr", $hStream, "ptr", $pEncoder, "ptr", $pParams) _GDIPlus_BitmapDispose($hBitmap) Local $hMemory = DllCall("ole32.dll", "uint", "GetHGlobalFromStream", "ptr", $hStream, "ptr*", 0) ;http://msdn.microsoft.com/en-us/library/aa911736.aspx $hMemory = $hMemory[2] Local $iMemSize = _MemGlobalSize($hMemory) Local $pMem = _MemGlobalLock($hMemory) $tData = DllStructCreate("byte[" & $iMemSize & "]", $pMem) Local $bData = DllStructGetData($tData, 1) Local $tVARIANT = DllStructCreate("word vt;word r1;word r2;word r3;ptr data;ptr") Local $aCall = DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $hStream, "dword", 8 + 8 * @AutoItX64, "dword", 4, "dword", 23, "dword", 0, "ptr", 0, "ptr", 0, "ptr", DllStructGetPtr($tVARIANT)) ;http://msdn.microsoft.com/en-us/library/windows/desktop/ms221473(v=vs.85).aspx _MemGlobalFree($hMemory) Return $bData EndFunc Func _GDIPlus_ScaleImage($sFile, $iW, $iH, $iInterpolationMode = 7) ;coded by UEZ 2012 If Not FileExists($sFile) Then Return SetError(1, 0, 0) Local $hImage = _GDIPlus_ImageLoadFromFile($sFile) If @error Then Return SetError(2, 0, 0) Local $hBitmap = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iW, "int", $iH, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0) If @error Then Return SetError(3, 0, 0) $hBitmap = $hBitmap[6] Local $hBmpCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) DllCall($ghGDIPDll, "uint", "GdipSetInterpolationMode", "handle", $hBmpCtxt, "int", $iInterpolationMode) _GDIPlus_GraphicsDrawImageRect($hBmpCtxt, $hImage, 0, 0, $iW, $iH) _GDIPlus_ImageDispose($hImage) _GDIPlus_GraphicsDispose($hBmpCtxt) Return $hBitmap EndFunc Br, UEZ
    1 point
  13. DaleHohm

    Catching IE download.

    It is not XMLHttpRequest, it is a bug in the Javascript parser in IE9 standards mode, as I understand it, that causes $oIE.document.parentwindow.eval to fail. The only workaround I am currently aware of is to set the page to compatability mode. Dale
    1 point
×
×
  • Create New...