Snippets ( AutoIt ): Difference between revisions

From AutoIt Wiki
Jump to navigation Jump to search
m (Added Template:Snippet Credit Header)
(Converted all snippets to the Template:Snippet Header)
Line 3: Line 3:
{{Snippet Credit Header}}
{{Snippet Credit Header}}


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' AutoItWinShow() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
{{Snippet Header|AutoItWinShow|35302-guinness|guinness|||1|AutoItCode=
<syntaxhighlight lang="autoit">
#include <GUIConstantsEx.au3>
#include <GUIConstantsEx.au3>


Line 10: Line 9:


Func Example()
Func Example()
     ; Display AutoIt's Hidden Window. See AutoItWinGetTitle and AutoItWinSetTitle for more details.
     ; Display AutoIt's Hidden Window. See AutoItWinGetTitle and AutoItWinSetTitle for more details.
     AutoItWinShow()
     AutoItWinShow()
Line 24: Line 22:
; Display AutoIt's Hidden Window. Returns the handle of the window.
; Display AutoIt's Hidden Window. Returns the handle of the window.
Func AutoItWinShow()
Func AutoItWinShow()
     Local $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window.
     Local Const $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window.
     WinMove($hWnd, '', (@DesktopWidth / 2) - 250, (@DesktopHeight / 2) - 250, 500, 500) ; Move the AutoIt Hidden Window and re-size for a better view of the data that will be set.
     WinMove($hWnd, '', (@DesktopWidth / 2) - 250, (@DesktopHeight / 2) - 250, 500, 500) ; Move the AutoIt Hidden Window and re-size for a better view of the data that will be set.
     WinSetState($hWnd, '', @SW_SHOW) ; Show the AutoIt Hidden Window, normally this is hidden, but in the interest of this example I'm displaying it.
     WinSetState($hWnd, '', @SW_SHOW) ; Show the AutoIt Hidden Window, normally this is hidden, but in the interest of this example I'm displaying it.
     Return $hWnd
     Return $hWnd
EndFunc  ;==>AutoItWinShow
EndFunc  ;==>AutoItWinShow
</syntaxhighlight>
}}
[[#top|Return To Contents]]
 
===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' AutoItWinGetText() & AutoItWinSetText() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
<syntaxhighlight lang="autoit">
#include <GUIConstantsEx.au3>


{{Snippet Header|AutoItWinGetText|35302-guinness|guinness|||1|AutoItCode=
Example()
Example()


Func Example()
Func Example()
     ; Display AutoIt's Hidden Window. See AutoItWinGetTitle and AutoItWinSetTitle for more details.
     ; Display AutoIt's Hidden Window. See AutoItWinGetTitle and AutoItWinSetTitle for more details.
     AutoItWinShow()
     AutoItWinShow()
Line 62: Line 55:
; Retrieve the text in AutoIt's Hidden Window.
; Retrieve the text in AutoIt's Hidden Window.
Func AutoItWinGetText()
Func AutoItWinGetText()
     Local $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window.
     Local Const $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window.
     Return ControlGetText($hWnd, '', ControlGetHandle($hWnd, '', 'Edit1'))
     Return ControlGetText($hWnd, '', ControlGetHandle($hWnd, '', 'Edit1'))
EndFunc  ;==>AutoItWinGetText
EndFunc  ;==>AutoItWinGetText
Line 68: Line 61:
; Add text to AutoIt's Hidden Window.
; Add text to AutoIt's Hidden Window.
Func AutoItWinSetText($sString)
Func AutoItWinSetText($sString)
     Local $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window.
     Local Const $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window.
     Return ControlSetText($hWnd, "", ControlGetHandle($hWnd, "", 'Edit1'), ControlGetText($hWnd, '', ControlGetHandle($hWnd, '', 'Edit1')) & $sString)
     Return ControlSetText($hWnd, "", ControlGetHandle($hWnd, "", 'Edit1'), ControlGetText($hWnd, '', ControlGetHandle($hWnd, '', 'Edit1')) & $sString)
EndFunc  ;==>AutoItWinSetText
EndFunc  ;==>AutoItWinSetText
Line 74: Line 67:
; Display AutoIt's Hidden Window. Returns the handle of the window.
; Display AutoIt's Hidden Window. Returns the handle of the window.
Func AutoItWinShow()
Func AutoItWinShow()
     Local $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window.
     Local Const $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window.
     WinMove($hWnd, '', (@DesktopWidth / 2) - 250, (@DesktopHeight / 2) - 250, 500, 500) ; Move the AutoIt Hidden Window and re-size for a better view of the data that will be set.
     WinMove($hWnd, '', (@DesktopWidth / 2) - 250, (@DesktopHeight / 2) - 250, 500, 500) ; Move the AutoIt Hidden Window and re-size for a better view of the data that will be set.
     WinSetState($hWnd, '', @SW_SHOW) ; Show the AutoIt Hidden Window, normally this is hidden, but in the interest of this example I'm displaying it.
     WinSetState($hWnd, '', @SW_SHOW) ; Show the AutoIt Hidden Window, normally this is hidden, but in the interest of this example I'm displaying it.
     Return $hWnd
     Return $hWnd
EndFunc  ;==>AutoItWinShow
EndFunc  ;==>AutoItWinShow
</syntaxhighlight>
}}
[[#top|Return To Contents]]
 
===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _DockToWindow()() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
<syntaxhighlight lang="autoit">


{{Snippet Header|_DockToWindow|35302-guinness|guinness|||1|AutoItCode=
#include <GUIConstantsEx.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <WindowsConstants.au3>


If (Not ProcessExists('SciTE.exe')) Then
If (Not ProcessExists("SciTE.exe")) Then
     Exit MsgBox(4096, '', 'Please start SciTE.exe')
     Exit MsgBox(4096, '', "Please start SciTE.exe")
EndIf
EndIf
Example()
Example()


Func Example()
Func Example()
     ; Create a GUI, similar to SciTE Jump's GUI.
     ; Create a GUI, similar to SciTE Jump's GUI.
     Local $hGUI = GUICreate('', 215, 400, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))
     Local Const $hGUI = GUICreate('', 215, 400, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))
     GUISetState(@SW_SHOW, $hGUI)
 
     GUISetState(@SW_SHOWNORMAL, $hGUI)


     ; Dock the first window to left and adjust the width based on the width of the second GUI.
     ; Dock the first window to left and adjust the width based on the width of the second GUI.
     _DockToWindow(WinGetHandle('[CLASS:SciTEWindow]'), $hGUI)
     _DockToWindow(WinGetHandle("[CLASS:SciTEWindow]"), $hGUI)


     While 1
     While 1
Line 108: Line 100:
         EndSwitch
         EndSwitch
     WEnd
     WEnd
     GUIDelete($hGUI)
     GUIDelete($hGUI)
EndFunc  ;==>Example
EndFunc  ;==>Example


Func _DockToWindow($hHandle_1, $hHandle_2)
Func _DockToWindow(Const $hHandle_1, Const $hHandle_2)
     ; Retrieve the working area, this is minus the taskbar dimensions so slightly different to @DesktopHeight and @DesktopWidth which is the
     ; Retrieve the working area, this is minus the taskbar dimensions so slightly different to @DesktopHeight and @DesktopWidth which is the
     ; monitors height and width.
     ; monitors height and width.
     Local Const $SPI_GETWORKAREA = 48
     Local Const $SPI_GETWORKAREA = 48
     Local $tWorkArea = DllStructCreate($tagRECT)
     Local Const $tWorkArea = DllStructCreate($tagRECT)
     _WinAPI_SystemParametersInfo($SPI_GETWORKAREA, 0, DllStructGetPtr($tWorkArea))
     _WinAPI_SystemParametersInfo($SPI_GETWORKAREA, 0, DllStructGetPtr($tWorkArea))


     ; Retieve the position of the second GUI.
     ; Retieve the position of the second GUI.
     Local $aClientSize_2 = WinGetPos($hHandle_2)
     Local Const $aClientSize_2 = WinGetPos($hHandle_2)


     ; Set the state of the windows to 'Restore'.
     ; Set the state of the windows to 'Restore'.
Line 131: Line 124:
     WinMove($hHandle_2, '', DllStructGetData($tWorkArea, 'Right') - DllStructGetData($tWorkArea, 'Left') - $aClientSize_2[2], DllStructGetData($tWorkArea, 'Top'), $aClientSize_2[2], DllStructGetData($tWorkArea, 'Bottom') - DllStructGetData($tWorkArea, 'Top'))
     WinMove($hHandle_2, '', DllStructGetData($tWorkArea, 'Right') - DllStructGetData($tWorkArea, 'Left') - $aClientSize_2[2], DllStructGetData($tWorkArea, 'Top'), $aClientSize_2[2], DllStructGetData($tWorkArea, 'Bottom') - DllStructGetData($tWorkArea, 'Top'))
EndFunc  ;==>_DockToWindow
EndFunc  ;==>_DockToWindow
</syntaxhighlight>
}}
[[#top|Return To Contents]]


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _FuncExists() ~ Author - [http://www.autoitscript.com/forum/user/52-geosoft/ GEOSoft] '''</blockquote> =====
{{Snippet Header|_FuncExists|52-geosoft|GEOSoft|||1|AutoItCode=
<syntaxhighlight lang="autoit">
MsgBox(0, "TEST", "Function Exists = " & _FuncExists("_FuncExists", @ScriptFullPath))
MsgBox(0, "TEST", "Function Exists = " & _FuncExists("_FuncExists", @ScriptFullPath))


Func _FuncExists($sFunc, $sPath)
Func _FuncExists($sFunc, $sPath)
   If NOT FileExists($sPath) Then Return SetError(1)
   If Not FileExists($sPath) Then Return SetError(1)
   Local $sStr = FileRead($sPath)
   Local Const $sStr = FileRead($sPath)
   Local $sRegEx = "(?i)(?m:^|\n)\s*Func\s+(" & $sFunc & ")\s*\("
   Local Const $sRegEx = "(?i)(?m:^|\n)\s*Func\s+(" & $sFunc & ")\s*\("
   Local $aRegEx = StringRegExp($sStr, $sRegEx, 1)
   Local Const $aRegEx = StringRegExp($sStr, $sRegEx, 1)
   If IsArray($aRegEx) Then Return 1
   If IsArray($aRegEx) Then Return 1
   Return 0
   Return 0
EndFunc
EndFunc
</syntaxhighlight>
}}
[[#top|Return To Contents]]
 
===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _FunctionSort() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====


<syntaxhighlight lang="autoit">
{{Snippet Header|_FunctionSort|35302-guinness|guinness|||1|AutoItCode=
; Get the list of Functions in a script and sort by alphabetical order.
; Get the list of Functions in a script and sort by alphabetical order.


#include <Array.au3>
#include <Array.au3>
Line 158: Line 146:


Local $sFile = FileOpenDialog(@ScriptName, "Select an AutoIt file.", "Au3 (*.au3)")
Local $sFile = FileOpenDialog(@ScriptName, "Select an AutoIt file.", "Au3 (*.au3)")
If @error Then
If @error Then
     Exit
     Exit
Line 164: Line 153:


Func _FunctionSort($sFilePath)
Func _FunctionSort($sFilePath)
     Local $aReturn, $sRead, $sReturn
     Local Const $sRead = FileRead($sFilePath)
 
Local $aReturn = StringRegExp("Func _Count()" & @CRLF & "EndFunc ;==>_Count" & $sRead, '(?s)(?i)Func(.*?)EndFunc', 3)


    $sRead = FileRead($sFilePath)
    $aReturn = StringRegExp("Func _Count()" & @CRLF & "EndFunc ;==>_Count" & $sRead, '(?s)(?i)Func(.*?)EndFunc', 3)
     If @error Then
     If @error Then
         Return SetError(1, 0, 0)
         Return SetError(1, 0, 0)
     EndIf
     EndIf
     $aReturn[0] = UBound($aReturn, 1) - 1
     $aReturn[0] = UBound($aReturn, 1) - 1
     _ArraySort($aReturn, 0, 1)
     _ArraySort($aReturn, 0, 1)
    Local $sReturn
     For $A = 1 To $aReturn[0]
     For $A = 1 To $aReturn[0]
         $sReturn &= "Func" & $aReturn[$A] & "EndFunc" & @CRLF & @CRLF
         $sReturn &= "Func" & $aReturn[$A] & "EndFunc" & @CRLF & @CRLF
     Next
     Next
     Return $sReturn
     Return $sReturn
EndFunc  ;==>_FunctionSort
EndFunc  ;==>_FunctionSort
</syntaxhighlight>
}}
[[#top|Return To Contents]]


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _IsButton() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
{{Snippet Header|_IsButton|35302-guinness|guinness|||1|AutoItCode=
<syntaxhighlight lang="autoit">
#include <ButtonConstants.au3>
#include <ButtonConstants.au3>
#include <Constants.au3>
#include <Constants.au3>
Line 190: Line 183:


Func Example()
Func Example()
     Local $hGUI = GUICreate('')
     Local Const $hGUI = GUICreate('')
     Local $iLabel = GUICtrlCreateButton('', 0, 0, 50, 50)
     Local Const $iLabel = GUICtrlCreateButton('', 0, 0, 50, 50)
     Local $iCheckbox = GUICtrlCreateCheckbox('', 0, 0, 100, 20) ; This is considered a 'Button' by _WinAPI_GetClassName too.
     Local Const $iCheckbox = GUICtrlCreateCheckbox('', 0, 0, 100, 20) ; This is considered a 'Button' by _WinAPI_GetClassName too.
     GUISetState(@SW_SHOW, $hGUI)
 
     GUISetState(@SW_SHOWNORMAL, $hGUI)


     MsgBox(4096, '', 'AutoIt Button ID: ' & _IsButton($iLabel) & @CRLF & _
     MsgBox(4096, '', 'AutoIt Button ID: ' & _IsButton($iLabel) & @CRLF & _
Line 208: Line 202:
         $hWnd = GUICtrlGetHandle($hWnd)
         $hWnd = GUICtrlGetHandle($hWnd)
     EndIf
     EndIf
     Local $sClassName = _WinAPI_GetClassName($hWnd)
 
     Local Const $sClassName = _WinAPI_GetClassName($hWnd)
 
     If $sClassName = 'Button' Then
     If $sClassName = 'Button' Then
         Local $aStyle[5] = [4, $BS_CHECKBOX, $BS_AUTOCHECKBOX, $BS_RADIOBUTTON, $BS_AUTORADIOBUTTON]
         Local Const $aStyle[5] = [4, $BS_CHECKBOX, $BS_AUTOCHECKBOX, $BS_RADIOBUTTON, $BS_AUTORADIOBUTTON]
         Local $iLong = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE)
 
        For $i = 1 To $aStyle[0]
         Local Const $iLong = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE)
 
For $i = 1 To $aStyle[0]
             If BitAND($iLong, $aStyle[$i]) = $aStyle[$i] Then
             If BitAND($iLong, $aStyle[$i]) = $aStyle[$i] Then
                 Return False
                 Return False
             EndIf
             EndIf
         Next
         Next
         Return True
         Return True
     EndIf
     EndIf
     Return False
     Return False
EndFunc  ;==>_IsButton
EndFunc  ;==>_IsButton
</syntaxhighlight>
}}
[[#top|Return To Contents]]
 
===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _IsControlID() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====


<syntaxhighlight lang="autoit">
{{Snippet Header|_IsControlID|35302-guinness|guinness|||1|AutoItCode=
; Check if a Control ID is a native AutoIt control.
; Check if a Control ID is a native AutoIt control.


Line 235: Line 232:


Func Example()
Func Example()
     Local $hGUI = GUICreate('')
     Local Const $hGUI = GUICreate('')
     Local $iControlID = GUICtrlCreateLabel('', 0, 0, 500, 500)
     Local Const $iControlID = GUICtrlCreateLabel('', 0, 0, 500, 500)
     Local $hListView = _GUICtrlListView_Create($hGUI, 'Example', 0, 0, 500, 500)
     Local Const $hListView = _GUICtrlListView_Create($hGUI, 'Example', 0, 0, 500, 500)
    GUISetState(@SW_SHOW, $hGUI)
 
GUISetState(@SW_SHOWNORMAL, $hGUI)


     MsgBox(4096, '', 'AutoIt ControlID: ' & _IsControlID($iControlID) & @CRLF & _
     MsgBox(4096, '', 'AutoIt ControlID: ' & _IsControlID($iControlID) & @CRLF & _
Line 247: Line 245:


     _GUICtrlListView_Destroy($hListView)
     _GUICtrlListView_Destroy($hListView)
     Return GUIDelete($hGUI)
     Return GUIDelete($hGUI)
EndFunc  ;==>Example
EndFunc  ;==>Example
Line 254: Line 253:
         $iControlID = _WinAPI_GetDlgCtrlID($iControlID)
         $iControlID = _WinAPI_GetDlgCtrlID($iControlID)
     EndIf
     EndIf
     Return IsHWnd(GUICtrlGetHandle($iControlID)) = 1
     Return IsHWnd(GUICtrlGetHandle($iControlID)) = 1
EndFunc  ;==>_IsControlID
EndFunc  ;==>_IsControlID
</syntaxhighlight>
}}
[[#top|Return To Contents]]


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">'''  _GetAutoItIncludesFromSciTE() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
{{Snippet Header|_GetAutoItIncludesFromSciTE|35302-guinness|guinness|||1|AutoItCode=
 
<syntaxhighlight lang="autoit">
#include <WinAPIEx.au3>
#include <WinAPIEx.au3>


Line 268: Line 265:
; Retrieve the AutoIt includes path from the SciTE process.
; Retrieve the AutoIt includes path from the SciTE process.
Func _GetAutoItIncludesFromSciTE()
Func _GetAutoItIncludesFromSciTE()
     Local $sRelativePath = '..\Include', $sWorkingDir = @WorkingDir
     Local $sRelativePath = '..\Include'
     FileChangeDir( _WinAPI_PathRemoveFileSpec(_WinAPI_GetProcessFileName(ProcessExists('SciTE.exe'))))
Local Const $sWorkingDir = @WorkingDir
     FileChangeDir(_WinAPI_PathRemoveFileSpec(_WinAPI_GetProcessFileName(ProcessExists('SciTE.exe'))))
     $sRelativePath = _WinAPI_GetFullPathName($sRelativePath)
     $sRelativePath = _WinAPI_GetFullPathName($sRelativePath)
     FileChangeDir($sWorkingDir)
     FileChangeDir($sWorkingDir)
     Return _WinAPI_PathRemoveBackslash($sRelativePath)
     Return _WinAPI_PathRemoveBackslash($sRelativePath)
EndFunc  ;==>_GetAutoItIncludesFromSciTE
EndFunc  ;==>_GetAutoItIncludesFromSciTE
</syntaxhighlight>
}}
[[#top|Return To Contents]]


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _GetAutoItInstall() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
{{Snippet Header|_GetAutoItInstall|35302-guinness|guinness|||1|AutoItCode=
 
<syntaxhighlight lang="autoit">
; Get the AutoIt installation folder.
; Get the AutoIt installation folder.


Line 287: Line 282:
     Return StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 2, -1) - 1)
     Return StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 2, -1) - 1)
EndFunc  ;==>_GetAutoItInstall
EndFunc  ;==>_GetAutoItInstall
</syntaxhighlight>
}}
[[#top|Return To Contents]]
 
===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">'''  _GetAutoItInstallEx() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====


<syntaxhighlight lang="autoit">
{{Snippet Header|_GetAutoItInstallEx|35302-guinness|guinness|||1|AutoItCode=
ConsoleWrite(_GetAutoItInstallEx() & @CRLF)
ConsoleWrite(_GetAutoItInstallEx() & @CRLF)


Line 311: Line 303:
     EndIf
     EndIf
EndFunc  ;==>_GetAutoItInstallEx
EndFunc  ;==>_GetAutoItInstallEx
</syntaxhighlight>
}}
[[#top|Return To Contents]]
 
===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">'''  _GetAutoItInstallFromSciTE() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====


<syntaxhighlight lang="autoit">
{{Snippet Header|_GetAutoItInstallFromSciTE|35302-guinness|guinness|||1|AutoItCode=
ConsoleWrite(_GetAutoItInstallFromSciTE() & @CRLF)
ConsoleWrite(_GetAutoItInstallFromSciTE() & @CRLF)


Line 327: Line 316:
     Return _WinAPI_PathRemoveBackslash($sRelativePath)
     Return _WinAPI_PathRemoveBackslash($sRelativePath)
EndFunc  ;==>_GetAutoItInstallFromSciTE
EndFunc  ;==>_GetAutoItInstallFromSciTE
</syntaxhighlight>
}}
[[#top|Return To Contents]]


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _GetClasses() ~ Author - [http://www.autoitscript.com/forum/user/24-cyberslug/ CyberSlug] '''</blockquote> =====
{{Snippet Header|_GetClasses|24-cyberslug|CyberSlug|||1|AutoItCode=
 
<syntaxhighlight lang="autoit">
; Get ALL Controls Info
; Get ALL Controls Info


Line 342: Line 328:


; Wait 10 seconds for the Calculator window to appear.
; Wait 10 seconds for the Calculator window to appear.
Local $hWnd = WinWait("[CLASS:CalcFrame]", "", 10)
Local const $hWnd = WinWait("[CLASS:CalcFrame]", '', 10)


; Retrieve a list of all the controls in the Calculator window using the handle returned by WinWait.
; Retrieve a list of all the controls in the Calculator window using the handle returned by WinWait.
MsgBox(4096, "", _GetClasses($hWnd))
MsgBox(4096, '', _GetClasses($hWnd))


; Close the Calculator window using the handle returned by WinWait.
; Close the Calculator window using the handle returned by WinWait.
Line 358: Line 344:


For $i = 1 To $aClasses[0]
For $i = 1 To $aClasses[0]
Select
Switch
Case $aClasses[$i] = "Button"
Case $aClasses[$i] = "Button"
$iCount_Button += 1
$iCount_Button += 1
Line 377: Line 363:
Next
Next


; Coombine the results.
; Combine the results.
Local $sReturn = ""
Local $sReturn = ""
For $i = 1 To $aClassID[0]
For $i = 1 To $aClassID[0]
$sReturn &= $aClassID[$i] & @LF
$sReturn &= $aClassID[$i] & @LF
Next
Next
Return $sReturn
Return $sReturn
EndFunc  ;==>_GetClasses
EndFunc  ;==>_GetClasses
</syntaxhighlight>
}}
[[#top|Return To Contents]]
 
===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _GetFile() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====


<syntaxhighlight lang="autoit">
{{Snippet Header|_GetFile|35302-guinness|guinness|||1|AutoItCode=
; FileRead Alternative
; FileRead Alternative


Line 401: Line 386:
     Return $sData
     Return $sData
EndFunc  ;==>_GetFile
EndFunc  ;==>_GetFile
</syntaxhighlight>
}}
[[#top|Return To Contents]]
 
===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _GetTitle() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====


<syntaxhighlight lang="autoit">
{{Snippet Header|_GetTitle|35302-guinness|guinness|||1|AutoItCode=
; Get the title of your program.
; Get the title of your program.


Line 417: Line 399:
     Return $sProgramName & $aOSArch[@AutoItX64] & $aPortable[FileExists($sInstallPath)]
     Return $sProgramName & $aOSArch[@AutoItX64] & $aPortable[FileExists($sInstallPath)]
EndFunc  ;==>_GetTitle
EndFunc  ;==>_GetTitle
</syntaxhighlight>
}}
[[#top|Return To Contents]]
 
===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _GetXML() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====


<syntaxhighlight lang="autoit">
{{Snippet Header|_GetXML|35302-guinness|guinness|||1|AutoItCode=
; Simple Way Of Parsing XML Data.
; Simple Way Of Parsing XML Data.


Line 442: Line 421:
     Return SetError(0, 0, $aReturn)
     Return SetError(0, 0, $aReturn)
EndFunc  ;==>_GetXML
EndFunc  ;==>_GetXML
</syntaxhighlight>
}}
[[#top|Return To Contents]]


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' Include Source With Exe ~ Author - [http://www.autoitscript.com/forum/user/54985-jlogan3o13/ JLogan3o13] '''</blockquote> =====
{{Snippet Header|Include Source With Exe|54985-jlogan3o13|JLogan3o13|||1|AutoItCode=
<syntaxhighlight lang="autoit">
;recover source .au3 file with /Extract switch
;recover source .au3 file with /Extract switch
; The above code would be copied into the top of your script. The source location (C:\Test.au3 in my example) is the full path to your script file.  
; The above code would be copied into the top of your script. The source location (C:\Test.au3 in my example) is the full path to your script file.
;Once compiled, if you run the script from the Run line with the /Extract switch, it will extact the original .au3 file into the Temp directory and will exit without actually executing the script.
;Once compiled, if you run the script from the Run line with the /Extract switch, it will extact the original .au3 file into the Temp directory and will exit without actually executing the script.
If StringInStr($cmdlineRaw, "/Extract") Then
If StringInStr($cmdlineRaw, "/Extract") Then
    FileInstall("C:\Test.au3", @TempDir & "\Test.au3", 1)
FileInstall("C:\Test.au3", @TempDir & "\Test.au3", 1)
Exit
Exit
EndIf
EndIf
</syntaxhighlight>
}}
[[#top|Return To Contents]]


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _IsANSIFile() & _IsUnicodeFile() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
{{Snippet Header|_IsANSIFile|35302-guinness|guinness|||1|AutoItCode=
 
<syntaxhighlight lang="autoit">
#include <FileConstants.au3>
#include <FileConstants.au3>


ConsoleWrite(_IsANSIFile(@ScriptFullPath) & @LF) ; Returns True.
ConsoleWrite(_IsANSIFile(@ScriptFullPath) & @LF) ; Returns True.
ConsoleWrite(_IsUnicodeFile(@ScriptFullPath) & @LF) ; Returns False.


Func _IsANSIFile($sFilePath)
Func _IsANSIFile($sFilePath)
     Return FileGetEncoding($sFilePath) = $FO_READ
     Return FileGetEncoding($sFilePath) = $FO_READ
EndFunc  ;==>_IsUnicodeFile
EndFunc  ;==>_IsUnicodeFile
}}
{{Snippet Header|_IsUnicodeFile|35302-guinness|guinness|||1|AutoItCode=
#include <FileConstants.au3>
ConsoleWrite(_IsUnicodeFile(@ScriptFullPath) & @LF) ; Returns False.


Func _IsUnicodeFile($sFilePath)
Func _IsUnicodeFile($sFilePath)
     Return FileGetEncoding($sFilePath) = $FO_UNICODE
     Return FileGetEncoding($sFilePath) = $FO_UNICODE
EndFunc  ;==>_IsUnicodeFile
EndFunc  ;==>_IsUnicodeFile
</syntaxhighlight>
}}
[[#top|Return To Contents]]
 
===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">'''  _IsAu3File() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====


<syntaxhighlight lang="autoit">
{{Snippet Header|_IsAu3File|35302-guinness|guinness|||1|AutoItCode=
ConsoleWrite(_IsAu3File(@AutoItExe) & @CRLF)
ConsoleWrite(_IsAu3File(@AutoItExe) & @CRLF)
ConsoleWrite(_IsAu3File(@ScriptFullPath) & @CRLF)
ConsoleWrite(_IsAu3File(@ScriptFullPath) & @CRLF)
Line 486: Line 461:
     Return StringTrimLeft($sFilePath, StringInStr($sFilePath, ".", 2, -1)) = "au3"
     Return StringTrimLeft($sFilePath, StringInStr($sFilePath, ".", 2, -1)) = "au3"
EndFunc  ;==>_IsAu3File
EndFunc  ;==>_IsAu3File
</syntaxhighlight>
}}
[[#top|Return To Contents]]


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _IsDefault() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
{{Snippet Header|_IsDefault|35302-guinness|guinness|||1|AutoItCode=
 
<syntaxhighlight lang="autoit">
If _IsDefault(Default) Then
If _IsDefault(Default) Then
     MsgBox(0, "_IsDefault() - 1", "This was a Default variable.")
     MsgBox(0, "_IsDefault() - 1", "This was a Default variable.")
Line 507: Line 479:
     Return StringRegExp($sDefault, "(?-i)\s|Default|-1|0")
     Return StringRegExp($sDefault, "(?-i)\s|Default|-1|0")
EndFunc  ;==>_IsDefault
EndFunc  ;==>_IsDefault
</syntaxhighlight>
}}
[[#top|Return To Contents]]


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _IsInTrial() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
{{Snippet Header|_IsInTrial|35302-guinness|guinness|||1|AutoItCode=
 
<syntaxhighlight lang="autoit">
#include <Date.au3> ; Required for _DateDiff()
#include <Date.au3> ; Required for _DateDiff()


Line 524: Line 493:
     Return (_DateDiff('D', $sDateString, @YEAR & '/' & @MON & '/' & @MDAY) < $iDays)
     Return (_DateDiff('D', $sDateString, @YEAR & '/' & @MON & '/' & @MDAY) < $iDays)
EndFunc  ;==>_IsInTrial
EndFunc  ;==>_IsInTrial
</syntaxhighlight>
}}
[[#top|Return To Contents]]


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _IsVisible() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
{{Snippet Header|_IsVisible|35302-guinness|guinness|||1|AutoItCode=
 
<syntaxhighlight lang="autoit">
; Check if the Notepad Window is visible.
; Check if the Notepad Window is visible.


Line 556: Line 522:
     Return BitAND(WinGetState($hWnd), 2) = 2
     Return BitAND(WinGetState($hWnd), 2) = 2
EndFunc  ;==>_IsVisible
EndFunc  ;==>_IsVisible
</syntaxhighlight>
}}
[[#top|Return To Contents]]


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' Open help file to desired page ~ Author - [http://www.autoitscript.com/forum/user/1967-garyfrost/ GaryFrost] '''</blockquote> =====
{{Snippet Header|Open help file to desired page|1967-garyfrost|GaryFrost|||1|AutoItCode=
 
<syntaxhighlight lang="autoit">
; Open help file / Open a desired page
; Open help file / Open a desired page


Local $sAutoItPath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir")
Global Const $sAutoItPath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir")


Run(@WindowsDir & "\hh.exe " & $sAutoItPath & "\AutoIt3.chm::/html/functions/GUICtrlCreateUpdown.htm")
Run(@WindowsDir & "\hh.exe " & $sAutoItPath & "\AutoIt3.chm::/html/functions/GUICtrlCreateUpdown.htm")
</syntaxhighlight>
}}
[[#top|Return To Contents]]


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _RunAU3() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
{{Snippet Header|_RunAU3|35302-guinness|guinness|||1|AutoItCode=
 
<syntaxhighlight lang="autoit">
_RunAU3("AU3_Example.txt", '"This is a commandline example!"')
_RunAU3("AU3_Example.txt", '"This is a commandline example!"')


Line 587: Line 547:
     Return $iPID
     Return $iPID
EndFunc  ;==>_RunWaitAU3
EndFunc  ;==>_RunWaitAU3
</syntaxhighlight>
}}
[[#top|Return To Contents]]


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' Run Any Au3 File From Your Program ~ Author - [http://www.autoitscript.com/forum/user/4920-valuater/ Valuater] '''</blockquote> =====
{{Snippet Header|Run Any Au3 File From Your Program|4920-valuater|Valuater|||1|AutoItCode=
 
<syntaxhighlight lang="autoit">
; Run Any Au3 File From Your Program
; Run Any Au3 File From Your Program


Local $sFilePath = @ScriptDir & "\Test.au3"
Global Const $sFilePath = @ScriptDir & "\Test.au3"


If @Compiled Then
If @Compiled Then
Local $sFileExe = FileGetShortName(@AutoItExe & ' /AutoIt3ExecuteScript "' & $sFilePath & '"')
Global Const $sFileExe = FileGetShortName(@AutoItExe & ' /AutoIt3ExecuteScript "' & $sFilePath & '"')
Run($sFileExe)
Run($sFileExe)
Else
Else
Local $sFileAu3 = FileGetShortName($sFilePath)
Global Const $sFileAu3 = FileGetShortName($sFilePath)
Run(@AutoItExe & " " & $sFileAu3, "", @SW_HIDE)
Run(@AutoItExe & " " & $sFileAu3, "", @SW_HIDE)
EndIf
EndIf
</syntaxhighlight>
}}
[[#top|Return To Contents]]
 
===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _ScriptName() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====


<syntaxhighlight lang="autoit">
{{Snippet Header|_ScriptName|35302-guinness|guinness|||1|AutoItCode=
ConsoleWrite(_ScriptName() & @CRLF)
ConsoleWrite(_ScriptName() & @CRLF)


Line 616: Line 570:
Return StringLeft(@ScriptName, StringInStr(@ScriptName, '.', 2, -1) - 1)
Return StringLeft(@ScriptName, StringInStr(@ScriptName, '.', 2, -1) - 1)
EndFunc  ;==>_ScriptName
EndFunc  ;==>_ScriptName
</syntaxhighlight>
}}
[[#top|Return To Contents]]


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _ScriptVersion() ~ Author - [http://www.autoitscript.com/forum/user/31149-milesahead/ MilesAhead] '''</blockquote> =====
{{Snippet Header|_ScriptVersion|31149-milesahead|MilesAhead|||1|AutoItCode=
<syntaxhighlight lang="autoit">
#NoTrayIcon
#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_UseUpx=n
Line 629: Line 582:
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
Global $version = _ScriptVersion()
Global $version = _ScriptVersion()


Global $msg = "ScriptVerDemo" & " " & $version & "  Copyright (c) 2012  www.favessoft.com" & @CRLF & @CRLF
Global $msg = "ScriptVerDemo" & " " & $version & "  Copyright (c) 2012  www.favessoft.com" & @CRLF & @CRLF
MsgBox(0x1040, "", $msg)
MsgBox(0x1040, "", $msg)


;return File Version string from compiled or .au3 script
; return File Version string from compiled or .au3 script
;returns "" if no version info available
; returns "" if no version info available
; Note: The .au3 script must contain #AutoItWrapper
; Note: The .au3 script must contain #AutoItWrapper
; directives with file version or "" is returned.
; directives with file version or "" is returned.
;
Func _ScriptVersion(Const $Script = @ScriptFullPath)
Func _ScriptVersion($Script = @ScriptFullPath)
    Local $ver = "", $scriptHandle = -1, $found = False, $sPos = 0
     If StringRight($Script,4) = ".exe" Then
     If StringRight($Script,4) = ".exe" Then
         Return FileGetVersion($Script)
         Return FileGetVersion($Script)
     Else
     Else
         $scriptHandle = FileOpen($Script)
         Local Const $scriptHandle = FileOpen($Script)
Local $ver
Local $found = False
Local $pos
 
         If $scriptHandle <> -1 Then
         If $scriptHandle <> -1 Then
             Do
             Do
                 $ver = FileReadLine($scriptHandle)
                 $ver = FileReadLine($scriptHandle)
                 $sPos = StringInStr($ver, "_Fileversion=")
                 $sPos = StringInStr($ver, "_Fileversion=")
                 If $sPos Then
                 If $sPos Then
                     $ver = StringMid($ver, $sPos + StringLen("_Fileversion="))
                     $ver = StringMid($ver, $sPos + StringLen("_Fileversion="))
Line 655: Line 613:
                 EndIf
                 EndIf
             Until StringLeft($ver, 1) <> "#"
             Until StringLeft($ver, 1) <> "#"
             FileClose($scriptHandle)
             FileClose($scriptHandle)
         EndIf
         EndIf
     EndIf
     EndIf
     If Not $found Then $ver = ""
     If Not $found Then $ver = ""
     Return $ver
     Return $ver
EndFunc  ;==>_ScriptVersion
EndFunc  ;==>_ScriptVersion
</syntaxhighlight>
}}
[[#top|Return To Contents]]


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _SetFile() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
{{Snippet Header|_SetFile|35302-guinness|guinness|||1|AutoItCode=
; FileWrite Alternative


<syntaxhighlight lang="autoit">
Func _SetFile(Const $sString, Const $sFile, Const $iOverwrite = 0)
; FileWrite Alternative
    Local Const $hFileOpen = FileOpen($sFile, $iOverwrite + 1)


Func _SetFile($sString, $sFile, $iOverwrite = 0)
    Local $hFileOpen = FileOpen($sFile, $iOverwrite + 1)
     FileWrite($hFileOpen, $sString)
     FileWrite($hFileOpen, $sString)
     FileClose($hFileOpen)
     FileClose($hFileOpen)
     If @error Then
     If @error Then
         Return SetError(1, 0, $sString)
         Return SetError(1, 0, $sString)
     EndIf
     EndIf
     Return $sString
     Return $sString
EndFunc  ;==>_SetFile
EndFunc  ;==>_SetFile
</syntaxhighlight>
}}
[[#top|Return To Contents]]
 
===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _ShowHelp() ~ Author - [http://www.autoitscript.com/forum/user/60350-chimaera/ Chimaera] '''</blockquote> =====


<syntaxhighlight lang="autoit">
{{Snippet Header|_ShowHelp|60350-chimaera|Chimaera|||1|AutoItCode=
HotKeySet("{F1}", "_ShowHelp")
HotKeySet("{F1}", "_ShowHelp")


Func _ShowHelp()
Func _ShowHelp()
Return ShellExecute(@ProgramFilesDir & "\AutoIt3\AutoIt3Help.exe"); change this to the location of your own helpfile.
Return ShellExecute(@ProgramFilesDir & "\AutoIt3\AutoIt3Help.exe") ; change this to the location of your own helpfile.
EndFunc  ;==>_ShowHelp
EndFunc  ;==>_ShowHelp
</syntaxhighlight>
}}
[[#top|Return To Contents]]


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _SingletonPID() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
{{Snippet Header|_SingletonPID|35302-guinness|guinness|||1|AutoItCode=
<syntaxhighlight lang="autoit">
Local $iSingleton = _SingletonPID('RandomName', 1)
Local $iSingleton = _SingletonPID('RandomName', 1)


Line 715: Line 671:
; Example .......: Yes
; Example .......: Yes
; ===============================================================================================================================
; ===============================================================================================================================
Func _SingletonPID($sOccurenceName, $iFlag = 0)
Func _SingletonPID(Const $sOccurenceName, Const $iFlag = 0)
     Local $hHandle = WinGetHandle($sOccurenceName)
     Local $hHandle = WinGetHandle($sOccurenceName)
     If @error Then
     If @error Then
         AutoItWinSetTitle($sOccurenceName)
         AutoItWinSetTitle($sOccurenceName)
Line 728: Line 685:
         EndIf
         EndIf
     EndIf
     EndIf
     Return 0
     Return 0
EndFunc  ;==>_SingletonPID
EndFunc  ;==>_SingletonPID
</syntaxhighlight>
}}
[[#top|Return To Contents]]


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _Sort() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
{{Snippet Header|_Sort|35302-guinness|guinness|||1|AutoItCode=
 
<syntaxhighlight lang="autoit">
#include <Constants.au3>
#include <Constants.au3>


ConsoleWrite(_Sort("$sVariable" & @CRLF & "$iVariable" & @CRLF & "$tVariable" & @CRLF & "$pVariable"))
ConsoleWrite(_Sort("$sVariable" & @CRLF & "$iVariable" & @CRLF & "$tVariable" & @CRLF & "$pVariable"))


Func _Sort($sSortList)
Func _Sort(Const $sSortList)
     Local $iPID = Run("sort.exe", @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD), $sOutput = ""
     Local Const $iPID = Run("sort.exe", @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD), $sOutput = ""


     StdinWrite($iPID, $sSortList)
     StdinWrite($iPID, $sSortList)
     StdinWrite($iPID)
     StdinWrite($iPID)
     While 1
     While 1
         $sOutput &= StdoutRead($iPID)
         $sOutput &= StdoutRead($iPID)
         If @error Then
         If @error Then
             ExitLoop
             ExitLoop
         EndIf
         EndIf
     WEnd
     WEnd
     Return $sOutput
     Return $sOutput
EndFunc  ;==>_Sort
EndFunc  ;==>_Sort
</syntaxhighlight>
}}
[[#top|Return To Contents]]
 
===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' Speak Object and save to wav file ~ Author - SolidSnake '''</blockquote> =====


<syntaxhighlight lang="autoit">
{{Snippet Header|Speak Object and Save to WAV File|52278-solidsnake26|SolidSnake26|||1|AutoItCode=
; Speak Object and save to wav file
; Speak Object and save to wav file


_SpeakToWAV("AutoIt Snippets", @ScriptDir & "\SavedFile.wav")
_SpeakToWAV("AutoIt Snippets", @ScriptDir & "\SavedFile.wav")


Func _SpeakToWAV($sText, $sFilePath)
Func _SpeakToWAV(Const $sText, Const $sFilePath)
Local $ObjVoice = ObjCreate("Sapi.SpVoice")
Local $ObjVoice = ObjCreate("Sapi.SpVoice")
Local $ObjFile = ObjCreate("Sapi.SpFileStream.1")
Local $ObjFile = ObjCreate("Sapi.SpFileStream.1")
$ObjVoice.Speak($sText)
$ObjVoice.Speak($sText)
$ObjFile.Open($sFilePath, 3)
$ObjFile.Open($sFilePath, 3)
$ObjVoice.AudioOutputStream = $ObjFile
$ObjVoice.AudioOutputStream = $ObjFile
EndFunc  ;==>_SpeakToWAV
EndFunc  ;==>_SpeakToWAV
</syntaxhighlight>
}}
[[#top|Return To Contents]]


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _VariableSwap() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
{{Snippet Header|_VariableSwap|35302-guinness|guinness|||1|AutoItCode=
<syntaxhighlight lang="autoit">
Global $sString_1 = 'This is string 1.'
Local $sString_1 = 'This is string 1.', $sString_2 = 'This is string 2.'
Global $sString_2 = 'This is string 2.'


ConsoleWrite('$sString_1: ' & $sString_1 & @CRLF)
ConsoleWrite('$sString_1: ' & $sString_1 & @CRLF)
Line 787: Line 745:
; Swap the contents of two variables.
; Swap the contents of two variables.
Func _VariableSwap(ByRef $vVariable_1, ByRef $vVariable_2) ; Similar to _ArraySwap though not obvious to some this isn't limited to arrays.
Func _VariableSwap(ByRef $vVariable_1, ByRef $vVariable_2) ; Similar to _ArraySwap though not obvious to some this isn't limited to arrays.
     Local $vTemp = $vVariable_1
     Local Const $vTemp = $vVariable_1
     $vVariable_1 = $vVariable_2
     $vVariable_1 = $vVariable_2
     $vVariable_2 = $vTemp
     $vVariable_2 = $vTemp
EndFunc  ;==>_VariableSwap
EndFunc  ;==>_VariableSwap
</syntaxhighlight>
}}
[[#top|Return To Contents]]
 
===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _WinAPI_CharLower() & _WinAPI_CharUpper() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====


<syntaxhighlight lang="autoit">
{{Snippet Header|_WinAPI_CharLower|35302-guinness|guinness|||1|AutoItCode=
;Convert characters to upper or lower case
;Convert characters to upper or lower case


ConsoleWrite(_WinAPI_CharLower("EXAMPLE") & @CRLF) ; Similar to StringLower.
ConsoleWrite(_WinAPI_CharLower("EXAMPLE") & @CRLF) ; Similar to StringLower.
ConsoleWrite(_WinAPI_CharUpper("example") & @CRLF) ; Similar to StringUpper.


; Convert characters to lowercase.
; Convert characters to lowercase.
Line 810: Line 764:
     Return $aReturn[0]
     Return $aReturn[0]
EndFunc  ;==>_WinAPI_CharLower
EndFunc  ;==>_WinAPI_CharLower
}}
{{Snippet Header|_WinAPI_CharUpper|35302-guinness|guinness|||1|AutoItCode=
;Convert characters to upper or lower case


; Convert characters to uppercase.
ConsoleWrite(_WinAPI_CharLower("EXAMPLE") & @CRLF) ; Similar to StringLower.
Func _WinAPI_CharUpper($sString)
 
     Local $aReturn = DllCall('user32.dll', 'wstr', 'CharUpperW', 'wstr', $sString)
; Convert characters to lowercase.
Func _WinAPI_CharLower($sString)
     Local $aReturn = DllCall('user32.dll', 'wstr', 'CharLowerW', 'wstr', $sString)
     If @error Then
     If @error Then
         Return SetError(1, 0, $sString)
         Return SetError(1, 0, $sString)
     EndIf
     EndIf
     Return $aReturn[0]
     Return $aReturn[0]
EndFunc  ;==>_WinAPI_CharUpper
EndFunc  ;==>_WinAPI_CharLower
</syntaxhighlight>
}}
[[#top|Return To Contents]]
 
===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _WinAPI_PathFileExists() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====


<syntaxhighlight lang="autoit">
{{Snippet Header|_WinAPI_PathFileExists|35302-guinness|guinness|||1|AutoItCode=
; An API Alternative To FileExist.
; An API Alternative To FileExist.


Line 839: Line 796:
     Return $aReturn[0]
     Return $aReturn[0]
EndFunc  ;==>_WinAPI_PathFileExists
EndFunc  ;==>_WinAPI_PathFileExists
</syntaxhighlight>
}}
[[#top|Return To Contents]]


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _WinActiveByExe() ~ Author - [http://www.autoitscript.com/forum/user/4813-smoke-n/ SmOke_N] '''</blockquote> =====
{{Snippet Header|_WinActiveByExe|4813-smoke-n|SmOke_N|||1|AutoItCode=
 
<syntaxhighlight lang="autoit">
; Window Active/Activate by Exe, Open Notepad whilst script is running
; Window Active/Activate by Exe, Open Notepad whilst script is running


Line 871: Line 825:
     Return SetError(2, 0, 0)
     Return SetError(2, 0, 0)
EndFunc
EndFunc
</syntaxhighlight>
}}
[[#top|Return To Contents]]


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">'''  _WindowShake() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
{{Snippet Header|_WindowShake|35302-guinness|guinness|||1|AutoItCode=
 
<syntaxhighlight lang="autoit">
; Shake a window left to right.
; Shake a window left to right.


Line 914: Line 865:
     Next
     Next
EndFunc  ;==>_WindowShake
EndFunc  ;==>_WindowShake
</syntaxhighlight>
}}
[[#top|Return To Contents]]


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _WinGetDetails() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
{{Snippet Header|_WinGetDetails|35302-guinness|guinness|||1|AutoItCode=
#include <Array.au3>


<syntaxhighlight lang="autoit">
Global $aArray = _WinGetDetails('[ACTIVE]') ; Returns the Window's title, PID, folder path filename.
#include <Array.au3>


Local $aArray = _WinGetDetails('[ACTIVE]') ; Returns the Window's title, PID, folder path & filename.
If @error Then
If @error Then
     Exit
     Exit
EndIf
EndIf
_ArrayDisplay($aArray)
_ArrayDisplay($aArray)


Line 956: Line 906:
     Return SetError(1, 0, $aReturn)
     Return SetError(1, 0, $aReturn)
EndFunc  ;==>_WinGetPath
EndFunc  ;==>_WinGetPath
</syntaxhighlight>
}}
[[#top|Return To Contents]]
 
===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _WinGetNumeratedClassList() ~ Authors - [http://www.autoitscript.com/forum/user/20477-mrcreator/ MrCreatoR] '''</blockquote> =====


<syntaxhighlight lang="autoit">
{{Snippet Header|_WinGetNumeratedClassList|20477-mrcreator|MrCreatoR|||1|AutoItCode=
; Description: Retrieves the numerated classes from a window.
; Description: Retrieves the numerated classes from a window.


Line 969: Line 916:
     Local $sRetClassList = "", $sHold_List = "|"
     Local $sRetClassList = "", $sHold_List = "|"
     Local $aiInHold, $iInHold
     Local $aiInHold, $iInHold
   
 
     For $i = 1 To UBound($aClassList) - 1
     For $i = 1 To UBound($aClassList) - 1
         If $aClassList[$i] = "" Then ContinueLoop
         If $aClassList[$i] = "" Then ContinueLoop
       
 
         If StringRegExp($sHold_List, "\|" & $aClassList[$i] & "~(\d+)\|") Then
         If StringRegExp($sHold_List, "\|" & $aClassList[$i] & "~(\d+)\|") Then
             $aiInHold = StringRegExp($sHold_List, ".*\|" & $aClassList[$i] & "~(\d+)\|.*", 1)
             $aiInHold = StringRegExp($sHold_List, ".*\|" & $aClassList[$i] & "~(\d+)\|.*", 1)
             $iInHold = Number($aiInHold[UBound($aiInHold)-1])
             $iInHold = Number($aiInHold[UBound($aiInHold)-1])
           
 
             If $iInHold = 0 Then $iInHold += 1
             If $iInHold = 0 Then $iInHold += 1
           
 
             $aClassList[$i] &= "~" & $iInHold + 1
             $aClassList[$i] &= "~" & $iInHold + 1
             $sHold_List &= $aClassList[$i] & "|"
             $sHold_List &= $aClassList[$i] & "|"
           
 
             $sRetClassList &= $aClassList[$i] & @LF
             $sRetClassList &= $aClassList[$i] & @LF
         Else
         Else
Line 989: Line 936:
         EndIf
         EndIf
     Next
     Next
   
 
     Return StringReplace(StringStripWS($sRetClassList, 3), "~", "")
     Return StringReplace(StringStripWS($sRetClassList, 3), "~", "")
EndFunc
EndFunc
</syntaxhighlight>
}}
[[#top|Return To Contents]]


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _WinGetHandleByPID() ~ Author - [http://www.autoitscript.com/forum/user/4813-smoke-n/ SmOke_N] '''</blockquote> =====
{{Snippet Header|_WinGetHandleByPID|4813-smoke-n|SmOke_N|||1|AutoItCode=
; Get Window Handle by PID


<syntaxhighlight lang="autoit">
#include <Array.au3>
; Get Window Handle by PID


; Author Smoke_N
Global $a1 = _WinGetHandleByPID(232)
Global $a2 = _WinGetHandleByPID("notepad.exe", -1)
Global $a3 = _WinGetHandleByPID("notepad.exe", 0)
Global $a4 = _WinGetHandleByPID("notepad.exe", 1)


#include <array.au3>
Local $a1, $a2, $a3, $a4
$a1 = _WinGetHandleByPID(232)
$a2 = _WinGetHandleByPID("notepad.exe", -1)
$a3 = _WinGetHandleByPID("notepad.exe", 0)
$a4 = _WinGetHandleByPID("notepad.exe", 1)
_ArrayDisplay($a1, "1")
_ArrayDisplay($a1, "1")
_ArrayDisplay($a2, "2")
_ArrayDisplay($a2, "2")
Line 1,016: Line 959:
Func _WinGetHandleByPID($vProc, $nVisible = 1)
Func _WinGetHandleByPID($vProc, $nVisible = 1)
     $vProc = ProcessExists($vProc);
     $vProc = ProcessExists($vProc);
     If Not $vProc Then Return SetError(1, 0, 0)
     If Not $vProc Then Return SetError(1, 0, 0)
     Local $aWL = WinList()
     Local $aWL = WinList()
     Local $aTemp[UBound($aWL)][2], $nAdd = 0
 
     Local $aTemp[UBound($aWL)][2]
 
Local $nAdd = 0
 
     For $iCC = 1 To $aWL[0][0]
     For $iCC = 1 To $aWL[0][0]
         If $nVisible = -1 And WinGetProcess($aWL[$iCC][1]) = $vProc Then
         If $nVisible = -1 And WinGetProcess($aWL[$iCC][1]) = $vProc Then
Line 1,036: Line 985:
         EndIf
         EndIf
     Next
     Next
     If $nAdd = 0 Then Return SetError(2, 0, 0);No windows found
 
     If $nAdd = 0 Then Return SetError(2, 0, 0) ; No windows found
 
     ReDim $aTemp[$nAdd + 1][2]
     ReDim $aTemp[$nAdd + 1][2]
     $aTemp[0][0] = $nAdd
     $aTemp[0][0] = $nAdd
     Return $aTemp
     Return $aTemp
EndFunc
EndFunc
</syntaxhighlight>
}}
[[#top|Return To Contents]]

Revision as of 03:23, 12 November 2012


Please always credit an author in your script if you use their code. It is only polite.


{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}








{{{AuthorName}}}