Chimaera

AutoIt Snippets

277 posts in this topic

#261 ·  Posted

Just what I was looking for :D

Share this post


Link to post
Share on other sites



#262 ·  Posted

Autoit Thread

If you want a function to be a true thread with it's own PID and all then check out this super simple example that does it well...

 

 

test.exe

test.au3

Share this post


Link to post
Share on other sites

#263 ·  Posted

2 hours ago, InternetMonkeyBoy said:

Autoit Thread

If you want a function to be a true thread with it's own PID and all then check out this super simple example that does it well...

 

 

test.exe

test.au3

This is not real thread.. it is just more processes. you may be interested in my udf to add the communication functionality.

Share this post


Link to post
Share on other sites

#264 ·  Posted

Autoit multi threading and _WinAPI_Create_Process - I just couldn't find / or get it to do what I needed.   This did it perfectly with only autoit code.  No DLL or fancy calls.  I say it rocks!

Share this post


Link to post
Share on other sites

#265 ·  Posted

; This works very very well.  Low CPU.  All you have is the exe in memory for each thread.

; Send messages anyway you need.  Try the iniwrite()/iniread(), regwrite()/regread, or fancy  _NamedPipes.

#include <WinAPI.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>
#include <WinAPIShPath.au3>
#include <Misc.au3>

If $CmdLine[0] > 0 Then
    If $CmdLine[1] = "MyFuncThread1" Then MyFuncThread1()
    If $CmdLine[1] = "MyFuncThread2" Then MyFuncThread2()
    If $CmdLine[1] = "MyFuncThread3" Then MyFuncThread3()
EndIf

If @Compiled Then
    ShellExecute(@AutoItExe, "MyFuncThread1")
    ShellExecute(@AutoItExe, "MyFuncThread2")
    ShellExecute(@AutoItExe, "MyFuncThread3")
Else
    ShellExecute(@ScriptName, "MyFuncThread1")
    ShellExecute(@ScriptName, "MyFuncThread2")
    ShellExecute(@ScriptName, "MyFuncThread3")
EndIf

;*** WARNING, if your thread returns without exiting - it will respawn.  (Maybe you need that?)

Func MyFuncThread1()
    _Singleton("MyFuncThread1", 0)
    MsgBox(0, "", "Thread 1", 0)
    Exit
EndFunc   ;==>MyFuncThread1

Func MyFuncThread2()
    _Singleton("MyFuncThread2", 0)
    MsgBox(0, "", "Thread 2", 0)
    Exit
EndFunc   ;==>MyFuncThread2

Func MyFuncThread3()
    _Singleton("MyFuncThread3", 0)
    MsgBox(0, "", "Thread 3", 0)
    Exit
EndFunc   ;==>MyFuncThread3

Oh, I forgot to post the code so here it is...

Share this post


Link to post
Share on other sites

#266 ·  Posted

Base64 Snippets:

