Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 09/16/2014 in all areas

  1. Andreik

    Pie chart

    This is an example how to draw a simple pie chart in a picture control. Available properties: Width - width of chart (including legend)Height - height of chart (including title)Title - chart titleTitleHeight - title height in pixels (default 30px)TitleAlign - title alignment: Left,Center,Right (default: Left)TitleSize - title text size (default: 12)TitleStyle - title style: Bold, Italic, Underline, Strikethrough (default: Bold)LegendWidth - width reserved for legend - calculated from total chart width, (default: 150 px)LegendTextSize - text size in legend area (default: 10px)LegendStyle - legend style: Bold, Italic, Underline, Strikethrough (default: Italic)LegendDetails - specify what details are displayed in legend area: Percent, Value, Nothing (default: Percent)Palette - palette of colors - delimited by | - must contain same number of colors (AARRGGBB format) as items in data arrayBackground - background color - AARRGGBB format (default: 0xFFFFFFFF - white)TextColor - text color - AARRGGBB format (default: 0xFF000000 - black)Font - title and legend font (default: Arial)OthersColor - color used for the slice that contain all slices with value less than MinSlice - AARRGGBB format (default: 0xFFC0C0C0 - grey)StartAngle - start angle of first slice (default: 0)Padding - chart padding (default: 5px)MinSlice - minimum value for a slice to be displayed (default: 1)Bullet - bullet used in legend: Square, Circle (default: Square)BorderColor - border color of chart - AARRGGBB format (default: 0xFF000000 - black)BorderSize - border size of chart (default: 0 - without border)Method Draw requires the ID of pic control where the chart will be draw and the array of data. Example: #include <Charts.au3> #cs $aData[0][0] - contains the number of items in data array $aData[0][1] - is not important (this will be used internaly to store the sum of values) ... $aData[n][0] - value $aData[n][1] - label #ce Local $aData[11][2] = _ [ [10,0], _ [72040000,"China"], _ [36784200,"Russia"], _ [26280000,"India"], _ [20373267,"United states"], _ [19102300,"Ukraine"], _ [11791072,"Poland"], _ [11643769,"Germany"], _ [8743976,"Belarus"], _ [7200000,"Netherlands"], _ [6271000,"France"]] _AutoItObject_Startup() $hMain = GUICreate('Pie chart',500,300) $hPic = GUICtrlCreatePic('',0,0,500,300) $Pie = PieChart() With $Pie .Width = 500 .Height = 300 .Title = 'Potatoes production in 2007 (tonnes)' .TitleHeight = 30 .TitleAlign = "Left" .TitleSize = 11 .TitleStyle = "Bold" .LegendWidth = 200 .LegendTextSize = 10 .LegendStyle = "Italic" .Palette = '0xFF00BEEF|0xFFDC143C|0xFF228B22|0xFF003399|0xFFFF8000|0xFF80FFA0|0xFFFFD700|0xFF800080|0xFFDB7093|0xFF7F00FF' .OthersColor = 0xFFEEE8AA .Background = 0xFFFFFFFF .TextColor = 0xFF002060 .Font = 'Tahoma' .StartAngle = 45 .Padding = 5 .MinSlice = 10000000 .Bullet = "Square" .LegendDetails = 'Percent' .BorderSize = 0 .BorderColor = 0xFF004000 .Draw($hPic,$aData) EndWith GUISetState(@SW_SHOW,$hMain) Do Sleep(10) Until GUIGetMsg() = -3 _AutoItObject_Shutdown() Charts.au3 #include-once #include <AutoItObject.au3> #include <GDIPlus.au3> Func PieChart() Local $oClass = _AutoItObject_Class() With $oClass .AddMethod("Draw","__pie_draw") .AddProperty("Width",$ELSCOPE_PUBLIC) .AddProperty("Height",$ELSCOPE_PUBLIC) .AddProperty("Title",$ELSCOPE_PUBLIC) .AddProperty("TitleHeight",$ELSCOPE_PUBLIC,30) .AddProperty("TitleAlign",$ELSCOPE_PUBLIC,"Left") .AddProperty("TitleSize",$ELSCOPE_PUBLIC,12) .AddProperty("TitleStyle",$ELSCOPE_PUBLIC,'Bold') .AddProperty("LegendWidth",$ELSCOPE_PUBLIC,150) .AddProperty("LegendTextSize",$ELSCOPE_PUBLIC,10) .AddProperty("LegendStyle",$ELSCOPE_PUBLIC,'Italic') .AddProperty("Palette",$ELSCOPE_PUBLIC) .AddProperty("Background",$ELSCOPE_PUBLIC,0xFFFFFFFF) .AddProperty("TextColor",$ELSCOPE_PUBLIC,0xFF000000) .AddProperty("OthersColor",$ELSCOPE_PUBLIC,0xFFC0C0C0) .AddProperty("Font",$ELSCOPE_PUBLIC,'Arial') .AddProperty("StartAngle",$ELSCOPE_PUBLIC,0) .AddProperty("Padding",$ELSCOPE_PUBLIC,5) .AddProperty("MinSlice",$ELSCOPE_PUBLIC,1) .AddProperty("Bullet",$ELSCOPE_PUBLIC,"Square") .AddProperty("LegendDetails",$ELSCOPE_PUBLIC,"Percent") .AddProperty("BorderColor",$ELSCOPE_PUBLIC,0xFF000000) .AddProperty("BorderSize",$ELSCOPE_PUBLIC,0) .AddProperty("Aspect",$ELSCOPE_PUBLIC,1) EndWith Return $oClass.Object EndFunc Func __pie_draw($oObject,$hCtrl,$aData) If $oObject.Aspect < 0.2 Then $oObject.Aspect = 0.2 If $oObject.Aspect > 1 Then $oObject.Aspect = 1 $oObject.StartAngle = Mod($oObject.StartAngle,360) Local $iW = $oObject.Width Local $iH = $oObject.Height Local $iPadding = $oObject.Padding Local $iLW = $oObject.LegendWidth Local $iTH = $oObject.TitleHeight Local $aPalette = StringSplit($oObject.Palette,'|') Local $iBase = $oObject.StartAngle Local $iSweep Local $hBrush, $hTextBrush Local $Align Local $Others Local $TitleSize = $oObject.TitleSize Local $LegendTextSize = $oObject.LegendTextSize Local $TitleStyle, $LegendStyle Local $iHidden, $iVisible If $aPalette[0] < $aData[0][0] Then Return False Switch $oObject.TitleAlign Case "Left" $Align = 0 Case "Center" $Align = 1 Case "Right" $Align = 2 EndSwitch Switch $oObject.TitleStyle Case "Bold" $TitleStyle = 1 Case "Italic" $TitleStyle = 2 Case "Underline" $TitleStyle = 4 Case "Strikethrough" $TitleStyle = 8 EndSwitch Switch $oObject.LegendStyle Case "Bold" $LegendStyle = 1 Case "Italic" $LegendStyle = 2 Case "Underline" $LegendStyle = 4 Case "Strikethrough" $LegendStyle = 8 EndSwitch For $Index = 1 To $aData[0][0] $aData[0][1] += $aData[$Index][0] If $aData[$Index][0] < $oObject.MinSlice Then $Others += $aData[$Index][0] $iHidden += 1 EndIf Next _GDIPlus_Startup() Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW,$iH) Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetSmoothingMode($hGraphics,2) _GDIPlus_GraphicsSetPixelOffsetMode($hGraphics,4) _GDIPlus_GraphicsClear($hGraphics,$oObject.Background) If $oObject.BorderSize > 0 Then Local $hPen = _GDIPlus_PenCreate($oObject.BorderColor,$oObject.BorderSize) _GDIPlus_GraphicsDrawRect($hGraphics,0,0,$iW,$iH,$hPen) _GDIPlus_PenDispose($hPen) EndIf $iH *= $oObject.Aspect Local $hFamily = _GDIPlus_FontFamilyCreate($oObject.Font) Local $hFontTitle = _GDIPlus_FontCreate($hFamily,$TitleSize,$TitleStyle) Local $hFontLegend = _GDIPlus_FontCreate($hFamily,$LegendTextSize,$LegendStyle) Local $tLayout = _GDIPlus_RectFCreate($iPadding,$iPadding,$iW-$iPadding*2,$iTH) Local $hFormat = _GDIPlus_StringFormatCreate(0x0020) Local $hTextBrush = _GDIPlus_BrushCreateSolid($oObject.TextColor) _GDIPlus_StringFormatSetAlign($hFormat,$Align) _GDIPlus_GraphicsDrawStringEx($hGraphics,$oObject.Title,$hFontTitle,$tLayout,$hFormat,$hTextBrush) For $Index = 1 To $aData[0][0] If $aData[$Index][0] >= $oObject.MinSlice Then $iVisible += 1 $iSweep = $aData[$Index][0]*360/$aData[0][1] $hBrush = _GDIPlus_BrushCreateSolid($aPalette[$Index]) _GDIPlus_GraphicsFillPie($hGraphics,$iPadding,$iPadding+$iTH,$iW-$iLW-$iPadding*2,$iH-$iTH-$iPadding*2,$iBase,$iSweep,$hBrush) Switch $oObject.Bullet Case "Square" _GDIPlus_GraphicsFillRect($hGraphics,$iW-$iLW+$iPadding,$iVisible*$iTH+5,5,5,$hBrush) Case "Circle" _GDIPlus_GraphicsFillEllipse($hGraphics,$iW-$iLW+$iPadding,$iVisible*$iTH+5,5,5,$hBrush) EndSwitch Switch $oObject.LegendDetails Case 'Percent' _GDIPlus_GraphicsDrawStringEx($hGraphics,$aData[$Index][1] & ' (' & Round($aData[$Index][0]*100/$aData[0][1],2) & '%)',$hFontLegend,_GDIPlus_RectFCreate($iW-$iLW+$iPadding+10,$iVisible*$iTH,$iW-$iLW-$iPadding-10,$iTH),$hFormat,$hTextBrush) Case 'Value' _GDIPlus_GraphicsDrawStringEx($hGraphics,$aData[$Index][1] & ' (' & $aData[$Index][0] & ')',$hFontLegend,_GDIPlus_RectFCreate($iW-$iLW+$iPadding+10,$iVisible*$iTH,$iW-$iLW-$iPadding-10,$iTH),$hFormat,$hTextBrush) Case Else _GDIPlus_GraphicsDrawStringEx($hGraphics,$aData[$Index][1],$hFontLegend,_GDIPlus_RectFCreate($iW-$iLW+$iPadding+10,$iVisible*$iTH,$iW-$iLW-$iPadding-10,$iTH),$hFormat,$hTextBrush) EndSwitch _GDIPlus_BrushDispose($hBrush) $iBase += $iSweep EndIf Next If $Others > 0 Then $iSweep = $Others*360/$aData[0][1] $hBrush = _GDIPlus_BrushCreateSolid($oObject.OthersColor) _GDIPlus_GraphicsFillPie($hGraphics,$iPadding,$iPadding+$iTH,$iW-$iLW-$iPadding*2,$iH-$iTH-$iPadding*2,$iBase,$iSweep,$hBrush) Switch $oObject.Bullet Case "Square" _GDIPlus_GraphicsFillRect($hGraphics,$iW-$iLW+$iPadding,($aData[0][0]-$iHidden+1)*$iTH+5,5,5,$hBrush) Case "Circle" _GDIPlus_GraphicsFillEllipse($hGraphics,$iW-$iLW+$iPadding,($aData[0][0]-$iHidden+1)*$iTH+5,5,5,$hBrush) EndSwitch Switch $oObject.LegendDetails Case 'Percent' _GDIPlus_GraphicsDrawStringEx($hGraphics,'Others (' & Round($Others*100/$aData[0][1],2) & '%)',$hFontLegend,_GDIPlus_RectFCreate($iW-$iLW+$iPadding+10,($aData[0][0]-$iHidden+1)*$iTH,$iW-$iLW-$iPadding-10,$iTH),$hFormat,$hTextBrush) Case 'Value' _GDIPlus_GraphicsDrawStringEx($hGraphics,'Others (' & $Others & ')',$hFontLegend,_GDIPlus_RectFCreate($iW-$iLW+$iPadding+10,($aData[0][0]-$iHidden+1)*$iTH,$iW-$iLW-$iPadding-10,$iTH),$hFormat,$hTextBrush) Case Else _GDIPlus_GraphicsDrawStringEx($hGraphics,'Others',$hFontLegend,_GDIPlus_RectFCreate($iW-$iLW+$iPadding+10,($aData[0][0]-$iHidden+1)*$iTH,$iW-$iLW-$iPadding-10,$iTH),$hFormat,$hTextBrush) EndSwitch _GDIPlus_BrushDispose($hBrush) EndIf Local $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) _WinAPI_DeleteObject(GUICtrlSendMsg($hCtrl,0x0172,0,$hHBITMAP)) _WinAPI_DeleteObject($hHBITMAP) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_FontDispose($hFontTitle) _GDIPlus_FontDispose($hFontLegend) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_BrushDispose($hTextBrush) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_Shutdown() EndFunc PS: Charts.au3 require AutoItObject.au3
    2 points
  2. After having lot of issues myself with getting ImageSearch to work I decided to make topic with explanation how to proper use this script. Here is link of original topic at this topic: Credits to kangkeng for creating such useful piece of code. What is ImageSearch? It's script that find part of screen which you before defined with given image. When should I use ImageSearch? You should use it whenever it's not possible or unlikely that pixelsearch will give what you need. So how can I use ImageSearch and enjoy it's awesome benefits? First of all to avoid mostly caused problems I recompiled DLLs for both architectures which you can download at end of this post. When you pick your package you should place both ImageSearch.au3 and ImageSearch.dll inside script folder. Usage Example: First of all take picture of what you want to search for (print screen + paint + corp + save as bmp). Place that picture in script directory (I named my picture checkImage (checkImage.bmp is full name with extension). You must include ImageSearch.au3 in your script. ImageSearch.au3 consist of 2 Functions you can use: _ImageSearch and _ImageSearchArea Note: Use _ImageSearch to search the entire desktop, _ImageSearchArea to specify a desktop region to search Values to put in for _ImageSearch function (entire screen search) ($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance, $HBMP=0) Values to put in for _ImageSearchArea function (you declare part of screen to be searched) ($findImage,$resultPosition,$x1,$y1,$right,$bottom,ByRef $x, ByRef $y, $tolerance,$HBMP=0) Description of parameters from ImageSearch.au3 itself: ; Description: Find the position of an image on the desktop ; Syntax: _ImageSearchArea, _ImageSearch ; Parameter(s): ; $findImage - the image to locate on the desktop ; $tolerance - 0 for no tolerance (0-255). Needed when colors of ; image differ from desktop. e.g GIF ; $resultPosition - Set where the returned x,y location of the image is. ; 1 for centre of image, 0 for top left of image ; $x $y - Return the x and y location of the image ; ; Return Value(s): On Success - Returns 1 ; On Failure - Returns 0 Example of my script using _ImageSearch ( entire screen search) #include <ImageSearch.au3> HotKeySet("p", "checkForImage") global $y = 0, $x = 0 Func checkForImage() Local $search = _ImageSearch('checkImage.bmp', 0, $x, $y, 0) If $search = 1 Then MouseMove($x, $y, 10) EndIf EndFunc while 1 sleep(200) WEnd Example of my script using _ImageSearchArea #include <ImageSearch.au3> HotKeySet("p", "checkForImage") global $y = 0, $x = 0 Func checkForImage() local $search = _ImageSearchArea('check5.bmp', 1, 800, 40, 900, 80, $x, $y, 0) If $search = 1 Then MouseMove($x, $y, 10) EndIf EndFunc while 1 sleep(200) WEnd I would like to apologize if by writing this I offended any of member that thinks this script is too simple to even have it explained, it's just as me being new to autoIt it took me so much time getting around errors and making this script to work. Thanks for reading, if you bump on any problems using it post it here, I will try to help you fixing it and update topic for further reference. Download links: 32bit: ImageSearch 32bit.rar 64bit: ImageSearch 64 bit.rar
    1 point
  3. Now replaced by a new version of the UDF in this link. <hr> [NEW VERSION] - 7 Mar 16 Added: A new option for $iAdded (+ 512) allows you to select just one cell of the ListView rather than the whole row. A new function _GUIListViewEx_SetDefColours allows the user to set the default colours when using either or both the "colour" and "single cell selection" options. Another new function _GUIListViewEx_BlockReDraw which prevents ListView redrawing during looped Insert/Delete/Change calls - this greatly speeds up execution by avoiding lengthy redrawing when using either or both the "colour" and "single cell selection" options, use of which forces the redraw to use a WM_NOTIFY handler within the script. Changed: A number of minor internal changes to speed up the loading of the ListView when using either or both of the "colour" and "single cell selection" options. A slightly modified Example_6 script shows the new functions in use. The LH native ListView can have rows and columns added/removed using both the old and new functions and has a context menu to allow for colour selection. The contents of this ListView can be mirrored to the RH UDF-created ListView which has "single cell selection" enabled and allows the colours of any item (including the selected cell) to be changed programmatically. New UDF in the zip below. Previous changes: ChangeLog.txt Hi, It seemed that I wanted to add, delete, edit or move items in a ListView quite often in my scripts and I got fed up with having to rewrite the code to do it each time. I also wanted to be able to drag items within and between ListViews with the mouse, plus edit the items. So I decided to write a UDF to make life easier and here is the result - GUIListViewEx. If you are interested in how it works, then read this bit - if not, then skip over it: The UDF is pretty easy to use: - You start by creating a ListView (either native or UDF) and passing the returned ControlID/handle and the array you used to fill it to the _Init function of the UDF. You also indicate whether the array has a count in the [0] (or [0][0]) element and if you create an empty ListView, the UDF will still cope and will shadow any items that you insert later. If you have a ListView filled with data but no matching array, there is a function to read that data into an array for you. You can select a colour for the insert mark when dragging items if you are going to use this feature - the default is black - and decide whether to have a shadow of the dragged item follow the mouse. Finally you can set the ListView to be sortable, editable - with various options to determine how the editing process works, determine external drag/drop behaviour and whether user colours are used. - You need to register a few Windows messages, but this is a single call to the _MsgRegister function. If you already have handlers for the relevant messages, there are functions to call within these handlers instead. If you do not want to drag, then you only need the WM_NOTIFY handler loaded. - Then you just need to call the main _Insert($vData), _Delete, _Up, and _Down functions when the appropriate button is pressed, select and drag items, or use one of the edit functions and your ListView responds automatically. - The UDF shadows the contents of the ListView (as explained in the spoiler section above) so you can get its current state at any time with the _ReturnArray function . Many of the functions actually return this data after each call just to help you keep track and there are dedicated Save/Load functions. - If enabled, the user can colour individual items within the ListView - and can set certain elements to be coloured on loading if required. - There are a couple of functions that you need to run in your idle loop if you need the functionality - they detect when items are dragged and edited. - When you have finished with the ListView, you should use the _Close function to clear the memory used by the UDF to shadow its contents. It is not vital, but if you use a lot of ListViews and do not do this, you could end up running out of memory. - You can have as many ListViews as you wish on display at any one time and the same "Insert", "Delete", "Up" and "Down" buttons can be used for them all - you just have to click on the one you want to be active. The UDF also allows you to set the active ListView programatically (_SetActive) - and to determine which is currently active (_GetActive). There are also additional Insert/DeleteSpec functions which allow you to action non-active ListViews. There are 6 example scripts to show the UDF working on native and UDF created ListViews, with single or multiple columns and either filled or empty, along with the UDF itself in this zip file: Credit to martin (for the basic drag code which I found on the forum), the Array UDF authors (for the basis of the array functions) and LarsJ (for the basic colour handler code). Happy for any feedback - hopefully positive! M23
    1 point
  4. A utility to look up constants in the Include files Countless times in writing or debugging I’ve interrupted my train of thought to go look up the numeric value of a named constant ... or worse, had to figure out which include file reference is needed. I finally got around to looking for a solution. (Actually, I’ve never understood why there hasn’t been some standard feature—in SciTE?— to do this. But I digress.) What I found was a pair of ready-to-use functions (from “Mat”) in the example files from 2009. They are everything I envisioned for the “lookup side” of the problem, but they lacked a GUI for convenient use. Encouraged by the possibilities, I began to work with richedit, drag/drop and WM_COMMAND (thanks, Melba23!), and I've now put all the pieces together into a desktop utility. (Caution to coding purists: I sought a solution, here—not programming art ... so you’ll see some “quick fix” code ... even (aghast!) some straight-line coding. I’m always interested in readable code and function trumps form, for me—certainly at this moment.) That said, I did add some touches using simple GUI methods: frameless ... draggable ... on top ... with some basic uses of transparency and parent drag. I wanted to stay away from GDI+. It’s great, but I’ve done enough at that level to really develop an appreciation for SIMPLE. Simple is so much easier to troubleshoot! But these forums are great sources of information for both levels. I’m continually amazed at what knowledge is embodied in the posts. Sometimes it takes a while—and some directional assistance—to ferret it out. But it’s there. [screen image] How to use the utility: Easiest use: just drag the text string for the constant into the lower box and let it go. (caveat: when dragging from SciTE, you MUST hold down the CTRL key to keep it from removing the text from your script—but more on that, below.) Or, you can type (or paste/edit) the name of the constant into the upper box and then click Find. Either way, the utility finds the occurrence (or occurrences) in the include files and shows the file(s), plus the numeric value for the constant. The other main feature (as afforded by Mat’s second function) is to type in (or paste) a numeric value into the top field and click Find. The utility will display an array of all the include files that have a constant with that value. A third use (which I took the liberty of modifying Mat’s functions to implement) is to look up references to include files that occur in the standard UDFs (those on the Include directory). As you might expect, “#i” is the trigger string for the lookup. For simplicity’s sake, only the first seven occurrences are listed. This feature is more a proof of concept than anything else, as it demonstrates how this simple utility might be expanded or adapted for other uses. Technical note on the drag/drop from SciTE: Let me be clear: dragging a constant from the SciTE window to the Lookup Utility WITHOUT USING THE CTRL KEY REMOVES IT from the script. Ctrl+Z is required to restore it. (Curiously, you can drag the same constant to WorkPad and it stays in SciTE.) I toyed with ways to automatically issue that restore, but SciTE apparently doesn’t accept sent keystrokes. Nine different attempts yielded nothing, so I dropped the idea. Later, I found these two entries on Google Groups: “In the simplest case, the target of a drag and drop action receives a copy of the data being dragged, and the source decides whether to delete the original. “ “There is no (SciTE) option. The code that controls this is in /scintilla/gtk/ScintillaGTK.cxx ScintillaGTK::DragMotionThis where preferredAction = GDK_ACTION_MOVE can be changed to GDK_ACTION_COPY.” Link: https://groups.google.com/forum/#!topicsearchin/scite-interest/drag/scite-interest/2AZzHfnfFIQ Apparently there’s at least the possibility of a solution. Programming notes: • Yes, the fonts are large. I trust I’m not the only one annoyed by tiny fonts on large screens. Anyone running a desktop setting of 125% or 150% with have to tune accordingly. • The progress bar exists only to give some indication of action. • The utility assumes you’re entering a findable name or number. Some minimal pre-check of the requested text would be worthwhile to avoid false runs. • Also, it would appear to be an easy extension to add “F” (for Func) as a 3rd trigger to locate functions in UDFs. The top entry field is a little wider to accommodate this eventuality, given that some names are long. Another obvious possibility is to bring the searched directory to the forefront and make it selectable so any group of au3 files can be searched. Right now, only the standard and user include directories are looked at. All that said, let me restate the main purpose: Provides a convenient desktop utility that locates a constant name (or value) in the include files. Anything more is icing ... but never forget the two-layer cake of simplicity and convenience! Well, that’s it, for now. Suggestions and advice are welcome; criticism, not so much! Lookup.zip IMPORTANT NOTE: Footnote: Mat’s functions did require one change for a compiled version to operate correctly: @AutoItExe >> $AutoItExe (“@AutoItExe is the full path and filename of the AutoIt executable currently running. For compiled scripts it is the path of the compiled script; for .a3x and .au3 files it is the path of the interpreter running the file.”) The functions must know where the actual AutoIt3.exe actually is ... and hence, where the Include files are.
    1 point
  5. JohnOne

    Failing at Variables

    Func Java() Local $Verify = 0 If FileCopy("\\fileserver01\disks\cody\java\deployment.properties", @UserProfileDir & "\appdata\locallow\sun\java\deployment", $FC_OVERWRITE) Then $Verify = MsgBox(0, "Verify", "Verify your Java and then run the script again!") If $Verify = 1 Then Run("C:\Program Files\Internet Explorer\IEXPLORE.EXE -new http://www.java.com/verify", "") If $Verify = 1 Then FileDelete(@UserProfileDir & "\appdata\locallow\sun\java\deployment") ShellExecuteWait(@UserProfileDir & "\appdata\locallow\sun\java\deployment") Else Exit MsgBox(0, 0, "Failed to copy file") EndIf EndFunc ;==>Java
    1 point
  6. qwert, Could I suggest that rather than asking the user to set the AutoIt path: $AutoitEXE = "C:\AutoIt3\AutoIt3.exe" ; <<< modify this if your copy is elsewhere <<< you check the location of the include folder automatically? And of course there could well be other folders in which the user has placed include files - see the Adding UDFs to AutoIt and SciTE tutorial in the Wiki to see how it is done. In the UserCallTip utility I collect all the include paths like this (They are delimited with "|" because the result goes into a combo): ; Create Include folder list Local $sInclude_Folders ; This returns a ";" delimited list of user created include folders Local $sUser_Folder = RegRead("HKEY_CURRENT_USER\Software\AutoIt v3\AutoIt", "Include") Local $aUser_Folder = StringSplit($sUser_Folder, ";") For $i = 1 To $aUser_Folder[0] If $aUser_Folder[$i] <> "" Then $sInclude_Folders &= $aUser_Folder[$i] & "\|" EndIf Next ; Now add the standard include folder Local $sAutoIt_Path = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\AutoIt3.exe", "") Local $sAutoIt_Folder = StringRegExpReplace($sAutoIt_Path, "(^.*\\)(.*)", "$1") $sInclude_Folders &= $sAutoIt_Folder & "Include\" Then you will always be sure to search on the correct paths. M23
    1 point
  7. Run(@ComSpec & " /c copy /b *.txt all.txt")
    1 point
  8. Without Bass.dll you can use my DirectSound UDF to decode the mp3.: http://autoit.de/index.php?page=Thread&postID=361564#post361564 And then look for the peaks. #include "DirectSound.au3" Global $hFile = FileOpen("Test.mp3", 16) Global $bMP3 = FileRead($hFile) FileClose($hFile) Local $aWav = _DSnd_MP3Decode($bMP3) _FindSilence($aWav) Func _FindSilence($aWav, $fThreshold = 0.05) Local $iWavLen = BinaryLen($aWav[0]) Local $iSamples = $iWavLen * 0.5 Local $tWav = DllStructCreate("byte[" & $iWavLen & "];") Local $tWavSmp = DllStructCreate("short[" & $iSamples & "];", DllStructGetPtr($tWav)) DllStructSetData($tWav, 1, $aWav[0]) Local $iThrHld = 32768 * $fThreshold Local $iStart = 0 For $i = 1 To $iSamples * 0.5 If Abs(DllStructGetData($tWavSmp, 1, $i)) >= $iThrHld Then ExitLoop $iStart = $i Next Local $iEnd = $iSamples For $i = $iSamples To $iSamples * 0.5 Step -1 $iEnd = $i If Abs(DllStructGetData($tWavSmp, 1, $i)) >= $iThrHld Then ExitLoop Next Local $fMSStart = $iStart / $aWav[1].SamplesPerSec / $aWav[1].Channels * 1000 Local $fMSEnd = $iEnd / $aWav[1].SamplesPerSec / $aWav[1].Channels * 1000 ConsoleWrite("> MSStart:" & $fMSStart & " MSEnd:" & $fMSEnd & @CRLF) EndFunc ;==>_FindSilence E Edit: faster, using ASM ;#include "FASM.au3" #include "DirectSound.au3" #include <Memory.au3> Global Const $bASM_SilenceStart_32 = "0x538B5424088B4C240C668B5C2410668B026609C0790366F7D86639D87C0489C8EB0883C20283E9017FE45BC20C00" Global Const $bASM_SilenceStart_64 = "0x668B016609C0790366F7D8664439C07C0489D0EB094883C10283EA017FE2C3" Global Const $bASM_SilenceEnd_32 = "0x538B5424088B4C240C668B5C241001CA01CA83EA02668B026609C0790366F7D86639D87C0489C8EB0583E9017FE45BC20C00" Global Const $bASM_SilenceEnd_64 = "0x4801D14801D14883E902668B016609C0790366F7D8664439C07C0489D0EB0583EA017FE2C3" Global $hFile = FileOpen("Test.mp3", 16) Global $bMP3 = FileRead($hFile) FileClose($hFile) Global $aWav = _DSnd_MP3Decode($bMP3) Global $aCut = _FindSilence($aWav) Global $bNew = _CutMP3($bMP3, $aCut[0], $aCut[1]) $hFile = FileOpen("New.mp3", 18) FileWrite($hFile, $bNew) FileClose($hFile) Func _FindSilence($aWav, $fThreshold = 0.1) Local $pASM_Start, $_pASM_Start, $pASM_End, $_pASM_End Switch @AutoItX64 Case 0 $pASM_Start = __ASMCreate($bASM_SilenceStart_32, $_pASM_Start) $pASM_End = __ASMCreate($bASM_SilenceEnd_32, $_pASM_End) Case Else $pASM_Start = __ASMCreate($bASM_SilenceStart_64, $_pASM_Start) $pASM_End = __ASMCreate($bASM_SilenceEnd_64, $_pASM_End) EndSwitch Local $iWavLen = BinaryLen($aWav[0]) Local $iSamples = $iWavLen * 0.5 Local $tWav = DllStructCreate("byte[" & $iWavLen & "];") DllStructSetData($tWav, 1, $aWav[0]) Local $iThrHld = 32768 * $fThreshold Local $aResult = DllCallAddress("uint", $pASM_Start, "struct*", $tWav, "uint", $iSamples, "short", $iThrHld) Local $iStart = $iSamples - $aResult[0] Local $aResult = DllCallAddress("uint", $pASM_End, "struct*", $tWav, "uint", $iSamples, "short", $iThrHld) Local $iEnd = $aResult[0] Local $fMSStart = $iStart / $aWav[1].SamplesPerSec / $aWav[1].Channels * 1000 Local $fMSEnd = $iEnd / $aWav[1].SamplesPerSec / $aWav[1].Channels * 1000 _MemVirtualFree($_pASM_Start, 0, $MEM_RELEASE) _MemVirtualFree($_pASM_End, 0, $MEM_RELEASE) Local $aRet[2] $aRet[0] = $fMSStart $aRet[1] = $fMSEnd Return $aRet EndFunc ;==>_FindSilence Func _CutMP3(ByRef $bMP3, $iMSStart, $iMSEnd, $bID3v2 = True) $iMSStart /= 1000 $iMSEnd /= 1000 Local $iMP3Len = BinaryLen($bMP3) Local $tMP3 = DllStructCreate("char[" & $iMP3Len * 2 & "]; byte[2882];") Local $pMP3 = DllStructGetPtr($tMP3) DllStructSetData($tMP3, 1, StringTrimLeft($bMP3, 2)) Local $aHeader = _MP3_GetHeaders($bMP3) Local $bNew = BinaryMid(0, 1, 0) If $bID3v2 And $aHeader[1][0] > 0 Then ;Id3v2Tag $bNew = BinaryMid($bMP3, 1, $aHeader[1][0]) ;ID3v2 EndIf Local $iFirstHeader = 1 Local $iXingVBRIFrames = __MP3_GetFrameCountXINGVBRI($pMP3 + $aHeader[1][0] * 2) If Not @error And $iXingVBRIFrames > 0 Then $iFirstHeader = 2 ;Skip XING / VBRI Frame Local $iMS = 0, $iFrameStart = $iFirstHeader For $i = $iFirstHeader To $aHeader[0][0] ;Skip $iMSStart Milliseconds $iMS += $aHeader[$i][5] / $aHeader[$i][2] If $iMS >= $iMSStart Then ExitLoop $iFrameStart = $i Next Local $iFrameEnd For $i = $iFrameStart To $aHeader[0][0] ;Add Frames $iMSStart to $iMSEnd $iFrameEnd = $i $iMS += $aHeader[$i][5] / $aHeader[$i][2] If $iMS > $iMSEnd Then ExitLoop Next $tMP3 = DllStructCreate("byte[" & $iMP3Len * 2 & "];") $pMP3 = DllStructGetPtr($tMP3) DllStructSetData($tMP3, 1, $bMP3) Local $tNew = DllStructCreate("byte[" & $aHeader[$iFrameEnd][0] - $aHeader[$iFrameStart][0] & "]", $pMP3 + $aHeader[$iFrameStart][0]) $bNew &= DllStructGetData($tNew, 1) Return $bNew EndFunc ;==>_CutMP3 Func _MP3_GetHeaders(Const ByRef $bMP3, $iMaxHeaders = -1, $iMaxErrors = 99, $bToolTip = True) ;by Eukalyptus AutoIt.de Local $iMP3Len = BinaryLen($bMP3) Local $tMP3 = DllStructCreate("char[" & $iMP3Len * 2 & "]; byte[2882];") Local $pMP3 = DllStructGetPtr($tMP3) DllStructSetData($tMP3, 1, StringTrimLeft($bMP3, 2)) Local $aHeader[128][6] = [[0, "BitRate", "SampleRate", "Chan", "FrameSize", "Samples"]] __MP3_GetHeaders($pMP3, $iMP3Len, $aHeader, $iMaxHeaders, $iMaxErrors, $bToolTip) Return $aHeader EndFunc ;==>_MP3_GetHeaders ;############################################################################################################ ;# Internal MP3 Functions ;############################################################################################################ Func __MP3_GetHeaders($pMP3, $iMP3Len, ByRef $aHeader, $iMaxHeaders = -1, $iMaxErrors = 99, $bToolTip = True) ;by Eukalyptus AutoIt.de $iMaxHeaders = Dec(Hex($iMaxHeaders, 8), 2) ;-1=4294967295 Local $iMP3Pos = 0, $iCnt = 1, $iTmpOff, $iError = 0 While $iCnt <= $iMaxHeaders $iTmpOff = $iMP3Pos If Not __MP3_GetFrameHeaderInfo($pMP3 + $iMP3Pos * 2, $iMP3Pos, $aHeader[$iCnt][1], $aHeader[$iCnt][2], $aHeader[$iCnt][3], $aHeader[$iCnt][4], $aHeader[$iCnt][5]) Then If $iMP3Pos >= $iMP3Len - 1440 Then $aHeader[$iCnt][0] = $iMP3Pos $iCnt += 1 ExitLoop ;End of file EndIf $iMP3Pos = $iTmpOff __MP3_SkipID3v2TAG($pMP3 + $iMP3Pos * 2, $iTmpOff) ;maybe ID3v2 inside MP3 Stream!? If $iTmpOff = $iMP3Pos Then ;no ID3v2 or no FrameHeader ahead $iError += 1 If $iError > $iMaxErrors Then ExitLoop $iMP3Pos += 26 ;try offset of MinFrameSize (8KBit, 22050Hz) Else $iMP3Pos = $iTmpOff; ID3v2 offset EndIf Else $aHeader[$iCnt][0] = $iMP3Pos - $aHeader[$iCnt][4] $iCnt += 1 If $iCnt >= UBound($aHeader) Then ReDim $aHeader[$iCnt * 2][6] If $bToolTip And Not Mod($iCnt, 1000) Then ToolTip(StringFormat("%.2f%%", $iMP3Pos * 100 / $iMP3Len)) EndIf WEnd If $bToolTip Then ToolTip("") $aHeader[0][0] = $iCnt - 1 ReDim $aHeader[$iCnt][6] Return $iError EndFunc ;==>__MP3_GetHeaders Func __MP3_GetFrameHeaderInfo($pMP3, ByRef $iMP3Pos, ByRef $iBitRate, ByRef $iSampleRate, ByRef $iChan, ByRef $iFrameSize, ByRef $iSamples) ;by Eukalyptus AutoIt.de ;[ Byte 1 ][ Byte 2 ][ Byte 3 ][ Byte 4 ] ;[1][1][1][1][1][1][1][1][1][1][1][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ] ;|_______________________________|| ||____|| ||__________|| ||_|| ||____|| ||_|| ||____| ; |____| |_| |____| |_| |____| |_| ; Sync Layer BitRate Pad Chan Copy Emph ; ID Protect Freq Prv ModEx Orig Local $aRegExp, $iRegExpOff, $iMod, $iHeader, $iID, $iBRate, $iBRM, $fBRF, $iPad Local $tMP3 = DllStructCreate("char[2882];", $pMP3) $aRegExp = StringRegExp(DllStructGetData($tMP3, 1), "FF[FE][23AB].{4}", 1) ;Match Header Mpeg(1/2/2.5) - Layer_III - ProtectionBit ON/OFF If @error Then Return SetError(1, 1, False) $iRegExpOff = @extended - 9 $iMod = Mod($iRegExpOff, 2) $iRegExpOff += $iMod $iMP3Pos += $iRegExpOff * 0.5 If Not $iMod Then ;Byte boundaries $iHeader = Dec($aRegExp[0], 1) $iID = BitAND(BitShift($iHeader, 19), 0x3) Switch $iID Case 0, 2 ;Mpeg2/2.5 $iSamples = 576 Case 3 ;Mpeg1 $iSamples = 1152 Case Else ; 1 = reserved Return SetError(1, 2, False) EndSwitch If BitAND(BitShift($iHeader, 17), 0x3) <> 1 Then Return SetError(1, 3, False) ; <> Layer III $iBRate = BitAND(BitShift($iHeader, 12), 0xF) Switch $iID Case 3 ;MPEG Version 1 $iBRM = Mod($iBRate + 2, 4) + 1 $fBRF = 2 ^ BitShift($iBRate + 2, 2) $iBitRate = 16 * $fBRF + 4 * $fBRF * $iBRM Case Else ;MPEG Version 2.5 + MPEG Version 2 $iBRM = Mod($iBRate - 1, 8) + 1 $fBRF = 2 ^ BitShift($iBRate - 1, 3) $iBitRate = 8 * $fBRF * $iBRM + 64 * ($fBRF - 1) EndSwitch Switch BitAND(BitShift($iHeader, 10), 0x3) Case 0 $iSampleRate = 11025 Case 1 $iSampleRate = 12000 Case 2 $iSampleRate = 8000 Case Else ; 3 = reserved Return SetError(1, 4, False) EndSwitch Switch $iID Case 2 $iSampleRate *= 2 ;Mpeg2 = 16000, 24000, 22050 Case 3 $iSampleRate *= 4 ;Mpeg1 = 32000, 48000, 44100 EndSwitch $iPad = BitAND(BitShift($iHeader, 9), 0x1) $iChan = (BitAND(BitShift($iHeader, 6), 0x3) <> 4) + 1 ;0,1=Stereo 2=DualMono 3=Mono $iFrameSize = Int((($iSamples / 0.008) * $iBitRate / $iSampleRate)) + $iPad $tMP3 = DllStructCreate("char[3];", $pMP3 + $iRegExpOff + $iFrameSize * 2) Switch DllStructGetData($tMP3, 1) Case "FFF", "FFE" $iMP3Pos += $iFrameSize Case Else Return SetError(1, 5, False) ;FrameSize offset does not match a FrameHeader - something went wrong EndSwitch Return True EndIf Return SetError(1, 6, False) EndFunc ;==>__MP3_GetFrameHeaderInfo Func __MP3_SkipID3v2TAG($pMP3, ByRef $iMP3Pos) ;by Eukalyptus AutoIt.de ;[49][44][33][xx][xx][yy][zz][zz][zz][zz] ;| ||______|| ||______________| ;|__________| |__| ; Version TagSize ; "ID3" Flags Local $iPos, $iHeader, $iFlags Local $tMP3 = DllStructCreate("char[2882];", $pMP3) Local $aRegExp = StringRegExp(DllStructGetData($tMP3, 1), "494433.{14}", 1) If @error Then Return SetError(0, 0, False) $iPos = @extended - 21 If Mod($iPos, 2) Then Return SetError(1, 0, False) ;TAG not at Byte-Boundaries $iPos *= 0.5 $iHeader = Dec(StringRight($aRegExp[0], 8)) If BitAND($iHeader, 0xFF) > 0x7F Or BitAND(BitShift($iHeader, 8), 0xFF) > 0x7F Or BitAND(BitShift($iHeader, 16), 0xFF) > 0x7F Or BitAND(BitShift($iHeader, 24), 0xFF) > 0x7F Then Return SetError(1, 1, False);Size Bytes <= 7F! If BitAND(BitShift($iHeader, 40), 0xFF) = 0xFF Or BitAND(BitShift($iHeader, 48), 0xFF) = 0xFF Then Return SetError(1, 2, False);Version Bytes <> FF! $iFlags = Dec(StringLeft(StringTrimLeft($aRegExp[0], 10), 2)) $iPos += BitOR(BitAND($iHeader, 0x7F), BitShift(BitAND($iHeader, 0x7F00), 1), BitShift(BitAND($iHeader, 0x7F0000), 2), BitShift(BitAND($iHeader, 0x7F000000), 3)) + (10 * BitShift(BitAND($iFlags, 0x8), 3)) + 10 $tMP3 = DllStructCreate("char[3];", $pMP3 + $iPos * 2) Switch DllStructGetData($tMP3, 1) Case "FFF", "FFE" $iMP3Pos += $iPos Case Else Return SetError(1, 3, False) ;Pos does not match a FrameHeader - something went wrong EndSwitch Return True EndFunc ;==>__MP3_SkipID3v2TAG Func __MP3_GetFrameCountXINGVBRI($pMP3) ;by Eukalyptus AutoIt.de Local $tMP3 = DllStructCreate("char[2882];", $pMP3) ;[58][69][6E][67][xx][xx][xx][xx][yy][yy][yy][yy][zz][zz][zz][zz][tt][tt][tt][tt][tt][tt]... ;|______________|| ||______________||______________||__________________________ ; |______________| ; "Xing" Frames Bytes 100 [Bytes] TOC ; Flags: 0x1 0x2 0x4 Local $aRegExp = StringRegExp(DllStructGetData($tMP3, 1), "(58696E67)(.{8})(.{8})", 3) ;"Xing" If Not @error Then If BitAND(Dec($aRegExp[1]), 1) = 1 Then Return Dec($aRegExp[2]) Else ;[56][42][52][49][xx][xx][yy][yy][zz][zz][xx][xx][xx][xx][yy][yy][yy][yy][zz][zz][xx][xx][yy][yy][zz][zz][xx][xx][xx][xx][xx]... ;|______________|| ||______|| ||______________|| ||______|| ||______|| ||______________________ ; |______| |______| |______________| |______| |______| ; "VBRI" Delay Bytes TOC Count Size TOC [size*count) ; Version Quality Frames Scale Frames/Entry $aRegExp = StringRegExp(DllStructGetData($tMP3, 1), "(56425249)(.{4})(.{4})(.{4})(.{8})(.{8})", 3) ;"VBRI" If Not @error Then Return Dec($aRegExp[5]) EndIf Return 0 EndFunc ;==>__MP3_GetFrameCountXINGVBRI #ASM _ASM_SilenceStart_32 # use32 # push ebx # mov edx, [esp+8] # mov ecx, [esp+12] # mov bx, [esp+16] # _Loop: # mov ax, [edx] # or ax, ax # jns _AbsResult # neg ax # _AbsResult: # cmp ax, bx # jl _Cont # mov eax, ecx # jmp _Ret # _Cont: # add edx, 2 # sub ecx, 1 # jg _Loop # _Ret: # pop ebx # ret 12 #ASMEND #ASM _ASM_SilenceStart_64 # use64 # _Loop: # mov ax, [rcx] # or ax, ax # jns _AbsResult # neg ax # _AbsResult: # cmp ax, r8w # jl _Cont # mov eax, edx # jmp _Ret # _Cont: # add rcx, 2 # sub edx, 1 # jg _Loop # _Ret: # ret #ASMEND #ASM _ASM_SilenceEnd_32 # use32 # push ebx # mov edx, [esp+8] # mov ecx, [esp+12] # mov bx, [esp+16] # add edx, ecx # add edx, ecx # _Loop: # sub edx, 2 # mov ax, [edx] # or ax, ax # jns _AbsResult # neg ax # _AbsResult: # cmp ax, bx # jl _Cont # mov eax, ecx # jmp _Ret # _Cont: # sub ecx, 1 # jg _Loop # _Ret: # pop ebx # ret 12 #ASMEND #ASM _ASM_SilenceEnd_64 # use64 # add rcx, rdx # add rcx, rdx # _Loop: # sub rcx, 2 # mov ax, [rcx] # or ax, ax # jns _AbsResult # neg ax # _AbsResult: # cmp ax, r8w # jl _Cont # mov eax, edx # jmp _Ret # _Cont: # sub edx, 1 # jg _Loop # _Ret: # ret #ASMEND Func __ASMCreate(Const ByRef $bBinaryCode, ByRef $pPtr) Local $iSize = BinaryLen($bBinaryCode) $pPtr = _MemVirtualAlloc(0, $iSize + 16, $MEM_COMMIT, $PAGE_EXECUTE_READWRITE) Local $pStruct = Number($pPtr) $pStruct = $pStruct + 16 - Mod($pStruct, 16) Local $tStruct = DllStructCreate("byte[" & $iSize & "];", $pStruct) DllStructSetData($tStruct, 1, $bBinaryCode) Return $pStruct EndFunc ;==>__ASMCreate
    1 point
  9. Or you trim the frames yourself: ;#include <Array.au3> Global $hFile = FileOpen("Test.mp3", 16) Global $bMP3 = FileRead($hFile) FileClose($hFile) ;MP3: [..........................................] ; | | ; 2s 6s ; |_______________| ; 4s Global $bNew = _CutMP3($bMP3, 2000, 6000) $hFile = FileOpen("New.mp3", 18) FileWrite($hFile, $bNew) FileClose($hFile) Func _CutMP3(ByRef $bMP3, $iMSStart, $iMSEnd, $bID3v2 = True) $iMSStart /= 1000 $iMSEnd /= 1000 Local $iMP3Len = BinaryLen($bMP3) Local $tMP3 = DllStructCreate("char[" & $iMP3Len * 2 & "]; byte[2882];") Local $pMP3 = DllStructGetPtr($tMP3) DllStructSetData($tMP3, 1, StringTrimLeft($bMP3, 2)) Local $aHeader = _MP3_GetHeaders($bMP3) ;_ArrayDisplay($aHeader) Local $bNew = BinaryMid(0, 1, 0) If $bID3v2 And $aHeader[1][0] > 0 Then ;Id3v2Tag $bNew = BinaryMid($bMP3, 1, $aHeader[1][0]) ;ID3v2 EndIf Local $iFirstHeader = 1 Local $iXingVBRIFrames = __MP3_GetFrameCountXINGVBRI($pMP3 + $aHeader[1][0] * 2) If Not @error And $iXingVBRIFrames > 0 Then $iFirstHeader = 2 ;Skip XING / VBRI Frame Local $iMS = 0, $iFrameStart = $iFirstHeader For $i = $iFirstHeader To $aHeader[0][0] ;Skip $iMSStart Milliseconds $iMS += $aHeader[$i][5] / $aHeader[$i][2] If $iMS >= $iMSStart Then ExitLoop $iFrameStart = $i Next For $i = $iFrameStart To $aHeader[0][0] ;Add Frames $iMSStart to $iMSEnd $bNew &= BinaryMid($bMP3, $aHeader[$i][0], $aHeader[$i][4]) $iMS += $aHeader[$i][5] / $aHeader[$i][2] If $iMS > $iMSEnd Then ExitLoop Next Return $bNew EndFunc ;==>_CutMP3 Func _MP3_GetHeaders(Const ByRef $bMP3, $iMaxHeaders = -1, $iMaxErrors = 99, $bToolTip = True) ;by Eukalyptus AutoIt.de Local $iMP3Len = BinaryLen($bMP3) Local $tMP3 = DllStructCreate("char[" & $iMP3Len * 2 & "]; byte[2882];") Local $pMP3 = DllStructGetPtr($tMP3) DllStructSetData($tMP3, 1, StringTrimLeft($bMP3, 2)) Local $aHeader[128][6] = [[0, "BitRate", "SampleRate", "Chan", "FrameSize", "Samples"]] __MP3_GetHeaders($pMP3, $iMP3Len, $aHeader, $iMaxHeaders, $iMaxErrors, $bToolTip) Return $aHeader EndFunc ;==>_MP3_GetHeaders ;############################################################################################################ ;# Internal MP3 Functions ;############################################################################################################ Func __MP3_GetHeaders($pMP3, $iMP3Len, ByRef $aHeader, $iMaxHeaders = -1, $iMaxErrors = 99, $bToolTip = True) ;by Eukalyptus AutoIt.de $iMaxHeaders = Dec(Hex($iMaxHeaders, 8), 2) ;-1=4294967295 Local $iMP3Pos = 0, $iCnt = 1, $iTmpOff, $iError = 0 While $iCnt <= $iMaxHeaders $iTmpOff = $iMP3Pos If Not __MP3_GetFrameHeaderInfo($pMP3 + $iMP3Pos * 2, $iMP3Pos, $aHeader[$iCnt][1], $aHeader[$iCnt][2], $aHeader[$iCnt][3], $aHeader[$iCnt][4], $aHeader[$iCnt][5]) Then If $iMP3Pos >= $iMP3Len - 1440 Then $aHeader[$iCnt][0] = $iMP3Pos $iCnt += 1 ExitLoop ;End of file EndIf $iMP3Pos = $iTmpOff __MP3_SkipID3v2TAG($pMP3 + $iMP3Pos * 2, $iTmpOff) ;maybe ID3v2 inside MP3 Stream!? If $iTmpOff = $iMP3Pos Then ;no ID3v2 or no FrameHeader ahead $iError += 1 If $iError > $iMaxErrors Then ExitLoop $iMP3Pos += 26 ;try offset of MinFrameSize (8KBit, 22050Hz) Else $iMP3Pos = $iTmpOff; ID3v2 offset EndIf Else $aHeader[$iCnt][0] = $iMP3Pos - $aHeader[$iCnt][4] $iCnt += 1 If $iCnt >= UBound($aHeader) Then ReDim $aHeader[$iCnt * 2][6] If $bToolTip And Not Mod($iCnt, 1000) Then ToolTip(StringFormat("%.2f%%", $iMP3Pos * 100 / $iMP3Len)) EndIf WEnd If $bToolTip Then ToolTip("") $aHeader[0][0] = $iCnt - 1 ReDim $aHeader[$iCnt][6] Return $iError EndFunc ;==>__MP3_GetHeaders Func __MP3_GetFrameHeaderInfo($pMP3, ByRef $iMP3Pos, ByRef $iBitRate, ByRef $iSampleRate, ByRef $iChan, ByRef $iFrameSize, ByRef $iSamples) ;by Eukalyptus AutoIt.de ;[ Byte 1 ][ Byte 2 ][ Byte 3 ][ Byte 4 ] ;[1][1][1][1][1][1][1][1][1][1][1][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ] ;|_______________________________|| ||____|| ||__________|| ||_|| ||____|| ||_|| ||____| ; |____| |_| |____| |_| |____| |_| ; Sync Layer BitRate Pad Chan Copy Emph ; ID Protect Freq Prv ModEx Orig Local $aRegExp, $iRegExpOff, $iMod, $iHeader, $iID, $iBRate, $iBRM, $fBRF, $iPad Local $tMP3 = DllStructCreate("char[2882];", $pMP3) $aRegExp = StringRegExp(DllStructGetData($tMP3, 1), "FF[FE][23AB].{4}", 1) ;Match Header Mpeg(1/2/2.5) - Layer_III - ProtectionBit ON/OFF If @error Then Return SetError(1, 1, False) $iRegExpOff = @extended - 9 $iMod = Mod($iRegExpOff, 2) $iRegExpOff += $iMod $iMP3Pos += $iRegExpOff * 0.5 If Not $iMod Then ;Byte boundaries $iHeader = Dec($aRegExp[0], 1) $iID = BitAND(BitShift($iHeader, 19), 0x3) Switch $iID Case 0, 2 ;Mpeg2/2.5 $iSamples = 576 Case 3 ;Mpeg1 $iSamples = 1152 Case Else ; 1 = reserved Return SetError(1, 2, False) EndSwitch If BitAND(BitShift($iHeader, 17), 0x3) <> 1 Then Return SetError(1, 3, False) ; <> Layer III $iBRate = BitAND(BitShift($iHeader, 12), 0xF) Switch $iID Case 3 ;MPEG Version 1 $iBRM = Mod($iBRate + 2, 4) + 1 $fBRF = 2 ^ BitShift($iBRate + 2, 2) $iBitRate = 16 * $fBRF + 4 * $fBRF * $iBRM Case Else ;MPEG Version 2.5 + MPEG Version 2 $iBRM = Mod($iBRate - 1, 8) + 1 $fBRF = 2 ^ BitShift($iBRate - 1, 3) $iBitRate = 8 * $fBRF * $iBRM + 64 * ($fBRF - 1) EndSwitch Switch BitAND(BitShift($iHeader, 10), 0x3) Case 0 $iSampleRate = 11025 Case 1 $iSampleRate = 12000 Case 2 $iSampleRate = 8000 Case Else ; 3 = reserved Return SetError(1, 4, False) EndSwitch Switch $iID Case 2 $iSampleRate *= 2 ;Mpeg2 = 16000, 24000, 22050 Case 3 $iSampleRate *= 4 ;Mpeg1 = 32000, 48000, 44100 EndSwitch $iPad = BitAND(BitShift($iHeader, 9), 0x1) $iChan = (BitAND(BitShift($iHeader, 6), 0x3) <> 4) + 1 ;0,1=Stereo 2=DualMono 3=Mono $iFrameSize = Int((($iSamples / 0.008) * $iBitRate / $iSampleRate)) + $iPad $tMP3 = DllStructCreate("char[3];", $pMP3 + $iRegExpOff + $iFrameSize * 2) Switch DllStructGetData($tMP3, 1) Case "FFF", "FFE" $iMP3Pos += $iFrameSize Case Else Return SetError(1, 5, False) ;FrameSize offset does not match a FrameHeader - something went wrong EndSwitch Return True EndIf Return SetError(1, 6, False) EndFunc ;==>__MP3_GetFrameHeaderInfo Func __MP3_SkipID3v2TAG($pMP3, ByRef $iMP3Pos) ;by Eukalyptus AutoIt.de ;[49][44][33][xx][xx][yy][zz][zz][zz][zz] ;| ||______|| ||______________| ;|__________| |__| ; Version TagSize ; "ID3" Flags Local $iPos, $iHeader, $iFlags Local $tMP3 = DllStructCreate("char[2882];", $pMP3) Local $aRegExp = StringRegExp(DllStructGetData($tMP3, 1), "494433.{14}", 1) If @error Then Return SetError(0, 0, False) $iPos = @extended - 21 If Mod($iPos, 2) Then Return SetError(1, 0, False) ;TAG not at Byte-Boundaries $iPos *= 0.5 $iHeader = Dec(StringRight($aRegExp[0], 8)) If BitAND($iHeader, 0xFF) > 0x7F Or BitAND(BitShift($iHeader, 8), 0xFF) > 0x7F Or BitAND(BitShift($iHeader, 16), 0xFF) > 0x7F Or BitAND(BitShift($iHeader, 24), 0xFF) > 0x7F Then Return SetError(1, 1, False);Size Bytes <= 7F! If BitAND(BitShift($iHeader, 40), 0xFF) = 0xFF Or BitAND(BitShift($iHeader, 48), 0xFF) = 0xFF Then Return SetError(1, 2, False);Version Bytes <> FF! $iFlags = Dec(StringLeft(StringTrimLeft($aRegExp[0], 10), 2)) $iPos += BitOR(BitAND($iHeader, 0x7F), BitShift(BitAND($iHeader, 0x7F00), 1), BitShift(BitAND($iHeader, 0x7F0000), 2), BitShift(BitAND($iHeader, 0x7F000000), 3)) + (10 * BitShift(BitAND($iFlags, 0x8), 3)) + 10 $tMP3 = DllStructCreate("char[3];", $pMP3 + $iPos * 2) Switch DllStructGetData($tMP3, 1) Case "FFF", "FFE" $iMP3Pos += $iPos Case Else Return SetError(1, 3, False) ;Pos does not match a FrameHeader - something went wrong EndSwitch Return True EndFunc ;==>__MP3_SkipID3v2TAG Func __MP3_GetFrameCountXINGVBRI($pMP3) ;by Eukalyptus AutoIt.de Local $tMP3 = DllStructCreate("char[2882];", $pMP3) ;[58][69][6E][67][xx][xx][xx][xx][yy][yy][yy][yy][zz][zz][zz][zz][tt][tt][tt][tt][tt][tt]... ;|______________|| ||______________||______________||__________________________ ; |______________| ; "Xing" Frames Bytes 100 [Bytes] TOC ; Flags: 0x1 0x2 0x4 Local $aRegExp = StringRegExp(DllStructGetData($tMP3, 1), "(58696E67)(.{8})(.{8})", 3) ;"Xing" If Not @error Then If BitAND(Dec($aRegExp[1]), 1) = 1 Then Return Dec($aRegExp[2]) Else ;[56][42][52][49][xx][xx][yy][yy][zz][zz][xx][xx][xx][xx][yy][yy][yy][yy][zz][zz][xx][xx][yy][yy][zz][zz][xx][xx][xx][xx][xx]... ;|______________|| ||______|| ||______________|| ||______|| ||______|| ||______________________ ; |______| |______| |______________| |______| |______| ; "VBRI" Delay Bytes TOC Count Size TOC [size*count) ; Version Quality Frames Scale Frames/Entry $aRegExp = StringRegExp(DllStructGetData($tMP3, 1), "(56425249)(.{4})(.{4})(.{4})(.{8})(.{8})", 3) ;"VBRI" If Not @error Then Return Dec($aRegExp[5]) EndIf Return 0 EndFunc ;==>__MP3_GetFrameCountXINGVBRI E
    1 point
  10. jvanegmond

    C# Graphics +1

    When it runs in Visual Studio in Debug mode but not in production when you build it for Release, then optimizations are immediately suspect. Try this: using (hGfx = Graphics.FromImage(hBmp)) { hGfx.CopyFromScreen(x, y, 0, 0, size); } Also found this on with a similar problem and same solution: http://stackoverflow.com/questions/6788276/runtime-error-after-taking-screenshots-in-net
    1 point
  11. jaberwacky

    C# Graphics +1

    The only thing I can say is that if the error only crops up in the production exe then there are some compiler settings that you should investigate. I'm no expert on this so take that as you will.
    1 point
  12. kylomas

    String to 2D array

    Fixed... #include <array.au3> ; EOL delimited string with tab delimited columns ;~ local $str = '4010506 1341001 4019001 4010014 2425012 4010030' & @lf & _ ;~ '1 5 4 3 8 7 10 12' & @crlf & _ ;~ '1 5 4 3' & @lf & _ ;~ '1 5 4 3 8 7' local $str = fileread(@scriptdir & '\string_split_test.txt') _arraydisplay(_DBG_StringSplit2D($str, @tab),'String Converted to 2D Array') func _DBG_StringSplit2d(byref $str,$delimiter) ; #FUNCTION# ====================================================================================== ; Name ................: _DBG_StringSplit2D($str,$delimiter) ; Description .........: Create 2d array from delimited string ; Syntax ..............: _DBG_StringSplit2D($str, $delimiter) ; Parameters ..........: $str - EOL (@CR, @LF or @CRLF) delimited string to split ; $delimiter - Delimter for columns ; Return values .......: 2D array ; Author ..............: kylomas ; ================================================================================================= local $a1 = stringregexp($str,'.*?(?:\R|$)',3), $a2 local $rows = ubound($a1) - 1, $cols = 0 ; determine max number of columns by splitting each row and keeping highest ubound value for $i = 0 to ubound($a1) - 1 $a2 = stringsplit($a1[$i],$delimiter,1) if ubound($a2) > $cols then $cols = ubound($a2) next ; define and populate array local $aRET[$rows][$cols-1] for $i = 0 to $rows - 1 $a2 = stringsplit($a1[$i],$delimiter,3) for $j = 0 to ubound($a2) - 1 $aRET[$i][$j] = $a2[$j] Next next return $aRET endfunc
    1 point
  13. Gianni

    String to 2D array

    or even this (copy your data to the clipboard before run this listing) #include <array.au3> ; just to show result Local $aArray1 = StringSplit(StringStripCR(ClipGet()), @LF), $aArray2, $aResult[$aArray1[0]][1] For $i = 1 To $aArray1[0] $aArray2 = StringSplit($aArray1[$i], @TAB) If $aArray2[0] > UBound($aResult, 2) Then ReDim $aResult[$aArray1[0]][$aArray2[0]] For $i2 = 1 To $aArray2[0] $aResult[$i-1][$i2-1] = $aArray2[$i2] Next Next _ArrayDisplay($aResult) edit: skin as Function #include <array.au3> ; just to show result ; $sMyVar = ClipGet() ; from Clipboard to a variable _ArrayDisplay(_VarTo2D($sMyVar)) ; Func _VarTo2D($var, $sSeparator = @TAB) Local $aRows = StringSplit(StringStripCR($var), @LF), $aColumns, $aResult[$aRows[0]][1] For $iRow = 1 To $aRows[0] $aColumns = StringSplit($aRows[$iRow], $sSeparator) If $aColumns[0] > UBound($aResult, 2) Then ReDim $aResult[$aRows[0]][$aColumns[0]] For $iColumn = 1 To $aColumns[0] $aResult[$iRow - 1][$iColumn - 1] = $aColumns[$iColumn] Next Next Return $aResult EndFunc ;==>_VarTo2D
    1 point
  14. Danyfirex

    String to 2D array

    or this: #include <Array.au3> Local $str = "4010506 1341001 4019001 4010014 2425012 4010030" & @LF & _ "1 5 4 3 8 7" & @LF & _ "1 5 4 3 8 7" & @LF & _ "1 5 4 3 8 7" Local $aArray=StringSplit($str ," " & @CRLF) Local $iFilas=StringSplit($str,@CRLF) Local $iCol=StringSplit($iFilas[1]," ")[0] $iFilas=$iFilas[0] Local $aArray2D[$iFilas][$iCol] Local $i=0 For $f= 0 to $iFilas-1 For $c=0 to $iCol-1 $aArray2D[$f][$c]=$aArray[$i+$c+1] Next $i+=$iCol Next _ArrayDisplay($aArray2D) Saludos
    1 point
  15. Jambaman, Kimba is no more. M23
    1 point
  16. most likely but I am not aware that anyone has made AutoIT a scripting language that you can use within another host stuff like this should be possible but maybe the Developers of AutoIT know if anyone ever tried http://msdn.microsoft.com/en-us/library/fdee6589(v=vs.94).aspx http://msdn.microsoft.com/en-us/magazine/cc302278.aspx http://msdn.microsoft.com/en-us/magazine/cc301316.aspx I did not see an activex/COM object like secureCRT.application or something like that https://forums.vandyke.com/archive/index.php/t-7195.html
    1 point
  17. have a look in the the help file for _IEFormElementSetValue (examples at foot of that document) get the firebug addon for firefox go to www.wikihow.com/macrame right click on the search box at the top select Inspect Element with Firebug check out the html for the form you want in the firebug window In this case it's: <form id="cse-search-box" action="/Special:GoogSearch"> <div> <input type="hidden" value="008953293426798287586:mr-gwotjmbs" name="cx"> <input type="hidden" value="FORID:10" name="cof"> <input type="hidden" value="UTF-8" name="ie"> <input type="text" x-webkit-speech="" class="search_box" value="" size="30" name="q" id="cse_q"> <input type="submit" onclick="gatTrack(&quot;Search&quot;,&quot;Search&quot;,&quot;Custom_search&quot;);" onmouseout="button_unswap(this);" onmouseover="button_swap(this);" class="search_button" value="Search" id="cse_sa"> </div> </form> So then this is the code to write something into the search box: #include <IE.au3> $oIE = _IECreate("www.wikihow.com/Macrame") ;open page in IE and get a handle to it Local $oForms = _IEFormGetCollection($oIE,1) ;get handle to form: 1 means get 2nd form on page Local $oQuery = _IEFormElementGetCollection($oForms,3) ;get handle to element: 3 means 4th element of that form _IEFormElementSetValue($oQuery,"Organic Lambswool Mirkin Patterns") ;put what you want into the field Remember the numbering starts at zero so element 4 has index number 3.
    1 point
×
×
  • Create New...