Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 03/27/2019 in Posts

  1. I create purebasic language functions similar to autolt I let the members of the furom improve the concept with a beginning of idea I included some functions it works very well for the moment I let you modify and give your ideas thank add in your purebasic source code (IncludeFile "AutoitCoding.PB") and program as on autolt it remains full of function to program the concept is to improve the languages remain similar AutoIt Code : 415 kb with UPX Interpreted Language $Time=TimerInit() MsgBox (16,"Autoit",StringIsDigit ("123a")) MsgBox (16,"Autoit",StringIsDigit ("123")) $VarBin=StringToBinary("Hello") MsgBox (64,"Autoit",@Hour) MsgBox (64,"Autoit",@TempDir) MsgBox (64,"Autoit",$VarBin) MsgBox (64,"Autoit",BinaryToString($VarBin)) MsgBox (0,"Autoit",StringLen ("bonjour")) MsgBox (1,"Autoit",@DesktopCommonDir) MsgBox (2,"Autoit",@ProgramFilesDir) Sleep (1000) MsgBox (3,"Autoit",FileGetSize("test.pb")) MsgBox (4,"Autoit",Random (1,10,1)) $Variable=FileGetSize("test.pb") MsgBox (0,"Autoit",$Variable) ;InetGet ("https://jardinage.lemonde.fr/images/dossiers/2018-07/language-chat-170054.jpg","image.jpg") MsgBox (0,"Autoit",StringReplace ("Hella","a","o")) MsgBox (0,"Autoit",StringTrimLeft ("Hello",1)) MsgBox (0,"Autoit",StringTrimRight("Hello",1)) If FileExists ("test.pb") Then MsgBox(0,"Title","the file exist") Else MsgBox(0,"Title","the file does not exist") EndIf MsgBox(0,"Autoit",FileGetTime ("UPX.exe",1,1)) MsgBox(0,"Autoit",FileGetTime ("UPX.exe",1,1)) MsgBox(0,"Autoit",FileGetVersion("UPX.exe")) MsgBox(0,"Autoit",TimerDiff($Time)) If IsAdmin() Then MsgBox(0,"Autoit", "IsAdmin You are administrator !.") Else MsgBox(0,"Autoit", "IsAdmin You are not administrator !.") EndIf MsgBox(0,"Autoit",String (10)) MsgBox(0,"Autoit",Ping ("google.fr")) ;################## StringSplit $Split = StringSplit("ABC*DEFG*JKL","*") MsgBox(0,"Autoit",$Split[1]) MsgBox(0,"Autoit",$Split[2]) MsgBox(0,"Autoit",$Split[3]) ;################## StringSplit IniWrite("setup3.ini", "General", "Title", "AutoIt") $inivar= IniRead("setup3.ini", "General", "Title",Default) MsgBox (0,"Autoit",$inivar) PureBasic Code : Executable Size : 12 kb with UPX Real Compiler ( Your source code is secure ) IncludeFile "AutoitCoding.PB" ;MsgBox (16,"Autoit",StringIsDigit ("123a")) ;StringIs.PB be sure to activate it in AutoitCoding.PB this increases the size of the executable ;MsgBox (16,"Autoit",StringIsDigit ("123")) ;StringIs.PB be sure to activate it in AutoitCoding.PB this increases the size of the executable ;InetGet ("https://jardinage.lemonde.fr/images/dossiers/2018-07/language-chat-170054.jpg","image.jpg") ; InetFonctions be sure to activate it in AutoitCoding.PB this increases the size of the executable ;##################Mouse Dim xy (1) MouseGetPos (xy()) Debug "Pos : X : "+xy(0)+" Y : "+xy(1) Debug WinGetHandle ("Notepad") ;################## ProcessList Dim ProcessName.s(1) ; Create array Dim PID.s(1) ; Create array ProcessList (ProcessName (),PID ()) MsgBox(0,"Autoit","ProcessName: "+ProcessName(10)+" YourPID: "+PID (10)) ;################## ProcessList For i = 0 To ArraySize (ProcessName ()) Debug ProcessName (i)+" PID : "+ PID (i) Next MsgBox (0,"Autoit",ProcessorArch ()) Time$=TimerInit() VarBin$=StringToBinary("Hello") MsgBox (0,"Autoit",ComSpec ()) MsgBox (64,"Autoit",GetCPUName ()) MsgBox (64,"Autoit",CpuSerialNumber ()) MsgBox (64,"Autoit",AutoItVersion ()) MsgBox (64,"Autoit","Hello"+CRLF ()+"Hello") MsgBox (64,"Autoit",Hours ()) MsgBox (64,"Autoit",TempDir ()) MsgBox (64,"Autoit",VarBin$) MsgBox (64,"Autoit",BinaryToString(VarBin$)) MsgBox (48,"Autoit",StringLenS ("bonjour")) MsgBox (1,"Autoit",DesktopCommonDir ()) MsgBox (2,"Autoit",ProgramFilesDir ()) Sleep (1000) MsgBox (3,"Autoit",FileGetSize("test.pb")) MsgBox (4,"Autoit",Randoms (1,10)) Variable$=FileGetSize("test.pb") MsgBox (0,"Autoit",Variable$) MsgBox (0,"Autoit",StringReplace ("Hella","a","o")) MsgBox (0,"Autoit",StringTrimLeft ("Hello",1)) MsgBox (0,"Autoit",StringTrimRight("Hello",1)) If FileExists ("test.pb") MsgBox(0,"Autoit","the file exist") Else MsgBox(0,"Autoit","the file does not exist") EndIf MsgBox(0,"Autoit",FileGetTime ("UPX.exe",1,"%mm/%dd/%yyyy %hh:%ii:%ss")) MsgBox(0,"Autoit",FileGetTime ("UPX.exe",1,"%hh:%ii:%ss")) MsgBox(0,"Autoit",FileGetVersion("UPX.exe",#FV_FileVersion)) MsgBox(0,"Autoit",TimerDiff(Time$)) If IsAdmin() MsgBox(0,"Autoit", "IsAdmin You are administrator !.") Else MsgBox(0,"Autoit", "IsAdmin You are not administrator !.") EndIf MsgBox(0,"Autoit",String(10)) MsgBox(0,"Autoit",Ping ("google.fr")) iLife = 42 If IsNumber(iLife) MsgBox(0, "", "Is Number") Else MsgBox(0, "", "Is not Number") EndIf ;################## StringSplit Dim Split.s(1) ; Create array StringSplit (split(), "ABC*DEFG*JKL", "*") MsgBox(0,"Autoit",Split(0)) MsgBox(0,"Autoit",Split(1)) MsgBox(0,"Autoit",Split(2)) ;################## StringSplit IniWrite("setup3.ini", "General", "Title", "AutoIt") inivar$= IniRead("setup3.ini", "General", "Title") MsgBox (0,"Autoit",inivar$) ;Bonus Function MsgBox(0,"Autoit",HostNameToIp ("google.fr")) there is a slight difference but nothing important I am counting on you to improve the project and add functions ! ( Disadvantage purebasic is paying you can not have all ) Functions compatible : Msgbox Sleep FileGetSize ClipPut ClipGet Randoms DirCopy DirCreate DirRemove StringReplace StringLen Add Fonctions : (11/03/2019) StringTrimLeft StringTrimRight FileCopy FileMove StringUpper StringLower Add Fonctions : (12/03/2019) StringIsFloat StringIsAlpha StringIsDigit StringReverse BinaryToString StringToBinary FileExists Msgbox ADD : MB_ICONERROR = 16 MB_ICONQUESTION = 32 MB_ICONWARNING = 48 MB_ICONINFORMATION=64 You can control the size of the executable Division of executable size by 10 ( 119 kb to 12 kb) ( I separated the functions in several file activated if necessary ) ;IncludeFile "FonctionsIncludes\StringIs.PB" I separated the functions into several activated files If necessary remove ;IncludeFile "FonctionsIncludes\InetFonctions.PB" ; I separated the functions into several activated files If necessary remove Add Functions: (20/03/2019) String IsAdmin TimerDiff (thank @JiBe) TimerInit (thank @JiBe) Ping FileGetVersion add : #FV_FileVersion #FV_FileDescription #FV_LegalCopyright #FV_InternalName #FV_OriginalFilename #FV_ProductName #FV_ProductVersion #FV_CompanyName #FV_LegalTrademarks #FV_SpecialBuild #FV_PrivateBuild #FV_Comments #FV_Language FileGetTime Flag : 0 Last modified (default) 1 Created 2 Last accessed Msgbox ADD : MB_DEFBUTTON2 = 256 Flag MB_DEFBUTTON3 = 512 Flag MB_DEFBUTTON4 = 768 Flag MB_SYSTEMMODAL = 4096 Flag MB_TASKMODAL = 8192 Flag MB_DEFAULT_DESKTOP_ONLY = 131072 Flag MB_RIGHT = 524288 Flag MB_RTLREADING = 1048576 Flag MB_SETFOREGROUND = 65536 Flag MB_TOPMOST = 262144 Flag MB_SERVICE_NOTIFICATION = 2097152 Flag Bonus Functions : HostNameToIp Add Functions: (22/03/2019) ----------------------- ADD Macros : (thank @AZJIO) DesktopCommonDir () MyDocumentsDir () ProgramFilesDir () ScriptFullPath () ScriptName () ScriptDir () ----------------------- OSVersions () Add Functions: (26/03/2019) ----------------------- ADD Macros : TempDir () Hours () Min () Sec () MDAY () MON () Years () LF () CR () CRLF () ----------------------- Functions: Floor Ceiling Stringlen ( Update :Return Number) StringlenS (Temporary function asks for reflection) Add Functions: 06/04/2019 Macro : AutoItVersion () ; it's for fun haha SystemDir () UserProfileDir () AppDataDir () ComSpec () ; Bug fixed UserName () LogonServer () HomeShare () HomeDrive () HomePath () HomeDrive () LocalAppDataDir () UserProfilDir () Bonus Macro : ProcessorsThreadNumber () Functions : Change of procedure in macro (optimization) Optimization of msgbox Fix a constant messagebox Beep StringSplit ( thank @AZJIO ) FileGetAttrib Bonus features : CpuSerialNumber() GetCPUName() Add Functions: 16/04/2019 Optimization UserName () Optimization CpuName () change of the name of the function GetCpuName () ProcessList () : Return PID Return ProcessName ProcessClose (); PID or ProcessName IniWrite () IniRead () Macro : ProcessorArch () DesktopHeights () DesktopWidths () DesktopRefresh () DesktopDepths () AutoItX64 () Add Functions: 19/04/2019 Functions: ( THANK @AZJIO ) IniDelete () DriveGetType() DriveGetLabel() DriveGetSerial() DriveSpaceFree() DriveSpaceTotal() DriveGetFileSystem() Add Functions: 30/04/2019 Minor bug fixes : DriveGetLabel() fixed function thank AZJIO DriveGetFileSystem() fixed function thank AZJIO ADD Functions : BlockInput () thank AZJIO FileGetShortName() FileGetLongName() MouseGetPos () WinGetHandle () Sqrt () Add Functions: 23/05/2019 ProcessExists () ClosePID () IniReadSectionNames() WinWait ();2 in 1 finds the same handle with a title or a partial text WinExists ();2 in 1 finds the same handle with a title or a partial text WinWaitClose ();2 in 1 finds the same handle with a title or a partial text WinWaitActive ();2 in 1 finds the same handle with a title or a partial text WinGetProcess ();2 in 1 finds the same handle with a title or a partial text HandleToHex ();x86 management Imitate autoit HexToHandle () ADD Macro : ScriptDir () Complete rewrite of functions with optimization : ProcessList () ProcessClose () WinGetHandle () Delete function : CountProcess () FileGetSize () ;Old function All the old function are put in the OldFonctions.pb file Add Fonctions : (18/07/2019) WinMinimizeAll() Winkill ();title or a partial text SearchHandle ();Bonus function to simplify your life look for the handle of a window with a title or a text patiel WinSetStade ();title or a partial text or Handle #SW_HIDE = 0 #SW_SHOW = 5 #SW_MINIMIZE = 6 #SW_MAXIMIZE = 3 #SW_RESTORE = 9 #SW_DISABLE = 4 #SW_ENABLE = 1 WinActive () Title or Handle WinList (); With the zero flag you can see the invisible windows and the flag 1 for visible windows more simplify than the original Default option : VisibleWindow = 1 WinSetTitle () Title or Handle Update : WinExists () Handle Management WinGetProcess () Handle Management Add Fonctions : (09/04/2020) IsHWnd (Return 0 or 1) PixelGetColor (x,y) WinSetTrans ;title or a partial text 0 To 255 Optimization of the msgbox function smaller and faster code (old msgbox function put in oldfunction.pb) Msgbox Fix minors bug MouseMoveSpeed Function under construction MouseClick Function under construction HibernateAllowed() Suspend() ShutdownPrivilege() Shutdown (Flag) #SD_LOGOFF=0 #SD_SHUTDOWN=1 #SD_REBOOT=2 #SD_FORCE=4 #SD_POWERDOWN=8 #SD_FORCEHUNG=16 #SD_STANDBY=32 #SD_HIBERNATE=64 ProcessSetPriority (Process.s, priority) #PROCESS_LOW =0 #PROCESS_BELOWNORMAL =1 #PROCESS_NORMAL =2 #PROCESS_ABOVENORMAL =3 #PROCESS_HIGH =4 #PROCESS_REALTIME =5 EnvSet () EnvGet () FileRecycleEmpty() add file in GuiExampleAutoitCoding (Hybrid Code) example method for window GuiExampleAutoitCoding (Hybrid Code) update files start of code to convert autoit to pb in construction Add Fonctions : (01/12/2022) #PB_OS_Windows_11 code upgrade OSVersion() WinActivate(hWnd) adding a new function thank @AZJIO #MB_SERVICE_NOTIFICATION1 I changed the name not compatible with purebasic 6 I added a 1 (msgbox) DriveGetLabel bugfix for version 6 of purebasic DriveGetFileSystem bugfix for version 6 of purebasic ProcessorArch () optimization of the function and addition of flag for Purebasic 6 ARM64 ARM ProcessorArch () the old function is moved to the file Old Functions.pb ProcessorArch () bug fixed stack has been corrupted ProcessorArch () add to file Example.pb InitNetwork remove Deprecated function HostNameToIp optimization of the function and addition of flag 0 HostNameToIp the old function is moved to the file Old Functions.pb Ping () optimization of the function and addition of flag and timeout Ping () fix minor bug flag 0 return ping flag 1 return PingStatus also returns errors 1 = Host disconnected 2 = Host unreachable 3 = Wrong destination 4 = Other errors flag 2 return DataSize timeout = 4000 like the original the setting support written web address and ip address (www.google.com or 127.0.0.1) Ping () the old function is moved to the file Old Functions.pb remove ExampleGui I moved the files in the same folder it is more manageable Add Fonctions : (05/09/2024) New Functions Added: DllOpen Implemented a new function DllCall Implemented a new function DllClose Implemented a new function iniWrite: Implemented a new function for writing to INI files. iniRead: Introduced a revised version of the basic function for reading INI files. CpuIdentifier() Combine some values to create a pseudo-unique identifier Function Rewrite: iniDelete: Updated the iniDelete function to enhance management of sections and keys. Ping improve performance Compatibility improved PureBasic 6.11 LTS Legacy Code Management: Moved obsolete functions to Oldfunctions.pb to streamline current codebase. Moved Macro Username to Oldfunctions.pb Moved Macro Blockinput to Oldfunctions.pb Bug fix : (05/09/2024) Bug fix : corrected IniRead procedure to return string instead of numeric value Update : (05/12/2024) FileGetVersion: bug fix pointer IniReadSection:Implemented a new function ExempleGui bug fix FileRecycleEmptyDrive : rewriting the function with return of flag 1 or 0 like autoit ;Code size optimization Reorganization and bug fix Example.pb ;added comment ;added example FileRecycleEmptyDrive Update Fonctions : (10/12/2024) WinGetClassList () ;thanks to @AZJIO I optimized and rewrote the function ;this remains an experience not yet stable and requires a lot of research because I remain an amateur developer ;added example WinGetClassList () ;IniReadSection translation of comments ;thanks to @AZJIO ;StringIsDigit new function with identical return values (fully written); ;StringIsXDigit new function with identical return values (fully written); ;added example StringIsDigit ;added example StringIsXDigit ;added MyGUICreate.pb ;Imitation of experimental windows of autoit functions with Windows API UPX official website to compress the executable : https://upx.github.io/ PureAutoitInclude.7z
    1 point
  2. This UDF brings the power and flexibility of jq to AutoIt scripts. jq is an open-source, powerful, and flexible command-line based JSON processor. As it says on their website, jq is like 'sed' for JSON. jq can be used for the simplest of tasks like retrieving JSON objects and values (parsing), to very advanced JSON processing using its numerous built-in functions and conditional processing. Its built-in functions can handle math, selection, conditional processing, mapping, object and array manipulation, flattening, reduction, grouping, and much more. You can even create your own jq functions. You can learn more about jq and even play with it in real-time, using jq's online jq playground, all on their website. Here and some helpful links to get you more familiar with jq, what can be done with it, its built-in functions, and its syntax. jq Website: https://jqlang.github.io/jq/ jq Manual: https://jqlang.github.io/jq/manual/ jqWiki (FAQ, Cookbook, Advanced Topics) https://github.com/jqlang/jq/wiki jq is a single 32 or 64 bit executable that has no other dependencies. Just like using the SQLite UDF, the only requirement to use this UDF is that the jq executable reside in a location in which the UDF can execute it. The latest win32 & win64 versions have been included in the UDF download. You can always get newer versions from the jq website. jq at a high level Like 'sed', jq reads JSON in, either through STDIN or one or more files, processes it thru one or more "filters", and outputs the results. You can, optionally, supply "options" that affect how it reads the input, where it gets its "filters", and how it writes its output. It looks a little like this: JSON ---> jq processor (using supplied filters and options) ---> Output So in jq lingo, you basically use "Filters" to tell jq what you want it to do. So in the UDF file, that is why the main functions ( _jqExec() and _jqExecFile() ) refer to filters and options. Please make note that jq works with relatively strict JSON. This means that all JSON read must be conform to the standard. Luckily, jq is pretty good at identifying where a format error exists in non standard JSON. The jq UDF There are 2 main funtions in the UDF file, _jqExec and jqExecFile. With these 2 functions, you can pretty much do anything that jq can do. The only difference between to two functions is whether the JSON is supplied by a string or a file. The 2 primary functions simply call the jq executable with the supplied information, after properly formatting the parameters. There are additional functions in the UDF to easily pretty-print your json, compact-print your json, dump the json data with its associated paths, and see if specific JSON keys exist, but they all just execute the _jqExec or _jqExecFile function with the proper filter. There are also a couple of extra functions to display what version of the UDF and jq executable you are currently using. There are also a couple of functions to enable and disable logging of jq information for debugging purposes. Most of the jq UDF file functions return an @error if unsuccessful. Some also include @extended info. Please see the actual function headers for more information on their usage and return values. The 2 primary functions below just format your jq request and pass it on the jq executable. The functions will also properly escape double quotes (") that are used in the filter. For most simple tasks, you just need to supply the JSON source and a filter. _jqExec($sJson, $sFilter, $sOptions = Default, $sWorkingDir = Default) Or _jqExecFile($sJsonFile, $sFilter, $sOptions = Default, $sWorkingDir = Default) Using jq in your script As stated earlier, the jq executable must reside somewhere where the script can locate and execute it. The _jqInit() function always has to be executed before any jq processing occurs. _jqInit() merely locates the executable or uses the supplied path. It also clears any previous debug log. The jq UDF folder contains a jq example script that has several examples to how to do some of the most common JSON processing tasks. Here are a few examples to get you started: How to pretty-print some JSON #include "jq.au3" ;_jqInit is only needed if the jq executale is not in the PATH or @ScriptDir _jqInit() If @error Then Exit ConsoleWrite("ERROR: Unable to initialize jq - @error = " & @error & @CRLF) $sJson = '{"fruits":[{"Apple":{"color":"Red","season":"Fall"}}, {"Banana":{"color":"Yellow","season":"Summer"}}]}' $sCmdOutput = _jqPrettyPrintJson($sJson) ConsoleWrite(@CRLF & "Pretty-Print JSON" & @CRLF & $sCmdOutput & @CRLF) How to compact-print some JSON #include "jq.au3" ;Initialize jq environment _jqInit() If @error Then Exit ConsoleWrite("ERROR: Unable to initialize jq - @error = " & @error & @CRLF) $sJson = '{ "fruits" : [{"Apple" : {"color":"Red","season":"Fall"}}, {"Banana":{"color":"Yellow","season":"Summer"}}]}' $sCmdOutput = _jqCompactPrintJson($sJson) ConsoleWrite(@CRLF & "Compact-Print JSON" & @CRLF & $sCmdOutput & @CRLF) Dump JSON data (paths and values) #include "jq.au3" ;Initialize jq environment _jqInit() If @error Then Exit ConsoleWrite("ERROR: Unable to initialize jq - @error = " & @error & @CRLF) $sJson = '{ "fruits" : [{"Apple" : {"color":"Red","season":"Fall"}}, {"Banana":{"color":"Yellow","season":"Summer"}}]}' $sCmdOutput = _jqDump($sJson) ConsoleWrite(@CRLF & "Dump JSON paths and values" & @CRLF & $sCmdOutput & @CRLF) How to GET JSON values #include "jq.au3" ;Initialize jq environment _jqInit() If @error Then Exit ConsoleWrite("ERROR: Unable to initialize jq - @error = " & @error & @CRLF) $sJson = '{"Apple" : {"color":"Red","season":"Fall"}, "Banana":{"color":"Yellow","season":"Summer"}}' $sFilter = '.Banana.color' $sCmdOutput = _jqExec($sJson, $sFilter) ConsoleWrite("Get color of banana" & @CRLF) ConsoleWrite("Input: : " & _jqCompactPrintJson($sJson) & @CRLF) ConsoleWrite("Filter : " & $sFilter & @CRLF) ConsoleWrite("Output : " & $sCmdOutput & @CRLF) or #include "jq.au3" ;Initialize jq environment _jqInit() If @error Then Exit ConsoleWrite("ERROR: Unable to initialize jq - @error = " & @error & @CRLF) $sJson = '{"Apple" : {"color":"Red","season":"Fall"}, "Banana":{"color":"Yellow","season":"Summer"}}' $sFilter = 'getpath(["Banana", "color"])' $sCmdOutput = _jqExec($sJson, $sFilter) ConsoleWrite("Get color of banana" & @CRLF) ConsoleWrite("Input: : " & _jqCompactPrintJson($sJson) & @CRLF) ConsoleWrite("Filter : " & $sFilter & @CRLF) ConsoleWrite("Output : " & $sCmdOutput & @CRLF) Check for the existence of a key #include "jq.au3" ;Initialize jq environment _jqInit() If @error Then Exit ConsoleWrite("ERROR: Unable to initialize jq - @error = " & @error & @CRLF) $sJson = '{"Apple":{"color":"Red","season":"Fall"}, "Banana":{"color":"Yellow","season":"Summer"}}' $sFilter = '.Banana | has("color")' $sCmdOutput = _jqExec($sJson, $sFilter) ConsoleWrite("Check for existence of color key within Banana object" & @CRLF) ConsoleWrite("Input: : " & _jqCompactPrintJson($sJson) & @CRLF) ConsoleWrite("Filter : " & $sFilter & @CRLF) ConsoleWrite("Output : " & $sCmdOutput & @CRLF) Count of how many Items in an object #include "jq.au3" ;Initialize jq environment _jqInit() If @error Then Exit ConsoleWrite("ERROR: Unable to initialize jq - @error = " & @error & @CRLF) $sJson = '{"Apple":{"color":"Red"}, "Banana":{"color":"Yellow","season":"Summer"}}' $sFilter = '.Banana | length' $sCmdOutput = _jqExec($sJson, $sFilter) ConsoleWrite("How many items in the Banana object" & @CRLF) ConsoleWrite("Input: : " & _jqCompactPrintJson($sJson) & @CRLF) ConsoleWrite("Filter : " & $sFilter & @CRLF) ConsoleWrite("Output : " & $sCmdOutput & @CRLF) How to PUT/Create/Modify JSON #include "jq.au3" ;Initialize jq environment _jqInit() If @error Then Exit ConsoleWrite("ERROR: Unable to initialize jq - @error = " & @error & @CRLF) $sInput = "" $sFilter = 'setpath(["Apple","color"];"Red") | setpath(["Banana","color"];"Yellow") | setpath(["Banana","season"];"Summer")' $sOptions = '-n' ;required if no input supplied $sCmdOutput = _jqExec($sInput, $sFilter, $sOptions) ConsoleWrite("Update/Create JSON" & @CRLF) ConsoleWrite("Filter : " & $sFilter & @CRLF) ConsoleWrite("Output : " & @CRLF & $sCmdOutput & @CRLF) List all of the fruits (top-level keys) #include "jq.au3" ;Initialize jq environment _jqInit() If @error Then Exit ConsoleWrite("ERROR: Unable to initialize jq - @error = " & @error & @CRLF) $sJson = '{"Apple":{"color":"Red"}, "Banana":{"color":"Yellow","season":"Summer"}}' $sFilter = 'keys | .[]' $sCmdOutput = _jqExec($sJson, $sFilter) ConsoleWrite("List all top-level keys (fruits)" & @CRLF) ConsoleWrite("Input : " & $sJson & @CRLF) ConsoleWrite("Filter : " & $sFilter & @CRLF) ConsoleWrite("Output : " & @CRLF & $sCmdOutput & @CRLF) Calculate the sum of all of the objects' price * qty #include "jq.au3" ;Initialize jq environment _jqInit() If @error Then Exit ConsoleWrite("ERROR: Unable to initialize jq - @error = " & @error & @CRLF) $sJson = '[{"id":1,"price":20.00,"qty":10},{"id":2,"price":15.00,"qty":20.25},{"id":3,"price":10.50,"qty":30}]' $sFilter = 'map(.price * .qty) | add' $sCmdOutput = _jqExec($sJson, $sFilter) ConsoleWrite("Calculate the sum of all of the objects' price * qty" & @CRLF) ConsoleWrite("Input : " & $sJson & @CRLF) ConsoleWrite("Filter : " & $sFilter & @CRLF) ConsoleWrite("Output : " & $sCmdOutput & @CRLF) The examples above, and the ones in the example files, merely scratch the surface of what jq can do. It may look intimidating at first but it really isn't that bad once you start playing with it. You can find several more examples and play around with them or create your own using jqPlayground. jqPlayground is a separate, stand alone, interactive tool for creating, testing and learning JSON processing using jq. If you have any questions regarding the UDF, or how to perform a certain task using jq, I'll try my best to answer them. Since jq has been around for a while now, there's also several jq-related questions and answers on StackOverflow. >>> Download the UDF in the Files Section <<<
    1 point
  3. Taking the idea from @Melba23's (btw, thanks ) ExtMsgBox and also making use of his StringSize UDF, I made a extended version of the InputBox function. From the README file: This UDF creates input boxes (just like native InputBox), but with multiple inputs. You can also set some inputs to be password-style, set the default texts for some of the edits and even set the label of the OK/cancel buttons. How to use _ExtInputBox($sTitle, $sTexts [ , $sDefaults = Null [ , $sPasswords = Null [ , $sBtnLabels = "OK|Cancel" [ , $iWidth = -1 [ , $iLeft = -1 [ , $iTop = -1 [ , $iTimeout = 0 [ , $hParent = 0 ] ] ] ] ] ] ] ] ) Arguments are: $sTitle (mandatory): The window title (e.g.: "Hello World") $sTexts (mandatory): The edit labels, separated by | (e.g.: "Your email|Your password") $sDefaults: The default input texts, separated by | (e.g.: "|you@us.com||" will tell that the first input will have nothing as default text, the second will have you@us.com as default text and the third and forth will also have nothing). Note that if you set the default value of 1 input, you must set the value of them all (even if it's nothing), otherwise all inputs will have no default value. Default is none. $sPasswords: One or more 1-based index of inputs, separated by anything that is not a number (pipeline - | - recommended), of the inputs that will receive password style (e.g.: "2|3" wíll tell that the second and third inputs are password-style, default is none) $sBtnLabels: The TWO label of the default OK/Cancel buttons (e.g.: "Submit|Close") $iWidth: Window width (default is the size of the longest string with the limit of 25% of the screen width). Obviously it's not possible to set the height as it's calculated automatically. $iLeft: Distance of the window from the left side of the screen (default is centered) $iTop: Distance of the window to the top of the screen (default is centered) $iTimeout: Time limit for filling the form data (default is none) $hParent: Parent form (default is none) Return value Sucess: an 1-based array with the input values entered ($aArray[1] = 1st input value, $aArray[2] = 2nd input value, $aArray[n] = nth input value, whereas $aArray[0] = input count) Failure: False, and set @extended to 1 if the user clicked cancel, 2 if the user closed the window, or 3 if timeout ended. Examples (two of them) #include 'ExtInputBox.au3' $sData = _ExtInputBox("Login", "Username|Password", Null, "2") If $sData = False Then MsgBox(0, "", "You pressed cancel, exit or timeout ended.") Else MsgBox(0, "You entered:", "Username: " & $sData[1] & @CRLF & "Password: " & $sData[2]) EndIf #include 'ExtInputBox.au3' $sData = _ExtInputBox("Login", "Your full name|Your email|Your telephone|Choose an username|Choose a password|Repeat password", "Mr./Ms. ||+1 |admin||", "5,6", "Register|Cancel") If $sData = False Then Switch @extended Case 1 MsgBox(0, "", "You clicked Cancel") Case 2 MsgBox(0, "", "You closed the window.") Case 3 MsgBox(0, "", "Timeout ended (but we have no timeout on this example, so this will never happen)") EndSwitch Else MsgBox(0, "You entered:", "Full name: " & $sData[1] & @CRLF & _ "Email: " & $sData[2] & @CRLF & _ "Telephone:" & $sData[3] & @CRLF & _ "Username: " & $sData[4] & @CRLF & _ "Password: " & $sData[5] & @CRLF & _ "Password repeat: " & $sData[6]) EndIf Download Download ZIP from GitHub Btw, fork me on Github
    1 point
  4. BrewManNH

    how detect file type ?

    If it were an xlsx file, the first 4 characters would be 0xPK, which by the way is the same signature as a zip archive. The reason for this is actually pretty straightforward. The xlsx file format IS a zip file, if you change the extension of it from xlsx to zip, you can open it as if it were an archive. All of the relevant file information for the spreadsheet is inside the archive as individual files. BTW, this would also confuse any type of file type detector because as far as the signature is concerned, it's still just a ZIP file.
    1 point
  5. Deye

    Stop sound if win active

    This should stop scripts playing sounds upon activating a folder that titles [title & .exe] = @ScriptName While 1 Sleep(1000) $sTitle = WinGetTitle(WinGetHandle("", ""), "") If @ScriptName = $sTitle & ".exe" Then SoundPlay("") Exit EndIf WEnd Deye
    1 point
  6. Jfish

    Stop sound if win active

    Try something like this (untested) - then just call that function with the parent process as the parameter. Check the UDF for _SoundStatus to get the status of a sound and also _soundPlay and _soundStop. func _playSound($aParentProcessName) SoundPlay("C:\audios\"&StringTrimRight($aParentProcessName,4)&"\expired.wav") EndFunc
    1 point
  7. What are you doing in comparing the 2? From what I can see, you read the first line of the file, then compare it to the 2,000,000 other lines in the file. After that you read the second line of the file, and proceed to loop through 2,000,000 lines of the file again to compare that one. Then you write those 4 trillion lines of seemingly useless data to the another file.
    1 point
  8. I'm an idiot That works! Thank you kind stranger! Local $oIE = _IEAttach("https://puesc.gov.pl","url") Local $hWnd = _IEPropertyGet($oIE, "hwnd") Local $oButs = _IETagNameGetCollection($oIE, "button") For $oBut In $oButs If StringInStr($oBut.innertext, "Dodaj dokument ręcznie") Then _IEAction($oBut, "click") Next
    1 point
  9. A common workaround to get the checked state of a listview item is to test the index of the state image. A checked and unchecked checkbox are two different state images. Usually with indices 2 and 3. But I don't remember it exactly, so please test it. _GUICtrlListView_GetItemStateImage( $hHandle, 3 ) Then you can switch the checked state with these commands: WinActivate WinWaitActive _GUICtrlListView_SetItemSelected( $hHandle, 3, True, True ) ; Selected = True, Focused = True Send( "{SPACE}" ) The code is untested.
    1 point
  10. I'd mass-change ConsoleWrite to $ConsoleWrite and put that ahead: Global $ConsoleWrite = @Compiled ? _ConsoleWriteNull : ConsoleWrite Func _ConsoleWriteNull(ByRef $s) Return EndFunc A few pointless invokations of such an empty function shouldn't be noticeable.
    1 point
  11. GajjarTejas

    TrIDLib.dll+UDF+GUI

    What is TrIDLib.dll? This standard Win32 DLL library, based on TrID's core engine, make adding file identification / file recognition capabilities to any kind of application a very easy & quick process. If you need a managed library, check the TrIDEngine. For more Info Go to Author website http://mark0.net/index-e.html Functions in the UDF are: _TrIDLib_Startup _TrIDLib_Shutdown _TrIDLib_GetInfo _TrIDLib_GetRealExtension _TrIDLib_GetVersion _TrIDLib_GetFileTypeDef Here is main udf: #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include-once ; TrIDlib AutoIt Demo[Modified] ; #INDEX# ======================================================================================================================= ; Title .........: 7Zip ; AutoIt Version : 3.3.8.1 ; Language ......: English ; Description ...: Functions that assist with TrIDLib DLL. ; Author(s) .....: Gajjar Tejas ; Notes .........: The original code came from this subject : http://mark0.net/download/tridlib-samples.zip ; - 12 June 2013 : ; * Intial ; * Added _TrIDLib_GetInfo, _TrIDLib_GetVersion, _TrIDLib_GetFileTypeDef,_TrIDLib_Startup, _TrIDLib_Shutdown,_TrIDLib_GetRealExtension ; * 32bit dll Version(v1.0.2.0). ; * Auto Open Dll, Manually Close ; - Note ; * Using _TrIDLib_Startup() and _TrIDLib_Shutdown() is recommanded for multiples Files. ; * The last x32 DLL file can be found here : http://mark0.net/code-tridlib-e.html ; * The last Definition file can be found here : http://mark0.net/soft-trid-e.html ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ;_TrIDLib_Startup ;_TrIDLib_Shutdown ;_TrIDLib_GetInfo Auto Open dll*** ;_TrIDLib_GetVersion Auto Open dll ;_TrIDLib_GetFileTypeDef Auto Open dll ;***Using _TrIDLib_Startup() and _TrIDLib_Startup() is recommanded for multiples Files to avoid ; repetitive dll open that can increase operation time. ;***If _TrIDLib_Startup is not specified then dll will open and close automatically for _TrIDLib_GetInfo() ; =============================================================================================================================== ; #VARIABLES# =================================================================================================================== ; Definations & dll File Global $sTridDllFile = @ScriptDir & "\TrIDLib.dll" Global $sTridDefDir = @ScriptDir Global $sTridDefFile = $sTridDefDir & "\triddefs.trd" ; Others Global $iTridIsDllOpen = 0 ;Default Dll is not opened. Global $hTridDll = 0 ;Handle to Dll Global $iTridAutoLoad = 1 ;Default auto load Dll ; Constants FOR TrID_GetInfo Const $TRID_GET_RES_NUM = 1 ;Get the number of results available Const $TRID_GET_RES_FILETYPE = 2 ;Filetype descriptions Const $TRID_GET_RES_FILEEXT = 3 ;Filetype extension Const $TRID_GET_RES_POINTS = 4 ;Matching points Const $TRID_GET_VER = 1001 ;TrIDLib version (major * 100 + minor) Const $TRID_GET_DEFSNUM = 1004 ;Number of filetypes definitions loaded ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TrIDLib ; Description ...: Identify file types from their binary signatures. ; Syntax ........: _TrIDLib($sFile) ; Parameters ....: $sFile - A full path of file. ; Return values .: Success - Returns the array (n x 4) with results ; n = Total No of possible file type found(UBound(array, 1)) ; array[0][0] = File Type 1st instant ; array[0][1] = Extension " ; array[0][2] = Points " ; array[0][3] = % Point " ; ... ; array[n-1][0] = File Type (n-1)th instant ; array[n-1][1] = Extension " ; array[n-1][2] = Points " ; array[n-1][3] = % Point " ; Failure - Returns 0 and and sets @error to non zero ; |1 = TrIDLib.dll File Not Found.(FileExist) ; |2 = Triddefs.trd File Not Found(FileExist) ; |3 = While Opening TrIDLib.dll(DllOpen) ; |4 = While Loading triddefs.trd(DllCall) ; |5 = While Submitting File(DllCall) ; |6 = While Analysing File(DllCall) ; |7 = Unable to detect file type(DllCall) ; Author ........: Gajjar Tejas ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _TrIDLib_GetInfo($sFile) If $iTridAutoLoad Then _TrIDLib_Startup() If @error Then Return SetError(@error, 0, 0) $iTridAutoLoad = 1 Else ;Check if Manually Load Using _TrIDLib_Startup and previously dll open or not If Not $iTridIsDllOpen Then _TrIDLib_Startup() If @error Then Return SetError(@error, 0, 0) EndIf EndIf ; load the definitions Local $Ret = DllCall($hTridDll, "int", "TrID_LoadDefsPack", "str", $sTridDefDir) If @error Then Return SetError(4, 0, 0) ; submit the file $Ret = DllCall($hTridDll, "int", "TrID_SubmitFileA", "str", $sFile) If @error Then Return SetError(5, 0, 0) ; perform the analysis $Ret = DllCall($hTridDll, "int", "TrID_Analyze") If @error Then Return SetError(6, 0, 0) Local $Buf $Ret = DllCall($hTridDll, "int", "TrID_GetInfo", "int", $TRID_GET_RES_NUM, "int", 0, "str", $Buf) Local $iTotalSumPoints = 0 Local $RetCom If $Ret[0] > 0 Then Local $aTridLibInfoInform2D[$Ret[0]][4] For $ResId = 0 To $Ret[0] - 1 ;Get File Type $RetCom = DllCall($hTridDll, "int", "TrID_GetInfo", "int", $TRID_GET_RES_FILETYPE, "int", $ResId + 1, "str", $Buf) $aTridLibInfoInform2D[$ResId][0] = $RetCom[3] ;First Element ;Get Extension $RetCom = DllCall($hTridDll, "int", "TrID_GetInfo", "int", $TRID_GET_RES_FILEEXT, "int", $ResId + 1, "str", $Buf) $aTridLibInfoInform2D[$ResId][1] = $RetCom[3] ;Second Element ;Get Points $RetCom = DllCall($hTridDll, "int", "TrID_GetInfo", "int", $TRID_GET_RES_POINTS, "int", $ResId + 1, "str", $Buf) $aTridLibInfoInform2D[$ResId][2] = $RetCom[0] $iTotalSumPoints += Number($aTridLibInfoInform2D[$ResId][2]) ;Third Element Next ;Get Points in Percentage If $iTotalSumPoints > 0 Then For $ResId = 0 To $Ret[0] - 1 $aTridLibInfoInform2D[$ResId][3] = Round($aTridLibInfoInform2D[$ResId][2] * 100 / $iTotalSumPoints, 2) ;Fourth Element Next EndIf Else Return SetError(7, 0, 0) EndIf If $iTridAutoLoad Then _TrIDLib_Shutdown() Return $aTridLibInfoInform2D EndFunc ;==>_TrIDLib_GetInfo ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TrIDLib_GetRealExtension ; Description ...: ; Syntax ........: _TrIDLib_GetRealExtension($sFile) ; Parameters ....: $sFile - A full path of file. ; Return values .: Success - Returns the Original File Extension ; Failure - Returns Empty String('') and and sets @error to non zero ; |1 = TrIDLib.dll File Not Found.(FileExist) ; |2 = Triddefs.trd File Not Found(FileExist) ; |3 = While Opening TrIDLib.dll(DllOpen) ; |4 = While Loading triddefs.trd(DllCall) ; |5 = While Submitting File(DllCall) ; |6 = While Analysing File(DllCall) ; |7 = Unable to detect file type(DllCall) ; |8 = File was Identified But Extension Not Found in the Database(null('') extension return by dll) ; Author ........: Gajjar Tejas ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _TrIDLib_GetRealExtension($sFile) Local $at = _TrIDLib_GetInfo($sFile) Local $iErr = @error Local $sExt = $at[0][1] If Not $iErr Then If $sExt <> "" Then $sExt = "." & $sExt Else Return SetError(8, 0, '');null extension return by dll EndIf Else Return SetError($iErr, 0, '') EndIf Return $sExt EndFunc ;==>_TrIDLib_GetRealExtension ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TrIDLib_GetVersion ; Description ...: Get the TrIDLib.dll version ; Syntax ........: _TrIDLib_GetVersion() ; Parameters ....: ; Return values .: Success - Returns Numrical - Version ; Failure - Returns 0 and and sets @error to non zero ; |1 = TrIDLib.dll File Not Found.(FileExist) ; |2 = Triddefs.trd File Not Found(FileExist) ; |3 = While Opening TrIDLib.dll(DllOpen) ; |4 = While Loading triddefs.trd(DllCall) ; Author ........: Gajjar Tejas ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _TrIDLib_GetVersion() ;Check if is dll open or not If Not $iTridIsDllOpen Then _TrIDLib_Startup() If @error Then Return SetError(@error, 0, 0) EndIf ;Get TrIDLib version Local $Buf Local $RetCom = DllCall($hTridDll, "int", "TrID_GetInfo", "int", $TRID_GET_VER, "int", 0, "str", $Buf) Return Round($RetCom[0] / 100, 2) EndFunc ;==>_TrIDLib_GetVersion ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TrIDLib_GetFileTypeDef ; Description ...: Get the total no of Definitions triddefs.trd ; Syntax ........: _TrIDLib_GetFileTypeDef() ; Parameters ....: ; Return values .: Success - Returns Numrical - Version ; Failure - Returns 0 and and sets @error to non zero ; |1 = TrIDLib.dll File Not Found.(FileExist) ; |2 = Triddefs.trd File Not Found(FileExist) ; |3 = While Opening TrIDLib.dll(DllOpen) ; |4 = While Loading triddefs.trd(DllCall) ; Author ........: Your Name ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _TrIDLib_GetFileTypeDef() ;Check if is dll open or not If Not $iTridIsDllOpen Then _TrIDLib_Startup() If @error Then Return SetError(@error, 0, 0) EndIf ; load the definitions DllCall($hTridDll, "int", "TrID_LoadDefsPack", "str", $sTridDefDir) If @error Then Return SetError(4, 0, 0) ;Get Number of filetypes definitions loaded Local $Buf Local $RetCom = DllCall($hTridDll, "int", "TrID_GetInfo", "int", $TRID_GET_DEFSNUM, "int", 0, "str", $Buf) Return $RetCom[0] EndFunc ;==>_TrIDLib_GetFileTypeDef ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TrIDLib_CheckFiles ; Description ...: Check File ; Syntax ........: _TrIDLib_CheckFiles() ; Parameters ....: ; Return values .: Success - Returns 1 ; Failure - Returns 0 and and sets @error to non zero ; |1 = TrIDLib.dll File Not Found.(FileExist) ; |2 = Triddefs.trd File Not Found(FileExist) ; Author ........: Gajjar Tejas ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _TrIDLib_CheckFiles() If Not FileExists($sTridDllFile) Then Return SetError(1, 0, 0) ElseIf Not FileExists($sTridDefFile) Then Return SetError(2, 0, 0) Else Return SetError(0, 0, 1) EndIf EndFunc ;==>_TrIDLib_CheckFiles ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TrIDLib_Startup ; Description ...: Manually Load TrIDLib.dll ; Syntax ........: _TrIDLib_Startup() ; Parameters ....: ; Return values .: Success - Returns 1 ; Failure - Returns 0 and and sets @error to non zero ; |1 = TrIDLib.dll File Not Found.(FileExist) ; |2 = Triddefs.trd File Not Found(FileExist) ; |3 = While Opening TrIDLib.dll(DllOpen) ; Author ........: Gajjar Tejas ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _TrIDLib_Startup() _TrIDLib_CheckFiles() If @error Then Return SetError(@error, 0, 0) $hTridDll = DllOpen($sTridDllFile) If $hTridDll = -1 Then Return SetError(3, 0, 0) $iTridIsDllOpen = 1 $iTridAutoLoad = 0 Return SetError(0, 0, 1) EndFunc ;==>_TrIDLib_Startup ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TrIDLib_Shutdown ; Description ...:Manually Unload TrIDLib.dll ; Syntax ........: _TrIDLib_Shutdown() ; Parameters ....: ; Return values .: None ; Author ........: Gajjar Tejas ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _TrIDLib_Shutdown() DllClose($hTridDll) $iTridAutoLoad = 1;Default auto load $iTridIsDllOpen = 0 EndFunc ;==>_TrIDLib_Shutdown Example:1 #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #Region ;************ Includes ************ #Include "_TrIDLib.au3" #include <Array.au3> #EndRegion ;************ Includes ************ _Example() Func _Example() MsgBox(0, "Info", _ "TrIDLib.dll version (major * 100 + minor): " & _TrIDLib_GetVersion() & @CRLF & _ "Number of filetypes definitions loaded:" & _TrIDLib_GetFileTypeDef()) Local $sFile, $at, $iErr $sFile = FileOpenDialog("Choose Any File", "", "Any File (*.*)", 3) ; a file to analyze If @error Then Exit $at = _TrIDLib_GetInfo($sFile) $iErr = @error If Not $iErr Then MsgBox(0, "Info", "Total No of possible file type found:" & UBound($at, 1)) MsgBox(0, "Info", "Suggested Extension:" & _TrIDLib_GetRealExtension($sFile)) _ArrayDisplay($at, "Result", -1, 0, "", "|", "No.|File Type|Extension|Points|% Points") Else Switch $iErr Case 1 MsgBox(0, "Error", "TrIDLib.dll File Not Found in Script Directory.") Case 2 MsgBox(0, "Error", "triddefs.trd File Not Found in Script Directory.") Case 3 MsgBox(0, "Error", "Error occurs during opening TrIDLib.dll") Case 4 MsgBox(0, "Error", "Error occurs during Loading triddefs.trd.") Case 5 MsgBox(0, "Error", "Error occurs during Submitting File: " & $sFile) Case 6 MsgBox(0, "Error", "Error occurs during Analysing File: " & $sFile) Case 7 MsgBox(0, "Error", "Unable to detect file type") Case 8 MsgBox(0, "Error", "File was Identified But Extension Not Found in the Database(null extension return by dll)") EndSwitch EndIf EndFunc ;==>_Example Example:2 #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #Region ;************ Includes ************ #Include "_TrIDLib.au3" #EndRegion ;************ Includes ************ _Example() Func _Example() ;Load Dll _TrIDLib_Startup() ;Select Folder Local $sDir = FileSelectFolder("choose folder", "") If @error Then Exit If StringRight($sDir, 1) <> "\" Then $sDir &= "\" ;Search Handle Local $search = FileFindFirstFile($sDir & "*.*") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf MsgBox(0, "Info", "Now,Press Ok to See Console Output") Local $at, $iErr = 0 While 1 ;Search for file and Folder Local $sFile = FileFindNextFile($search) If @error Then ExitLoop ;Only file allowed If StringInStr(FileGetAttrib($sDir & $sFile), "D") = 0 Then ConsoleWrite("==============================================================" & @LF) ConsoleWrite(">File: " & $sDir & $sFile & @LF) ;Get detailed info in array $at = _TrIDLib_GetInfo($sDir & $sFile) $iErr = @error If Not $iErr Then ConsoleWrite("Total no of possible file type found:" & UBound($at, 1) & @LF) ConsoleWrite("-Suggested extension:" & $at[0][1] & @LF) For $i = 0 To UBound($at) - 1 ConsoleWrite($i + 1 & "==============" & @LF) ConsoleWrite("File Type:" & $at[$i][0] & @LF) ConsoleWrite("Extension:" & $at[$i][1] & @LF) ConsoleWrite("Points:" & $at[$i][2] & @LF) ConsoleWrite("Points %:" & $at[$i][3] & @LF) Next Else Switch $iErr Case 1 ConsoleWrite("!Error: TrIDLib.dll File Not Found in Script Directory.") Case 2 ConsoleWrite("!Error: triddefs.trd File Not Found in Script Directory.") Case 3 ConsoleWrite("!Error: Error occurs during opening TrIDLib.dll") Case 4 ConsoleWrite("!Error: Error occurs during Loading triddefs.trd.") Case 5 ConsoleWrite("!Error: Error occurs during Submitting File: " & $sFile) Case 6 ConsoleWrite("!Error: Error occurs during Analysing File: " & $sFile) Case 7 ConsoleWrite("!Error: Unable to detect file type") EndSwitch ConsoleWrite(@LF) EndIf EndIf WEnd ; Close the search handle FileClose($search) ;Close Dll _TrIDLib_Shutdown() EndFunc ;==>_Example This udf require the following components: TrIDLib.dll - The last x32 DLL file can be found here : http://mark0.net/code-tridlib-e.html triddefs.trd - The last Definition file can be found here : http://mark0.net/soft-trid-e.html Includes in Download: Examples, triddefs.trd and TrIDLib.dll _TrIDLib.7z This is my first udf Hope you will like.
    1 point
  12. Valuater

    Sorting Numbers

    Like This... #include <array.au3> $Array = StringSplit("2,5,3,4,6,1,8,9,7", ",") _ArraySortNum($Array) _ArrayDisplay($Array, "Sorted Array") Func _ArraySortNum(ByRef $n_array, $i_descending = 0, $i_start = 1) Local $i_ub = UBound($n_array) For $i_count = $i_start To $i_ub - 2 Local $i_se = $i_count If $i_descending Then For $x_count = $i_count To $i_ub - 1 If Number($n_array[$i_se]) < Number($n_array[$x_count]) Then $i_se = $x_count Next Else For $x_count = $i_count To $i_ub - 1 If Number($n_array[$i_se]) > Number($n_array[$x_count]) Then $i_se = $x_count Next EndIf Local $i_hld = $n_array[$i_count] $n_array[$i_count] = $n_array[$i_se] $n_array[$i_se] = $i_hld Next EndFunc ;==>_ArraySortNum 8)
    1 point
  13. Andreik

    GDIPlus Vertical Text

    Malkey wrote this nice function: http://www.autoitscript.com/forum/index.ph...st&p=584436 Edit: an example #include <GDIPlus.au3> $GUI = GUICreate("GDI+",400,400) $TEXT = GUICtrlCreateInput("02695",5,5,100,20) $DRAW = GUICtrlCreateButton("DRAW",5,30,50,20) _GDIPlus_Startup() $GRAPHIC = _GDIPlus_GraphicsCreateFromHWND($GUI) GUISetState() While 1 $MSG = GUIGetMsg() If $MSG = -3 Then _GDIPlus_GraphicsDispose($GRAPHIC) _GDIPlus_Shutdown() Exit ElseIf $MSG = $DRAW Then GDIPlus_SetAngledText($GRAPHIC,GUICtrlRead($TEXT),200,200,90,"Arial",12,0xFF000000) EndIf Sleep(20) WEnd Func GDIPlus_SetAngledText($hGraphic, $nText, $iCentreX = 0, $iCentreY = 0, $iAngle = 0, $nFontName = "Arial", _ $nFontSize = 12, $iARGB = 0xFFFF00FF, $iAnchor = 0) Local $iPI = 3.14159265358979 Local $x, $y, $iX, $iY, $iWidth, $iHeight Local $hMatrix, $iXt, $iYt, $hBrush, $hFormat, $hFamily, $hFont, $tLayout If $iAngle = "" Then $iAngle = 0 If $nFontName = "" Or $nFontName = -1 Then $nFontName = "Arial" If $nFontSize = "" Then $nFontSize = 12 If $iARGB = "" Then $iARGB = "0xFF" & Hex(Random(0, 255, 1), 2) & Hex(Random(0, 255, 1), 2) & Hex(Random(0, 255, 1), 2) EndIf $hFormat = _GDIPlus_StringFormatCreate(0) $hFamily = _GDIPlus_FontFamilyCreate($nFontName) $hFont = _GDIPlus_FontCreate($hFamily, $nFontSize, 1, 3) $tLayout = _GDIPlus_RectFCreate($iCentreX, $iCentreY, 0, 0) $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $nText, $hFont, $tLayout, $hFormat) $iWidth = Ceiling(DllStructGetData($aInfo[0], "Width")) $iHeight = Ceiling(DllStructGetData($aInfo[0], "Height")) If $iAnchor = 0 Then $iX = $iCentreX $iY = $iCentreY Else $iX = $iCentreX + (($iWidth - Abs($iHeight * Sin($iAngle * $iPI / 180))) / 2) $iY = $iCentreY + (($iHeight + Abs($iWidth * Sin($iAngle * $iPI / 180))) / 2) EndIf $hMatrix = _GDIPlus_MatrixCreate() _GDIPlus_MatrixRotate($hMatrix, $iAngle, 1) _GDIPlus_GraphicsSetTransform($hGraphic, $hMatrix) $x = ($iWidth / 2) * Cos($iAngle * $iPI / 180) - ($iHeight / 2) * Sin($iAngle * $iPI / 180) $y = ($iWidth / 2) * Sin($iAngle * $iPI / 180) + ($iHeight / 2) * Cos($iAngle * $iPI / 180) $iXt = ($iX - $x) * Cos($iAngle * $iPI / 180) + ($iY - $y) * Sin($iAngle * $iPI / 180) $iYt = -($iX - $x) * Sin($iAngle * $iPI / 180) + ($iY - $y) * Cos($iAngle * $iPI / 180) $hBrush = _GDIPlus_BrushCreateSolid($iARGB) $tLayout = _GDIPlus_RectFCreate($iXt, $iYt, $iWidth, $iHeight) _GDIPlus_GraphicsDrawStringEx($hGraphic, $nText, $hFont, $tLayout, $hFormat, $hBrush) _GDIPlus_MatrixDispose($hMatrix) _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($hBrush) $tLayout = "" Return 1 EndFunc ;==>GDIPlus_SetAngledText
    1 point
  14. I was just about to post the above post when I thought of a possibility. Have you ever wanted to place text on a curve in AutoIt? Well, neither have I. But now you can. The idea was to place each character in a string perpendicular to a curve. Geometry of how it works Using parametic equations for an ellipse, and function parameter, $iStartAngle, the first point on the boundary of the ellipse can be established. The 2nd point in a clockwise direction is established by being a "single character font rectangle width" distance from the 1st point and also on the boundary of the ellipse. This is done in the Do / While loop in the TextDataClockwiseEllipse() function. Note:- Script could bomb out here. Eg. If the font width is close to or greater than the Axis length of the ellipse, the 2nd point will not be established. The 1st and 2nd points on the ellipse, a font width apart, is a chord of the curve. A perpendiculer from the mid-point of the chord at a distance (font height )/2 in a direction away from the centre of the ellipse, gives the x, y values of the centre of the single character rectangle. This x and y values, together with the angle of the perpendicular to the chord are entered as parameters of the GDIPlus_SetAngledText() function, to rotate the text. This is repeated for each character in the string. Although the starting angle of the next character is the angle to the 2nd point of the previous character. That is, an angle from the x-axis to a line which is from the centre of the ellipse to the 2nd point on the boundary of the ellipse. Added Features I can see possible added features by adding rewrites of the TextDataClockwiseEllipse() function. The only two added features are :- An array of colours - (optional) The colours in the array are looped through which colours each character sequencially in the string; and, Spacing of characters - (optional) A plus or minus value to increase or decrease the spacing between characters of the string when displayed on the curve. #include <GuiConstantsEx.au3> #include <GDIPlus.au3> #include <WinAPI.au3> Opt('MustDeclareVars', 1) Global $hGUI, $hGraphic, $hGraphicGUI, $hBMPBuff, $hPen Global Const $iPI = 3.1415926535897932384626433832795 _Main() Func _Main() Local $iGuiX = 350, $iGuiY = 250, $hBrush Local $hMatrix, $iXt, $iYt, $hBrush, $hFormat, $hFamily, $hFont, $tLayout, $aInfo ; Create GUI $hGUI = GUICreate("GDI+ Text 2 Curve", $iGuiX, $iGuiY) ;$hWnd = WinGetHandle("GDI+") GUISetState() _GDIPlus_Startup() $hGraphicGUI = _GDIPlus_GraphicsCreateFromHWND($hGUI) $hBMPBuff = _GDIPlus_BitmapCreateFromGraphics($iGuiX, $iGuiY, $hGraphicGUI) $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBMPBuff) GDIPlus_AntiAlias($hGraphic) ;---- Start of Drawing Graphics $hPen = _GDIPlus_PenCreate(0xFF000000, 1) _GDIPlus_GraphicsClear($hGraphic, 0xFFf0FFF0) GDIPlus_Text2Curve($hGraphic, "An AutoIt Text to Curve Example.", 50, 50, 250, 150, 201, -1, "Arial", 12, 0xFF101010) ; Using an array of colours for each character Local $aARGB[4] = [0xFFF000F0, 0xFF00A000, 0xFFFF0000, 0xFF0000FF] GDIPlus_Text2Curve($hGraphic, "An AutoIt Text to Curve Example.", 50, 50, 250, 150, 200, -1, "Arial", 12, $aARGB) GDIPlus_Text2Curve($hGraphic, "AutoIt", 165, 115, 20, 20, 180, -9, "Arial", 13, 0xFF0000FF) ;---- End of Graphics GUIRegisterMsg(0xF, "MY_PAINT"); Register PAINT-Event 0x000F = $WM_PAINT (WindowsConstants.au3) _WinAPI_RedrawWindow($hGUI, 0, 0, 2) ;PAINT the window Flag $RDW_INTERNALPAINT = 0x0002 ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE ; Clean up resources _GDIPlus_GraphicsDispose($hGraphicGUI) _GDIPlus_PenDispose($hPen) _WinAPI_DeleteObject($hBMPBuff) _GDIPlus_Shutdown() EndFunc ;==>_Main ;Parameters ; $hGraphics - Handle to a Graphics object ; $sText - The string of text to be displayed around the ellipse. ; $iX - The X coordinate of the upper left corner of the rectangle that bounds the ellipse ; in which todraw the arc on which the text will be placed. ; $iY - The Y coordinate of the upper left corner of the rectangle that bounds the ellipse in which to ; draw the arc on which the text will be placed. ; $iWidth - The width of the rectangle that bounds the ellipse in which to draw the arc ; $iHeight - The height of the rectangle that bounds the ellipse in which to draw the arc ; $nStartAngle - The angle between the X axis and the starting point of the arc ; $iSpacing - A plus or minus value to increase or decrease the spacing between the displayed characters. ; $nFontName - Name of the font to use for drawing ; $nFontSize - Font size to use for drawing ; $iARGB - A colour that is used to colour the text. Default is a black. If an array of colours is used, ; the colours will be used sequencially on each character, again and again to end of string. Func GDIPlus_Text2Curve($hGraphics, $sText, $iX, $iY, $iWidth, $iHeight, $iStartAngle = 200, $iSpacing = -1, _ $nFontName = "Arial", $nFontSize = 12, $iARGB = 0xFF000000) Local $aChar, $hFormat, $hFamily, $hFont, $tLayout, $aInfo, $iRectWidth, $iRectHeight, $iMaxRectWidth = 0 Local $hPen1, $aTextDat, $aARGB If IsArray($iARGB) Then $aARGB = $iARGB $aChar = StringSplit($sText, "") Local $aCharAll[$aChar[0] + 1][3] For $n = 1 To $aChar[0] ;ConsoleWrite($n & " " & $aChar[$n] & " Width = ") $hFormat = _GDIPlus_StringFormatCreate(0) $hFamily = _GDIPlus_FontFamilyCreate($nFontName) $hFont = _GDIPlus_FontCreate($hFamily, $nFontSize, 3, 3) $tLayout = _GDIPlus_RectFCreate(50, 50, 0, 0) $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $aChar[$n], $hFont, $tLayout, $hFormat) $aCharAll[$n][1] = Ceiling(DllStructGetData($aInfo[0], "Width")) $aCharAll[$n][2] = Ceiling(DllStructGetData($aInfo[0], "Height")) If $aCharAll[$n][1] > $iMaxRectWidth Then $iMaxRectWidth = $aCharAll[$n][1] ;ConsoleWrite($aCharAll[$n][1 ]& " Height = " & $aCharAll[$n][2] & @CRLF) Next ; Draw Ellipses $hPen1 = _GDIPlus_PenCreate(0xFF800000, 2) ;GDIPlus_AntiAlias($hGraphic) _GDIPlus_GraphicsDrawArc($hGraphic, $iX - $iMaxRectWidth - 2, $iY - $iMaxRectWidth - 2, _ $iWidth + 4 + $iMaxRectWidth * 2, $iHeight + 4 + $iMaxRectWidth * 2, $iStartAngle, 360, $hPen1) _GDIPlus_GraphicsDrawArc($hGraphic, $iX, $iY, $iWidth, $iHeight, $iStartAngle, 360, $hPen1) ;ConsoleWrite( "$iMaxRectWidth = " &$iMaxRectWidth & @CRLF) ; For each character get positioning data, then use GDIPlus_SetAngledText() to draw rotated text. Local $index For $n = 1 To $aChar[0] $aTextDat = TextDataClockwiseEllipse($iStartAngle, $iMaxRectWidth, $aCharAll[$n][2], $iX, $iY, $iWidth, $iHeight, $iSpacing) $iStartAngle = $aTextDat[3] ;ConsoleWrite("$aChar[$n] = " & $aChar[$n] & " $iStartAngle = " & $iStartAngle & @CRLF) If IsArray($aARGB) Then $index = Mod($n, UBound($aARGB)) $iARGB = $aARGB[$index] EndIf GDIPlus_SetAngledText($hGraphic, $aChar[$n], $aTextDat[0], $aTextDat[1], $aTextDat[2], "", "", $iARGB, 0) Next If $hPen1 <> "" Then _GDIPlus_PenDispose($hPen1) EndFunc ;==>GDIPlus_Text2Curve ; Used in conjuction with and called from GDIPlus_Text2Curve(). Func TextDataClockwiseEllipse($iStartAngle, $iRectWidth, $iRectHeight, $iX, $iY, $iWidth, $iHeight, $iSpacing) Local $x2, $y2, $dist, $xT, $yT, $dist1, $xfact, $yfact, $direct, $aRet[4], $iQuadrant, $t, $x, $y Local $SmallAxis Local $h = $iX + ($iWidth / 2) ; X coordinate of centre of ellipse Local $k = $iY + ($iHeight / 2) ; Y coordinate of centre of ellipse Local $a = $iWidth / 2 ; a axis length of ellipse Local $b = $iHeight / 2 ; other axis of ellipse If $a < $b Then $SmallAxis = $a Else $SmallAxis = $a EndIf $iRectWidth += $iSpacing $t = $iStartAngle $x = $h + $a * Cos($t * $iPI / 180); 1st point on ellipse boundary $y = $k + $b * Sin($t * $iPI / 180) ;Initializing ready for Do/Until loop Local $Ang = Int(($iRectWidth / ($SmallAxis * 2)) * 360 / $iPI) + 10 Local $increm = 5 Local $counter = 0 $t = $iStartAngle + $Ang $x2 = $h + $a * Cos($t * $iPI / 180) ; 2nd point on ellipse $y2 = $k + $b * Sin($t * $iPI / 180) $dist = Sqrt(($x - $x2) ^ 2 + ($y - $y2) ^ 2) ; Finds the 2nd point on the ellipse boundary that is $iRectWidth distance from 1st point Do $dist1 = $dist $t = $iStartAngle + $Ang ;The angle from centre of ellipse to 2nd point on ellipse boundary $x2 = $h + $a * Cos($t * $iPI / 180) ; keep adjusting the angle for new 2nd point $y2 = $k + $b * Sin($t * $iPI / 180) $dist = Sqrt(($x - $x2) ^ 2 + ($y - $y2) ^ 2) ; new distance between 1st and 2nd points. If $dist < $iRectWidth Then $Ang += $increm If $dist > $iRectWidth Then $Ang -= $increm If $dist1 < $dist Then $increm = $increm * 0.75 $counter += 1 If $counter > 300 Then MsgBox(0, "Error", "Stuck in Do / Until loop in TextDataClockwiseEllipse()") Exit EndIf ;ConsoleWrite(" $counter = " & $counter &" $iRectWidth = " & $iRectWidth & " $x2 = " & _ ;$x2 & " $y2 = " & $y2 & "$t = " & $t & " Near $dist = " & $dist & @CRLF) Until $dist + 0.000001 > $iRectWidth And $dist - 0.000001 < $iRectWidth Local $AngPerp = ATan(-($x2 - $x) / ($y2 - $y)) * 180 / $iPI + 180;Angle perpendicular to chord, $iRectWidth long ;ConsoleWrite( " $AngPerp = " & $AngPerp & @CRLF) Local $xc = ($x2 - $x) / 2 + $x ;Midpoint of chord Local $yc = ($y2 - $y) / 2 + $y ; Chech which quadrant the angle of the line from the centre of ellipse through centre of $iRectWidth (chord on ellipse) $iQuadrant = Mod(Int((($t - $iStartAngle) / 2 + $iStartAngle) / 90), 4) + 1 Switch $iQuadrant Case 1 ; 1st quadrant between zero and 90 degrees $xfact = -1 $yfact = -1 $direct = -90 Case 2 ; 2nd quadrant between 90 and 180 degrees $xfact = 1 $yfact = 1 $direct = 90 Case 3 ; 3rd quadrant between 180 and 270 degrees $xfact = 1 $yfact = 1 $direct = 90 Case 4 ; 4th quadrant between 270 and 360 degrees $xfact = -1 $yfact = -1 $direct = -90 EndSwitch ; The point that is half the font height ($iRectHeight) distance away from, and is perpendicular to ; the midpoint of the font width($iRectWidth). $iRectWidth is a chord on the curved ellipse boundary. $xT = $xc + $iRectHeight / 2 * Cos($AngPerp * $iPI / 180) * $xfact $yT = $yc + $iRectHeight / 2 * Sin($AngPerp * $iPI / 180) * $yfact $aRet[0] = $xT $aRet[1] = $yT $aRet[2] = $AngPerp + $direct ; $t is the angle off X-axis of line from centre oy ellipse to 2nd point on ellipse boundary. Will become ; starting angle for next character. $aRet[3] = $t Return $aRet EndFunc ;==>TextDataClockwiseEllipse ;Func to redraw the BMP on PAINT MSG Func MY_PAINT($hWnd, $MSG, $wParam, $lParam) ; Check, if the GUI with the Graphic should be repainted If $hWnd = $hGUI Then _GDIPlus_GraphicsDrawImage($hGraphicGUI, $hBMPBuff, 0, 0) EndFunc ;==>MY_PAINT ;See 1st post at http://www.autoitscript.com/forum/index.php?s=&showtopic=81443&view=findpost&p=584436 Func GDIPlus_SetAngledText($hGraphic, $nText, $iCentreX = 0, $iCentreY = 0, $iAngle = 0, $nFontName = "Arial", _ $nFontSize = 12, $iARGB = 0xFFFF00FF, $iAnchor = 0) Local $x, $y, $iX, $iY, $iWidth, $iHeight Local $hMatrix, $iXt, $iYt, $hBrush, $hFormat, $hFamily, $hFont, $tLayout, $aInfo If $iAngle = "" Then $iAngle = 0 If $nFontName = "" Or $nFontName = -1 Then $nFontName = "Arial" ; "Microsoft Sans Serif" If $nFontSize = "" Then $nFontSize = 12 If $iARGB = "" Then ; Randomize ARGB color $iARGB = "0xFF" & Hex(Random(0, 255, 1), 2) & Hex(Random(0, 255, 1), 2) & Hex(Random(0, 255, 1), 2) EndIf $hFormat = _GDIPlus_StringFormatCreate(0) $hFamily = _GDIPlus_FontFamilyCreate($nFontName) $hFont = _GDIPlus_FontCreate($hFamily, $nFontSize, 1, 3) $tLayout = _GDIPlus_RectFCreate($iCentreX, $iCentreY, 0, 0) $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $nText, $hFont, $tLayout, $hFormat) $iWidth = Ceiling(DllStructGetData($aInfo[0], "Width")) $iHeight = Ceiling(DllStructGetData($aInfo[0], "Height")) If $iAnchor = 0 Then ; Reference to middle of Text rectangle $iX = $iCentreX $iY = $iCentreY Else ; Referenced centre point moved to top left corner of text string. $iX = $iCentreX + (($iWidth - Abs($iHeight * Sin($iAngle * $iPI / 180))) / 2) $iY = $iCentreY + (($iHeight + Abs($iWidth * Sin($iAngle * $iPI / 180))) / 2) EndIf $hMatrix = _GDIPlus_MatrixCreate() _GDIPlus_MatrixRotate($hMatrix, $iAngle, 1) _GDIPlus_GraphicsSetTransform($hGraphic, $hMatrix) $x = ($iWidth / 2) * Cos($iAngle * $iPI / 180) - ($iHeight / 2) * Sin($iAngle * $iPI / 180) $y = ($iWidth / 2) * Sin($iAngle * $iPI / 180) + ($iHeight / 2) * Cos($iAngle * $iPI / 180) $iXt = ($iX - $x) * Cos($iAngle * $iPI / 180) + ($iY - $y) * Sin($iAngle * $iPI / 180) $iYt = -($iX - $x) * Sin($iAngle * $iPI / 180) + ($iY - $y) * Cos($iAngle * $iPI / 180) $hBrush = _GDIPlus_BrushCreateSolid($iARGB) $tLayout = _GDIPlus_RectFCreate($iXt, $iYt, $iWidth, $iHeight) _GDIPlus_GraphicsDrawStringEx($hGraphic, $nText, $hFont, $tLayout, $hFormat, $hBrush) _GDIPlus_MatrixDispose($hMatrix) _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($hBrush) $tLayout = "" Return 1 EndFunc ;==>GDIPlus_SetAngledText Func GDIPlus_AntiAlias($hGraphics) Local $aResult $aResult = DllCall($ghGDIPDll, "int", "GdipSetSmoothingMode", "hwnd", $hGraphics, "int", 2) If @error Then Return SetError(@error, @extended, False) Return SetError($aResult[0], 0, $aResult[0] = 0) EndFunc ;==>GDIPlus_AntiAlias Enjoy
    1 point
×
×
  • Create New...