; #FUNCTION# ====================================================================================================================
; Name ..........: _Base64_Encode
; Description ...: Encode the $vData in Base64
; Syntax ........: _Base64_Encode($vData)
; Parameters ....: $vData               - $vData to Encode.
; Return values .: Success: Base64 encoded $vData in the form of a string.
;                  Failure: False and @error set to:
;                           1 - If "error calculating the length of the buffer needed"
;                           2 - If "error encoding"
; Author ........: trancexx
; Modified ......: Damon Harris (TheDcoder)
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _Base64_Encode($vData)
    $vData = Binary($vData)
    Local $tByteStruct = DllStructCreate("byte[" & BinaryLen($vData) & "]")
    DllStructSetData($tByteStruct, 1, $vData)
    Local $tIntStruct = DllStructCreate("int")
    Local $aDllCall = DllCall("Crypt32.dll", "int", "CryptBinaryToString", _
            "ptr", DllStructGetPtr($tByteStruct), _
            "int", DllStructGetSize($tByteStruct), _
            "int", 1, _
            "ptr", 0, _
            "ptr", DllStructGetPtr($tIntStruct))
    If @error Or Not $aDllCall[0] Then
        Return SetError(1, 0, False) ; error calculating the length of the buffer needed
    EndIf
    Local $tCharStruct = DllStructCreate("char[" & DllStructGetData($tIntStruct, 1) & "]")
    $aDllCall = DllCall("Crypt32.dll", "int", "CryptBinaryToString", _
            "ptr", DllStructGetPtr($tByteStruct), _
            "int", DllStructGetSize($tByteStruct), _
            "int", 1, _
            "ptr", DllStructGetPtr($tCharStruct), _
            "ptr", DllStructGetPtr($tIntStruct))
    If @error Or Not $aDllCall[0] Then
        Return SetError(2, 0, False) ; error encoding
    EndIf
    Return DllStructGetData($tCharStruct, 1)
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: _Base64_Decode
; Description ...: Decode a base64 string
; Syntax ........: _Base64_Decode($sBase64)
; Parameters ....: $sBase64             - $sBase64 to decode.
; Return values .: Success: Decode data in the form of binary
;                  Failure: False & @error set to:
;                           1 - If "error calculating the length of the buffer needed"
;                           2 - If "error decoding"
; Author ........: trancexx
; Modified ......: Damon Harris (TheDcoder)
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _Base64_Decode($sBase64)
    Local $tIntStruct = DllStructCreate("int")
    $aDllCall = DllCall("Crypt32.dll", "int", "CryptStringToBinary", _
            "str", $sBase64, _
            "int", 0, _
            "int", 1, _
            "ptr", 0, _
            "ptr", DllStructGetPtr($tIntStruct, 1), _
            "ptr", 0, _
            "ptr", 0)
    If @error Or Not $aDllCall[0] Then
        Return SetError(1, 0, False) ; error calculating the length of the buffer needed
    EndIf
    Local $tByteStruct = DllStructCreate("byte[" & DllStructGetData($tIntStruct, 1) & "]")
    $aDllCall = DllCall("Crypt32.dll", "int", "CryptStringToBinary", _
            "str", $sBase64, _
            "int", 0, _
            "int", 1, _
            "ptr", DllStructGetPtr($tByteStruct), _
            "ptr", DllStructGetPtr($tIntStruct, 1), _
            "ptr", 0, _
            "ptr", 0)
    If @error Or Not $aDllCall[0] Then
        Return SetError(2, 0, False); error decoding
    EndIf
    Return DllStructGetData($tByteStruct, 1)
EndFunc

I don't take credit, @trancexx made it, I just polished the functions, enjoy!

 

TD :D


Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

#267 ·  Posted

; Hours, Minutes, Seconds To Milliseconds
Func _HMS_To_MS($H = 0, $M = 0, $S = 0)
    Local $Rtn = 0
    If $S > 0 Then
        $Rtn += $S * 1000
    EndIf

    If $M > 0 Then
        $Rtn += $M * (1000 * 60)
    EndIf

    If $H > 0 Then
        $Rtn += $H * ((1000 * 60) * 60)
    EndIf
    Return $Rtn
EndFunc

 


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

#268 ·  Posted

8 hours ago, JohnOne said:
; Hours, Minutes, Seconds To Milliseconds
Func _HMS_To_MS($H = 0, $M = 0, $S = 0)
    Local $Rtn = 0
    If $S > 0 Then
        $Rtn += $S * 1000
    EndIf

    If $M > 0 Then
        $Rtn += $M * (1000 * 60)
    EndIf

    If $H > 0 Then
        $Rtn += $H * ((1000 * 60) * 60)
    EndIf
    Return $Rtn
EndFunc

 

Or in a simpler form...

; Hours, Minutes, Seconds To Milliseconds
Func _HMS_To_MS($H = 0, $M = 0, $S = 0)
    Return $H * 3600000 + $M * 60000 + $S * 1000
EndFunc   ;==>_HMS_To_MS

... & the return trip...

; Milliseconds To Hours:Minutes:Seconds
Func _MS_TO_HHMMSS($iMs)
    $iMs /= 1000
    Return StringFormat("%02d:%02d:%02d", Floor($iMs / 3600), Mod(Floor($iMs / 60), 60), Mod($iMs, 60))
EndFunc   ;==>_MS_TO_HHMMSS

 

2 people like this

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#269 ·  Posted

Subclass labels to make them link with their corresponding checkbox. Ran into an issue creating a picture background with some checkboxes on it and the checkbox label wasn't transparent, but labels are. The checkbox doesn't get the highlight until you actually left click on it but I think it's a cleaner way of doing it since I can make windows send the handle of the checkbox this label goes to.

#include <GUIConstants.au3>
#include <StaticConstants.au3>
#include <WinAPIShellEx.au3>
#include <WinAPI.au3>

