Jump to content

AutoIt Snippets


Chimaera
 Share

Recommended Posts

A fure AutoIt function to display number with group!

It good for me. and not sure for any one, please test before use

Func num($num, $round = 0, $group = ",", $negative = "-", $decimal = ".")
    If $num = 0 Then Return "0" 
    Local $sign = ""    
    $num = StringReplace($num, $group, "")
    If StringInStr($num, $negative) Then
        $num = StringReplace($num, $negative, "")
        $sign = "-"
    EndIf
    $split = StringSplit($num, $decimal, 2)
    $int = $split[0]
    $tail = ""
    If UBound($split) >= 2 Then
        $tail = $split[1]
    Else
        $mod = Mod(StringLen($int), 3)
        If $mod = 0 Then
            $int = StringRegExpReplace($int, "(\d{1,3})", ".$1")
            $int = StringRight($int, StringLen($int) - 1)
            If $round = 0 Then
                Return $sign & $int
            Else
                Return $sign & $int & "," & StringFormat("%0" & $round & "s", "0")
            EndIf
        ElseIf $mod = 2 Or $mod = 1 Then
            $int1 = StringLeft($int, $mod)
            $int2 = StringRight($int, StringLen($int) - $mod)
            If $round = 0 Then
                Return $sign & $int1 & StringRegExpReplace($int2, "(\d{1,3})", ".$1")
            Else
                Return $sign & $int1 & StringRegExpReplace($int2, "(\d{1,3})", ".$1") & "," & StringFormat("%0" & $round & "s", "0")
            EndIf
        EndIf
    EndIf
    $tail = Round("0." & $tail, $round)
    If $tail = 1 Then
        $int = $int + 1
        $tail = StringFormat("%0" & $round & "s", "0")
        $mod = Mod(StringLen($int), 3)
        If $mod = 0 Then
            $int = StringRegExpReplace($int, "(\d{1,3})", ".$1")
            If $round = 0 Then
                Return $sign & StringRight($int, StringLen($int) - 1)
            Else
                Return $sign & StringRight($int, StringLen($int) - 1) & "," & StringMid(StringFormat("%f", $tail), 3, $round)
            EndIf
        ElseIf $mod = 2 Or $mod = 1 Then
            $int1 = StringLeft($int, $mod)
            $int2 = StringRight($int, StringLen($int) - $mod)
            If $round = 0 Then
                Return $sign & $int1 & StringRegExpReplace($int2, "(\d{1,3})", ".$1")
            Else
                Return $sign & $int1 & StringRegExpReplace($int2, "(\d{1,3})", ".$1") & "," & StringMid(StringFormat("%f", $tail), 3, $round)
            EndIf
        EndIf
    Else
        $mod = Mod(StringLen($int), 3)
        If $mod = 0 Then
            $int = StringRegExpReplace($int, "(\d{1,3})", ".$1")
            $int = StringRight($int, StringLen($int) - 1)
            If $round = 0 Then
                Return $sign & $int
            Else
                Return $sign & $int & "," & StringMid(StringFormat("%f", $tail), 3, $round)
            EndIf
        ElseIf $mod = 2 Or $mod = 1 Then
            $int1 = StringLeft($int, $mod)
            $int2 = StringRight($int, StringLen($int) - $mod)
            If $round = 0 Then
                Return $sign & $int1 & StringRegExpReplace($int2, "(\d{1,3})", ".$1")
            Else
                Return $sign & $int1 & StringRegExpReplace($int2, "(\d{1,3})", ".$1") & "," & StringMid(StringFormat("%f", $tail), 3, $round)
            EndIf
        EndIf
    EndIf
EndFunc   ;==>num

 

Link to comment
Share on other sites

  • 1 month later...

I wrote code to remove carriage returns that are only there for formatting reasons. So every newline sequence followed by text directly will be replaced with a space only.

That could be helpful if you copy a text somewhere and want to paste it to a place where are longer lines.