Global $pNewWindowProc = DllCallbackGetPtr(DllCallbackRegister("NewWindowProc", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr"))
Global $hMain = GUICreate("Example", 200, 450)
Global $aCheckHandles[22]
Global $aLabelHandles[22]
Global $tRectMain = _WinAPI_GetClientRect($hMain)

For $i = 0 to 21
    $aCheckHandles[$i] = GUICtrlGetHandle(GUICtrlCreateCheckbox("", DllStructGetData($tRectMain, "right") - 20, 10 + $i * 20, 13, 13))
    $aLabelHandles[$i] = GUICtrlGetHandle(GUICtrlCreateLabel("Label " & $i, DllStructGetData($tRectMain, "right") - ($i < 10 ? 75 : 85), 10 + $i * 20, ($i < 10 ? 50 : 60), 20))
    GUICtrlSetFont(-1, 10, 600, "", "Arial")
    GUICtrlSetColor(-1, 0X1F1F1F)
Next

GUISetState(@SW_SHOW, $hMain)

For $i = 0 to 21
    _WinAPI_SetWindowSubclass($aLabelHandles[$i], $pNewWindowProc, 9999, $aCheckHandles[$i])
Next


While (True)
    Switch (GUIGetMsg())
        Case $GUI_EVENT_CLOSE
            For $i = 0 to 21
                _WinAPI_RemoveWindowSubclass($aLabelHandles[$i], $pNewWindowProc, 9999)
            Next
            GUIDelete($hMain)
            Exit 0
    EndSwitch
WEnd

Func NewWindowProc($hWnd, $iMsg, $wParam, $lParam, $uIdSubclass, $dwRefData)
    If ($iMsg = $WM_LBUTTONUP Or $iMsg = $WM_LBUTTONDOWN Or $iMsg = $WM_MOUSEMOVE) Then Return _SendMessage($dwRefData, $iMsg, $wParam, _WinAPI_MakeLong(3, 3))
    Return _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam)
EndFunc

 

Share this post


Link to post
Share on other sites

#270 ·  Posted

Day of the week

MsgBox(0, '', "Today is " & _DayOfTheWeek())
MsgBox(0, '', "Johann Sebastian Bach was born on " & _DayOfTheWeek(1685, 3, 31))

;  Passing a date in the form (yyyy, mm, dd) it returns the day of the week
Func _DayOfTheWeek($y = @YEAR, $m = @MON, $d = @MDAY)
    Local Static $aDaysOfWeek[7] = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
    Local $fJulianDay = 367 * $y - Int(7 * ($y + Int(($m + 9) / 12)) / 4) - Int(3 * (Int(($y + Int(($m - 9) / 7)) / 100) + 1) / 4) + Int(275 * $m / 9) + $d + 1721028.5
    Local $iDOW = Mod($fJulianDay + .5, 7) ; 0 = Monday . . . 6 = Sunday
    Return $aDaysOfWeek[$iDOW]
EndFunc   ;==>_DayOfTheWeek

 

2 people like this

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#271 ·  Posted

Is that significantly different from _DateDayOfWeek() from Date.au3?


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#272 ·  Posted

6 hours ago, jchd said:

Is that significantly different from _DateDayOfWeek() from Date.au3?

Yes it is,
this one I posted here is worse and even worst it's not multilingual..... :D

jokes apart, this is just another way to have all in one line without the need to include the whole date.au3
When I came across this formula,  I liked it and I could not resist to post here this snippet, that's all.


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#274 ·  Posted (edited)

The most efficient and fast  way to store number in Array and then  check if the number is exists in the array.

#include <Array.au3>


Global $g_aNumbers[101]

AddNumber(0)
AddNumber(5)
AddNumber(80)
AddNumber(21)
AddNumber(100)

ConsoleWrite('Number 0: '&NumberExists(0)&@CRLF)
ConsoleWrite('Number 5: '&NumberExists(5)&@CRLF)
ConsoleWrite('Number 80: '&NumberExists(80)&@CRLF)
ConsoleWrite('Number 21: '&NumberExists(21)&@CRLF)
ConsoleWrite('Number 100: '&NumberExists(100)&@CRLF)


ConsoleWrite('Number 1: '&NumberExists(1)&@CRLF)
ConsoleWrite('Number 6: '&NumberExists(6)&@CRLF)
ConsoleWrite('Number 81: '&NumberExists(81)&@CRLF)
ConsoleWrite('Number 22: '&NumberExists(22)&@CRLF)
ConsoleWrite('Number 99: '&NumberExists(99)&@CRLF)



Func AddNumber($iNumber)
    $g_aNumbers[$iNumber] = True
EndFunc

Func RemoveNumber($iNumber)
    $g_aNumbers[$iNumber] = False
EndFunc

Func NumberExists($iNumber)
    Return $g_aNumbers[$iNumber]
EndFunc

 

Note that this technique requires that the array size will be the size of the biggest number + 1 that you may store.
It is ultra fast compared to Array search

Edited by gil900

Share this post


Link to post
Share on other sites

#275 ·  Posted

If you know how many there are because you have to set the ubound, and you know where they are because you can totally count.  Why would you need an array?  You have developed a rube goldberg machine for setting flags.


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

#276 ·  Posted (edited)

I do not understand. What is the alternative? use 101 variables, each representing a number?
It does not seem right to me ..

In my case my max count is 255. (not 100) I need to know if a x number (that is <= 255 and >= 0) is exists. and I want it to be fast as possible.
The only way I thought about how to do it without loop is in this way. do you have a better idea? If so, I'd love to know.

 

Edit:
Oh, flags. I understand .. it does not appear in my head. This may also good..
But in my case, the machine flags I developing is more complex then the example. it is 3d array (it is std::vector<std::vector<std::vector<byte>>> vecRgbColorsA;) of bytes.. and it is in c++ ..

Screenshot_6.png.c65848ecd232c1976b92556

 

This is the  concept and it works.

Now if I want to check if the color 10,8,9 is added, I go to index 10 (the R value) inside the array of R.
If it's .size() is bigger then 0 then I continue to check and go into the sub array to look for 8,9 (GB)
It works
 

 

Edited by gil900

Share this post


Link to post
Share on other sites

#277 ·  Posted

On Dienstag, 24. Juli 2012 at 4:11 PM, guinness said:

[translate the language code] using _GetOSLanguage (see signature) but didn't bother.

I noticed that "_Iif" has been removed since v3.3.10, so here is an updated version of above script:

#include <Misc.au3>

; Version: 1.10. AutoIt: V3.3.14.2 - replaced _Iif
; Retrieve the recommended information of the current system when posting a support question.
Local $sSystemInfo = 'For my AutoIt support question, here the details of my system:' & @CRLF & @CRLF & _
        'AutoIt  Version: V' & @AutoItVersion & _ ; ' [' & _ Iif(@AutoItX64, 'X64', 'X32') & ']' & @CRLF & _
        ' [' &( (@AutoItX64<>0) ? ('X64'):('X32') )& ']' & @CRLF & _
        'Windows Version: ' & @OSVersion & ' [' & _GetOSLanguage() & ']' & @CRLF & _
        'Language: ' & @OSLang & @CRLF & @CRLF
MsgBox(4096, 'Get this info from the clipboard with Ctrl + V.', $sSystemInfo)
ClipPut($sSystemInfo)

; #FUNCTION# ====================================================================================================================
; Name ..........: _GetOSLanguage
; Description ...: Retrieves the language of the OS, this supports 19 of the most popular languages.
; Syntax ........: _GetOSLanguage()
; Parameters ....: None
; Return values .: None
; Author ........: guinness
; Link ..........: http://www.autoitscript.com/forum/topic/131832-getoslanguage-retrieve-the-language-of-the-os/
; Example .......: No
; ===============================================================================================================================
Func _GetOSLanguage()
    Local $aString[20] = [19, "0409 0809 0c09 1009 1409 1809 1c09 2009 2409 2809 2c09 3009 3409", "0404 0804 0c04 1004 0406", "0406", "0413 0813", "0425", _
            "040b", "040c 080c 0c0c 100c 140c 180c", "0407 0807 0c07 1007 1407", "040e", "0410 0810", _
            "0411", "0414 0814", "0415", "0416 0816", "0418", _
            "0419", "081a 0c1a", "040a 080a 0c0a 100a 140a 180a 1c0a 200a 240a 280a 2c0a 300a 340a 380a 3c0a 400a 440a 480a 4c0a 500a", "041d 081d"]

    Local $aLanguage[20] = [19, "English", "Chinese", "Danish", "Dutch", "Estonian", "Finnish", "French", "German", "Hungarian", "Italian", _
            "Japanese", "Norwegian", "Polish", "Portuguese", "Romanian", "Russian", "Serbian", "Spanish", "Swedish"]
    For $i = 1 To $aString[0]
        If StringInStr($aString[$i], @OSLang) Then
            Return $aLanguage[$i]
        EndIf
    Next
    Return $aLanguage[1]
EndFunc   ;==>_GetOSLanguage

I also shortened the message to fit into the top of the MsgBox().


-HaJo

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now