#include <MsgBoxConstants.au3>
Local $sText = ClipGet()
Local $sRegexKillEnters = "(?m)(?<=\V)\R(?!\R|\h\h|\t)" ; (any character that's not a vertical whitespace ); any Unicode newline sequence; (but not if second 2. Unicode newline sequence or 2 Spaces or a Tab - spaces and tab could be a list)
$sText = StringRegExpReplace($sText, $sRegexKillEnters, " ")
Local $sRegexKeepListingIntendation = "(?m)(?<=^)\h{2,}" ; replace start of a line and more than 1 space with a tabulator - to keep listing
$sText = StringRegExpReplace($sText, $sRegexKeepListingIntendation, @TAB)
Local $sRegexKillMoreThenOneSpace = "(?m)\h{2,}" ; replace more than 1 spaces with only 1
$sText = StringRegExpReplace($sText, $sRegexKillMoreThenOneSpace, " ")
MsgBox($MB_TOPMOST, "Result", $sText)
ClipPut($sText)

Thanks @mikell for the correct "kill enters" symbol.

Simpel

SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win_10   Build = 19044   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Link to comment
Share on other sites

  • 1 month later...

To know if a control is checked or not. 

Func _IsChecked($idControlID)
    Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED
EndFunc

 

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

I was playing with FolderDescriptions and special folders and wrote this. It may be useful for someone else.
 

#include <Debug.au3>
#include <Array.au3>
Local $a

$a = Enumerate_SpecialFolders()
_DebugArrayDisplay($a, "Enumerate_SpecialFolders()")
Func Enumerate_SpecialFolders()
    Local $t = TimerInit(), $n, $a[101][2], $o, $s, $objShell = ObjCreate("Shell.Application")
    $a[0][0] = 0
    For $n = 1 To UBound($a) - 1
        $o = $objShell.NameSpace($n)
        If Not IsObj($o) Then ContinueLoop
        If StringInStr($s, "|" & $o.Self.Path & "|") Then ContinueLoop
        If Not StringInStr($o.Self.Path, ":") Then ContinueLoop
        $a[0][0] += 1
        $a[$a[0][0]][1] = $o.Self.Path
        $a[$a[0][0]][0] = $o.Self.Name
        $s &= "|" & $a[$a[0][0]][1] & "|"
        ConsoleWrite($a[$a[0][0]][0] & @CRLF & @TAB & $a[$a[0][0]][1] & @CRLF)
    Next
    ReDim $a[$a[0][0] + 1][2]
    _ArraySort($a, 0, 1, 0, 1)
    For $n = 1 To UBound($a) - 1
        If StringLeft($a[$n][1], 1) = ":" Then ContinueLoop
        $a[0][1] = $n ; future use
        _ArraySort($a, 0, 1, $n - 1, 0)
        _ArraySort($a, 0, $n, UBound($a) - 1, 0)
        ExitLoop
    Next
    $a[0][1] = "Time: " & Int(TimerDiff($t)) & " ms."
    Return $a
EndFunc   ;==>Enumerate_SpecialFolders

$a = Reg_FolderDescriptions()
_DebugArrayDisplay($a, "Reg_FolderDescriptions()")
Func Reg_FolderDescriptions()
    Local $t = TimerInit(), $sHKLM = "HKLM"
    If StringInStr(@OSArch, "64") Then $sHKLM = "HKLM64"
    Local $sRootKeyName = $sHKLM & "\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions"
    Local $sSubKey = "", $x = 0, $aEnumKey[10000][10]
    $aEnumKey[0][1] = "Name"
    $aEnumKey[0][2] = "Category"
    $aEnumKey[0][3] = "Attributes"
    $aEnumKey[0][4] = "Roamable"
    $aEnumKey[0][5] = "ParsingName"
    For $n = 1 To 10000
        $sSubKey = RegEnumKey($sRootKeyName, $n)
        If @error Then ExitLoop
        If RegRead($sRootKeyName & '\' & $sSubKey, "Name") = "" Then ContinueLoop
        $x += 1
        $aEnumKey[$x][0] = $sSubKey
        $aEnumKey[$x][1] = RegRead($sRootKeyName & '\' & $sSubKey, "Name")
        $aEnumKey[$x][2] = RegRead($sRootKeyName & '\' & $sSubKey, "Category")
        $aEnumKey[$x][3] = RegRead($sRootKeyName & '\' & $sSubKey, "Attributes")
        $aEnumKey[$x][4] = RegRead($sRootKeyName & '\' & $sSubKey, "Roamable")
        $aEnumKey[$x][5] = RegRead($sRootKeyName & '\' & $sSubKey, "ParsingName")
    Next
    ReDim $aEnumKey[$x + 1][6]
    $aEnumKey[0][0] = $x
    _ArraySort($aEnumKey, 0, 1, 0, 1)
    $aEnumKey[0][1] = "Time: " & Int(TimerDiff($t)) & " ms."
    Return $aEnumKey
EndFunc   ;==>Reg_FolderDescriptions

 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

  • 3 weeks later...

This is probably more a tool than a function but should be helpful.

This script will take rows and columns that you copy to the clipboard from Excel and produce autoit code to create a one or two dimensional array.

I was doing a mock-up of a menu system in Excel and once I had what I liked I thought it would be nice if I could just copy and paste it into Autoit as dim array code.

 

To use the script go in Excel  highlight the data you want to use and copy it while you still have dashed lines around the data run the script and it will produce autoit code to define an array in the console and copied to the clipboard. Then you can paste the array code into your program.

Note that Excel only has the data on the clipboard while there are dotted lines around the data. If you don't get what you expect check and see that there are dashes around the Excel data.

 

A matrix can be looked at as either rows and columns or columns and rows (2,5) or (5,2). Because of what I was working on the system defaults to columns and rows but if you want to see it the other way there's a string variable called $transpose that's defined as True if you change that to False you will get code with rows and columns.

 

Another nice use I found was I had display array up with about 20 files showing in it and I needed about 8 of them so I control clicked on the 8 and pressed copy data then ran my program can it produced a 1d array code.

 

I hope someone uses this (actually a lot of people) because my girlfriend says it will never save me the time I put into it. Of course she doesn't understand that it was fun doing it.

For some reason my code colors didn't come out right when I pasted it below....

Scratch that the colors are fine now that I left the page and went back to it.

;Excel matrix to Autoit array code
#include <array.au3>
#include <string.au3>

$transpose = True
$sClipt = ClipGet()
$sClipt = StringReplace($sClipt, Chr(10), "") ;remove those pesky line feeds
If StringInStr($sClipt, @TAB) = 0  Then make_code_1D()

$sClipt = StringReplace($sClipt, @TAB, "|") ;save the tabs
$aE = StringSplit($sClipt, @CR, $STR_NOCOUNT)
_ArrayDelete($aE, UBound($aE) - 1) ;remove the last row
$aE3 = StringSplit($aE[0], "|", $STR_NOCOUNT)
Dim $aE3[0][UBound($aE3)]
;Build up the $aE3 array
For $i = 0 To UBound($aE) - 1
    ;ConsoleWrite($i &" "& $aE[$i] & @CRLF)
    $aE2 = StringSplit($aE[$i], "|", $STR_NOCOUNT)
    _ArrayTranspose($aE2)
    _ArrayAdd($aE3, $aE2)
Next

If $transpose Then _ArrayTranspose($aE3)
;_ArrayDisplay($aE3, "Before save")
make_code_2D($aE3)

Func make_code_2D($aD)
    Local $q = '"'
    Local $sLine = "dim $aAr[" & UBound($aD, 2) & "][" & UBound($aD) & "] = [["
    For $j = 0 To UBound($aD, 2) - 1
        For $i = 0 To UBound($aD) - 1
            $sLine = $sLine & $q & $aD[$i][$j] & $q & ", "
        Next
        $sLine = StringTrimRight($sLine, 2) & "], ["
    Next
    $sLine = StringTrimRight($sLine, 3) & "]"
    ConsoleWrite($sLine & @CRLF)
    ClipPut($sLine)
EndFunc   ;==>make_code_2D

Func make_code_1D()
    Local $q = '"'
    Local $aD = StringSplit($sClipt, @CR, $STR_NOCOUNT)
    _ArrayDelete($aD, UBound($aD) - 1) ;remove the last row
    Local $sLine = "dim $aAr[" & UBound($aD) & "] = ["
    For $i = 0 To UBound($aD) - 1
        $sLine = $sLine & $q & $aD[$i] & $q & ", "
    Next
    $sLine = StringTrimRight($sLine, 2) & "]"
    ConsoleWrite($sLine & @CRLF)
    ClipPut($sLine)
    Exit
EndFunc   ;==>make_code_1D

 

Edited by wolflake
Link to comment
Share on other sites

  • 1 month later...

For any use this might get later: Bookmarking it Here for now ..  (_ArrayAppendToRow, _ArrayShrink)

 

;~ https://www.autoitscript.com/forum/topic/197474-indexing-idea

#include <Array.au3>

Local $Array[4][11] = [ _
        [], _
        ["B", 1], _
        ["C", 1, 2], _
        ["D", 1, 2, 3]]

_ArrayDisplay($Array, "Original")
_ArrayShrink($Array)    ; shrink the Array to the first none blank Col
_ArrayDisplay($Array, "Original (shrinked)")

_ArrayAppendToRow($Array, 1, "|||||Append-Point")   ;Appended with blanks
_ArrayAppendToRow($Array, 1, "Another Append Point")    ;Appended to first blank Col
_ArrayAppendToRow($Array, 0, _ArrayExtract($Array, 0, Default, 0, 0))  ;1D (COl 0) ;Array
_ArrayAppendToRow($Array, 2, "Append-Point|11|12|13")
_ArrayAppendToRow($Array, 3, "Append-Point|11|12")

$iNew = _ArrayAdd($Array, "")
_ArrayAppendToRow($Array, $iNew, "^>>")

_ArrayDisplay($Array, "Original + Appends")

Func _ArrayAppendToRow(ByRef $Array, $iRow, $Vadd)
    Local $aAdd = (StringInStr($Vadd, "|") ? StringSplit($Vadd, "|", 3) : ($Vadd ? 1 : $Vadd))
    Local $i = UBound(StringRegExp(_ArrayToString($Array, "|", $iRow, $iRow), "[^|]+\|", 3))
    Local $iColAdd = ($aAdd ? $aAdd : UBound($aAdd))
    If UBound($Array, 2) - ($i + $iColAdd) < 0 Then ReDim $Array[UBound($Array)][$i + $iColAdd]
    If $iColAdd > 1 Then
        For $j = 0 To UBound($aAdd) - 1
            $Array[$iRow][$i + $j] = $aAdd[$j]
        Next
    Else
        $Array[$iRow][$i] = $Vadd
    EndIf
EndFunc   ;==>_ArrayAppendToRow

Func _ArrayShrink(ByRef $Array)
    Local $iCols = UBound($Array, 2), $aCol, $x = 0
    Do
        $x += 1
        $aCol = _ArrayExtract($Array, Default, Default, ($iCols - $x), ($iCols - $x))
    Until UBound(StringRegExp(_ArrayToString($aCol, "|"), "[^|]+", 3))
    If $x > 1 Then ReDim $Array[UBound($Array)][$iCols - $x + 1]
EndFunc   ;==>_ArrayShrink

 

Edited by Deye
Link to comment
Share on other sites

  • 3 weeks later...

using _arrayadd instead of stringsplit and ubound

Just dropped this in a thread and thought it slightly clever, cant remember if its been explored already. You are probably eating some time penalties for being lazy, but look how lazy you can be.

#include<array.au3>

$str = "computer:user:45ms"
;~ $str = "computer:user45ms"
;~ $str = "computeruser45ms"
local $arr[0]

for $i = 0 to _ArrayAdd($arr , $str , 0 , ":")
    msgbox(0, $i + 1 & ' of ' & ubound($arr), $arr[$i])
next

 

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

Link to comment
Share on other sites

  • 3 weeks later...

..didn't want to post as a new example, as is just how to do it.
There is no example of _GUICtrlMenu_GetItemChecked() and _GUICtrlMenu_GetSystemMenu() in the same code, so ( more like a note to self ) here it is:

#include <GuiMenu.au3>

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("SystemMenu: Add Menu example", 615, 143)
Global $Button1 = GUICtrlCreateButton("Button1", 24, 24, 75, 25)
Global $Edit1 = GUICtrlCreateEdit("", 128, 16, 457, 105)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
GUICtrlSetOnEvent($Button1, "Button1Click")

Global Enum $eSys_Top = 2200, $eSys_Bottom, $eSys_TopSub
Global $hMenu = _GUICtrlMenu_CreateMenu()
_GUICtrlMenu_InsertMenuItem(_GUICtrlMenu_GetSystemMenu($Form1), 0, "", 0)
_GUICtrlMenu_InsertMenuItem(_GUICtrlMenu_GetSystemMenu($Form1), 0, "&Up on top", $eSys_Top, $hMenu)
_GUICtrlMenu_InsertMenuItem($hMenu, 0, "&Up on top sub", $eSys_TopSub)
_GUICtrlMenu_InsertMenuItem(_GUICtrlMenu_GetSystemMenu($Form1), -1, "", 0)
_GUICtrlMenu_InsertMenuItem(_GUICtrlMenu_GetSystemMenu($Form1), -1, "&Down on bottom", $eSys_Bottom)

GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND")
Func WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam)
    #forceref $hWnd, $Msg, $lParam
    Local $nID = BitAND($wParam, 0x0000FFFF)
    Switch $nID
        Case $eSys_Bottom, $eSys_TopSub
            Local $hSystemMenu = _GUICtrlMenu_GetSystemMenu($Form1)
            If _GUICtrlMenu_GetItemChecked($hSystemMenu, $nID, False) Then
                GUICtrlSetData($Edit1, "menu  " & $nID & "  unchecked at " & @HOUR & ":" & @MIN & ":" & @SEC & "." & @MSEC)
                _GUICtrlMenu_SetItemChecked($hSystemMenu, $nID, False, False)
            Else
                GUICtrlSetData($Edit1, "menu  " & $nID & "  checked at " & @HOUR & ":" & @MIN & ":" & @SEC & "." & @MSEC)
                _GUICtrlMenu_SetItemChecked($hSystemMenu, $nID, True, False)
            EndIf
    EndSwitch
EndFunc   ;==>WM_SYSCOMMAND

While 1
    Sleep(100)
WEnd

Func Button1Click()
    GUICtrlSetData($Edit1, "clicked at " & @HOUR & ":" & @MIN & ":" & @SEC & "." & @MSEC)
EndFunc   ;==>Button1Click

Func Form1Close()
    GUIDelete()
    Exit
EndFunc   ;==>Form1Close

 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

  • 3 weeks later...

I use Koda to make the GUI but I'd like the code generated to be different do I put this together.
You may like the output too, so here it is.

ReformatKodaGuiSection()
Func ReformatKodaGuiSection($sScript = @ScriptFullPath)
    Local $c, $h, $p = "Pr" & "fx", $s, $g, $b, $n, $k = 0, $a = FileReadToArray($sScript)
    For $n = 0 To UBound($a) - 1
        If StringInStr($a[$n], "### START Koda " & "GUI section ###") Then
            $a[$n] &= @CRLF & @CRLF & '; *** change "' & $p & '" to your own prefix ( Ctrl + H from within SciTE ) ***' & @CRLF & @CRLF
            $k = $n
            ContinueLoop
        EndIf
        If Not $k Then ContinueLoop
        If StringInStr($a[$n], $p) Then
            ConsoleWrite('>'&$a[$n] &'<'& @CRLF)
            Return
        EndIf
        If StringInStr($a[$n], "### END Koda " & "GUI section ###") Then
            $a[$k - 1] = $a[$k - 1] & @CRLF & @CRLF & $g & @CRLF
            $a[$n - 1] &= @CRLF & 'EndFunc' & @CRLF
            $s = @CRLF & @CRLF & @CRLF
            $s &= '_' & $p & '_Main()' & @CRLF
            $s &= 'Func _' & $p & '_Main()' & @CRLF
            $s &= @TAB & 'Local $nMsg' & @CRLF
            $s &= @TAB & 'If Not $' & $p & '_Form1 Then _' & $p & '_Gui()' & @CRLF
            $s &= @TAB & 'While 1' & @CRLF
            $s &= @TAB & @TAB & '$nMsg = GUIGetMsg()' & @CRLF
            $s &= @TAB & @TAB & 'Switch $nMsg' & @CRLF
            $s &= @TAB & @TAB & @TAB & 'Case $GUI_EVENT_CLOSE' & @CRLF
            $s &= @TAB & @TAB & @TAB & @TAB & 'GUIDelete($' & $p & '_Form1)' & @CRLF
            $s &= @TAB & @TAB & @TAB & @TAB & '$' & $p & '_Form1 = 0' & @CRLF
            $s &= @TAB & @TAB & @TAB & @TAB & 'ExitLoop' & @CRLF & @CRLF
            $s &= $c
            $s &= @TAB & @TAB & 'EndSwitch' & @CRLF
            $s &= @TAB & 'WEnd' & @CRLF
            $s &= 'EndFunc' & @CRLF
            $a[$n] &= $s
            $k = 0
        EndIf
        If StringLeft(StringStripWS($a[$n], 3), 1) = "$" Then
            $b = StringSplit(StringStripWS($a[$n], 8), "=")
            $s = StringReplace($b[1], "$", "$" & $p & "_")
            If $g = "" Then
                $g &= 'Global ' & $s & ' = 0'
                If StringInStr($a[$n], "GUICreate(") Then ReformatKodaGuiSection_Titler($a, $n, $p, $k)
            Else
                $g &= ', ' & $s
            EndIf
            $a[$n] = StringReplace($a[$n], $b[1], $s)
            $c &= @TAB & @TAB & @TAB & 'Case ' & $s & @CRLF
            $c &= @TAB & @TAB & @TAB & @TAB & 'ConsoleWrite("- '& $s &'" & @CRLF)' & @CRLF & @CRLF
        EndIf
    Next
    $s = ""
    For $n = 0 To UBound($a) - 1
        If StringInStr($a[$n], "While 1") = 1 Then ExitLoop
        $s &= $a[$n] & @CRLF
    Next

    ConsoleWrite($s) ; ..to see the new file

;~  $h = FileOpen($sScript, 2) ; ..to overwrite this file
;~  Sleep(200) ; these delays are to give SciTE time to update the code,
;~  FileWrite($h, $s)
;~  FileClose($h)
;~  Sleep(500) ; or press "Ctrl + R" to reload the script

    Exit

EndFunc   ;==>ReformatKodaGuiSection

Func ReformatKodaGuiSection_Titler(ByRef $a, ByRef $n, ByRef $p, ByRef $k)
    Local $b = StringInStr($a[$n], '"', 0, 1)
    Local $e, $d, $c = StringInStr($a[$n], '"', 0, 1, $b + 1)
    $d = StringMid($a[$n], $b, $c - $b + 1)
    $e = '$' & $p & '_Title'
    $a[$n] = StringReplace($a[$n], $d, $e)
    $a[$k] &= @CRLF & '_' & $p & '_Gui()' & @CRLF & 'Func _' & $p & '_Gui('& $e &' = '& $d &')' ; Func _gSttgs_Gui($gSttg__s_Title = " Settings: Media Burn Aid")
EndFunc


; your Koda code goes down below

 

Edited by argumentum

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

Thanks @Deye

Little modified version:

; #FUNCTION# ====================================================================================================================
; Name ..........: _IsProcessWindowed
; Description ...: Check if Procces (specified by name) exist and is windowed
; Syntax ........: _IsProcessWindowed($sProcessName)
; Parameters ....: $sProcessName            - a string value. Process name to check
; Return values .: True / False
; Author ........: Deye
; Modified ......: mLipok
; Remarks .......:
; Related .......:
; Link ..........: https://www.autoitscript.com/forum/topic/139260-autoit-snippets/?do=findComment&comment=1422521
; Example .......: No
; ===============================================================================================================================
Func _IsProcessWindowed($sProcessName)
    Local $iPID = ProcessExists($sProcessName)
    If $iPID = 0 Then Return SetError(1, 1, False)

    _WinAPI_EnumProcessWindows($iPID)
    If @error Then Return SetError(@error, 2, False)
    Return True
EndFunc   ;==>_IsProcessWindowed

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

@Deye An useful snippet, I recommend accepting a PID instead of a process name since it is more accurate and flexible in terms of which process to target, your function could return undesireble results if multiple instances of the same process exist. Using a PID would solve the problem

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

Please use mLipok's Mod.

I posted that hastily as an idea , Didn't really test it through (mine doesn't work)

mLipok got to test it out and his works (Thanks to mLipok)

@TheDcoder ProcessExists()  will pick the latest used pid of the ProcessName (where GUI's trivially precede other pids for their process) so luckily the function matches this triviality
Unless a process (known as gui Based in name) but also generates other none gui pids
might get useful to find out where a pid belonging to a process precedes the gui one .. in some listening mod ...etc

Deye

Edited by Deye
Link to comment
Share on other sites

@TheDcoder

ProcessExists() accepts both. Helpfile: "The name or PID of the process to check."

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)

Link to comment
Share on other sites

@jchd Good point, I did not notice that ProcessExist was being used, just saw that the function accepted a string instead of the PID in the documentation.

@Deye  Yes, a matter of personal preference I guess... though most of the time in my scripts I do readily have the PID of the processes that I would want to automate the GUI for :)

The best course of action would be to just change the documentation to also include the fact about accepting PID :D

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

Func IsGui($h_Gui) ; if GUICreate() exists now
    If IsHWnd($h_Gui) Then Return $h_Gui
    Return 0
EndFunc   ;==>IsGui

Func IsCtrl($i_Ctrl) ; if GUICtrlCreateXxxxx() exists now
    If Not GUICtrlGetHandle($i_Ctrl) Then Return 0
    Return $i_Ctrl
EndFunc   ;==>IsCtrl

I found a need for these. May come in handy for you.

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

Like WinWaitClose but for windows that hide themselves instead of closing, if WinWaitClose doesn't work for you, then your should try this:

; $WIN_STATE_VISIBLE is stored in this include
#include <AutoItConstants.au3>

Func WinWaitHidden(ByRef $hWindow)
    While True
        Local $iState = WinGetState($hWindow)
        If Not BitAND($iState, $WIN_STATE_VISIBLE) Then Return
        Sleep(250)
    WEnd
EndFunc
Edited by TheDcoder

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

  • 1 month later...

Since Windows 7 and Server 2008 the function UpdateSystemParametersPerUser does not work in a stable way anymore, using USER32.DLL

They say It was an undocumented feature from the beginning...

If you want to make the scripted Desktop Wallpaper effective right away, you can use this Function to make it happen.

Func MakeWallpaperEffective()
;~  DllCall("user32.dll", "", "UpdatePerUserSystemParameters")  ; Obsolete
    Local $SPI_SETDESKWALLPAPER = 0x14
    Local $SPIF_UPDATEINIFILE = 0x1
    Local $SPIF_SENDCHANGE = 0x2
    DllCall("user32.dll", _
    "int", "SystemParametersInfo", _
    "int", $SPI_SETDESKWALLPAPER, _
    "int", 0, _
    "str", RegRead("HKCU\Control Panel\Desktop", "Wallpaper"), _
    "int", BitOR($SPIF_UPDATEINIFILE, $SPIF_SENDCHANGE))
EndFunc

 

Edited by DutchCoder
Link to comment
Share on other sites

  • 2 weeks later...
  • 3 weeks later...

Get the smallest and largest value of an array or list without directly comparing their values. This code is intentionally weird because it was part of a challenge.

#include <StringConstants.au3>

; #FUNCTION# ====================================================================================================================
; Name ..........: IntLenSort
; Description ...: Sorts out the Largest and Smallest value in an array or Data Seperated List
; Syntax ........: IntLenSort($vInput)
; Parameters ....: $vInput              - A 1D array or a GUIDataSeparatorChar seperated list
; Return values .: Lowest Value, Highest Value
; Author ........: Robert Maehl
; Modified ......: 6/10/2019
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func IntLenSort($vInput)

    If Not IsArray($vInput) Then $vInput = StringSplit($vInput, Opt("GUIDataSeparatorChar"), $STR_NOCOUNT)

    For $i = 0 To UBound($vInput) - 1 Step 1

        If $i = 0 Then
            Local $iHighest = $vInput[$i]
            Local $iLowest = $vInput[$i]
        EndIf

        If StringLen(String(10^$vInput[$i])) > StringLen(String(10^$iHighest)) Then
            If StringLeft(String(10^$vInput[$i]), 1) = "0" Then ; Negative Number
                ;;;
            Else
                $iHighest = $vInput[$i]
            EndIf
        EndIf

        If StringLen(String(10^$vInput[$i])) > StringLen(String(10^$iLowest)) Then
            If StringLeft(String(10^$vInput[$i]), 1) = "0" Then ; Negative Number
                $iLowest = $vInput[$i]
            Else
                ;;;
            EndIf
        EndIf

    Next

    Return $iLowest & ", " & $iHighest

EndFunc

 

Edited by rcmaehl

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...