Skip to content

Commit

Permalink
Adjust example scripts to latest v2 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ragnar-F committed Jul 15, 2020
1 parent e875aa9 commit c436ef8
Show file tree
Hide file tree
Showing 26 changed files with 110 additions and 114 deletions.
4 changes: 2 additions & 2 deletions docs/commands/BufferAlloc.htm
Expand Up @@ -50,7 +50,7 @@ <h2 id="Examples">Examples</h2>
bufW := BufferAlloc(max_chars*2)

<em>; Print a UTF-16 string into the buffer with wsprintfW().</em>
DllCall("wsprintfW", "Ptr", bufW, "Str", "0x%08x", "UInt", 4919)
DllCall("wsprintfW", "Ptr", bufW, "Str", "0x%08x", "UInt", 4919, "CDecl")

<em>; Retrieve the string from bufW and show it.</em>
MsgBox StrGet(bufW, "UTF-16") <em>; Or just StrGet(bufW).</em>
Expand All @@ -59,7 +59,7 @@ <h2 id="Examples">Examples</h2>
bufA := BufferAlloc(max_chars)

<em>; Print an ANSI string into the buffer with wsprintfA().</em>
DllCall("wsprintfA", "Ptr", bufA, "AStr", "0x%08x", "UInt", 4919)
DllCall("wsprintfA", "Ptr", bufA, "AStr", "0x%08x", "UInt", 4919, "CDecl")

<em>; Retrieve the string from bufA (converted to the native format), and show it.</em>
MsgBox StrGet(bufA, "CP0")
Expand Down
14 changes: 6 additions & 8 deletions docs/commands/CallbackCreate.htm
Expand Up @@ -111,9 +111,7 @@ <h2>Related</h2>
<h2>Examples</h2>
<div class="ex" id="ExWinList">
<p><a href="#ExWinList">#1</a>: The following is a working script that displays a summary of all top-level windows.</p>
<pre><em>; For performance and memory conservation, call CallbackCreate only once for a given callback:</em>
if not EnumAddress <em>; Fast-mode is okay because it will be called only from this thread:</em>
EnumAddress := <strong>CallbackCreate</strong>(&quot;EnumWindowsProc&quot;, &quot;Fast&quot;)
<pre>EnumAddress := <strong>CallbackCreate</strong>(&quot;EnumWindowsProc&quot;, &quot;Fast&quot;) <em>; Fast-mode is okay because it will be called only from this thread.</em>

DetectHiddenWindows True <em>; Due to fast-mode, this setting will go into effect for the callback too.</em>

Expand All @@ -123,11 +121,11 @@ <h2>Examples</h2>

EnumWindowsProc(hwnd, lParam)
{
global Output
title := WinGetTitle("ahk_id " hwnd)
class := WinGetClass("ahk_id " hwnd)
if title
Output .= &quot;HWND: &quot; . hwnd . &quot;`tTitle: &quot; . title . &quot;`tClass: &quot; . class . &quot;`n&quot;
global Output := ""
win_title := WinGetTitle("ahk_id " hwnd)
win_class := WinGetClass("ahk_id " hwnd)
if win_title
Output .= &quot;HWND: &quot; hwnd &quot;`tTitle: &quot; win_title &quot;`tClass: &quot; win_class &quot;`n&quot;
return true <em>; Tell EnumWindows() to continue until all windows have been enumerated.</em>
}</pre>
</div>
Expand Down
24 changes: 4 additions & 20 deletions docs/commands/ComCall.htm
Expand Up @@ -93,35 +93,19 @@ <h2>Examples</h2>
IID_ITaskbarList := "{56FDF342-FD6D-11d0-958A-006097C9A090}"
CLSID_TaskbarList := "{56FDF344-FD6D-11d0-958A-006097C9A090}"

<em>; Create the TaskbarList object and store its address in tbl.</em>
<em>; Create the TaskbarList object.</em>
tbl := <a href="ComObjCreate.htm">ComObjCreate</a>(CLSID_TaskbarList, IID_ITaskbarList)

<em>; Since an IID was specified above, tbl is a pointer (an integer).
; The pointer may be wrapped so that it will be released automatically
; when the script no longer has a reference to the wrapper object.
; This example will still work if the following line is removed:</em>
tbl := ComObject(13, tbl)

activeHwnd := WinExist("A")

ComCall(3, tbl) <em>; tbl.<a href="http://msdn.microsoft.com/en-us/library/bb774650.aspx">HrInit</a>()</em>
ComCall(5, tbl, "ptr", activeHwnd) <em>; tbl.<a href="http://msdn.microsoft.com/en-us/library/bb774648.aspx">DeleteTab</a>(activeHwnd)</em>
Sleep 3000
ComCall(4, tbl, "ptr", activeHwnd) <em>; tbl.<a href="http://msdn.microsoft.com/en-us/library/bb774646.aspx">AddTab</a>(activeHwnd)</em>

if IsObject(tbl) <em>; Was ComObject(13, tbl) used?</em>
{
<em>; When finished with the object, simply replace any references with
; some other value (or if its a local variable, just return):</em>
tbl := ""
}
else
{
<em>; Since the pointer wasn't wrapped, it must be released manually
; (although any memory used by the object or the corresponding
; library would be reclaimed when the program exits, anyway).</em>
ObjRelease(tbl)
}
<em>; When finished with the object, simply replace any references with
; some other value (or if its a local variable, just return):</em>
tbl := ""
</pre>
</div>

Expand Down
2 changes: 2 additions & 0 deletions docs/commands/ComObjArray.htm
Expand Up @@ -64,6 +64,7 @@ <h2>Examples</h2>
arr[0] := "Auto"
arr[1] := "Hot"
arr[2] := "key"
t := ""
Loop arr.MaxIndex() + 1
t .= arr[A_Index-1]
MsgBox t
Expand All @@ -78,6 +79,7 @@ <h2>Examples</h2>
dim := DllCall("oleaut32\SafeArrayGetDim", "ptr", ComObjValue(arr))

<em>; Get the bounds of each dimension:</em>
dims := ""
Loop dim
dims .= arr.MinIndex(A_Index) " .. " arr.MaxIndex(A_Index) "`n"
MsgBox dims
Expand Down
1 change: 1 addition & 0 deletions docs/commands/ComObjConnect.htm
Expand Up @@ -71,6 +71,7 @@ <h2 id="Examples">Examples</h2>

<b>IE_<a href="http://msdn.microsoft.com/en-us/library/aa768329.aspx">DocumentComplete</a></b>(ieEventParam, url, ieFinalParam) {
global ie
s := ""
if (ie != ieEventParam)
s .= "First parameter is a new wrapper object.`n"
if (ie == ieFinalParam)
Expand Down
21 changes: 11 additions & 10 deletions docs/commands/DllCall.htm
Expand Up @@ -229,10 +229,10 @@ <h2>Examples</h2>

<div class="ex" id="ExQPC">
<p><a href="#ExQPC">#5</a>: Demonstrates QueryPerformanceCounter(), which gives more precision than <a href="../Variables.htm#TickCount">A_TickCount's</a> 10ms.</p>
<pre>DllCall(&quot;QueryPerformanceFrequency&quot;, &quot;Int64*&quot;, freq)
DllCall(&quot;QueryPerformanceCounter&quot;, &quot;Int64*&quot;, CounterBefore)
<pre>DllCall(&quot;QueryPerformanceFrequency&quot;, &quot;Int64*&quot;, freq := 0)
DllCall(&quot;QueryPerformanceCounter&quot;, &quot;Int64*&quot;, CounterBefore := 0)
Sleep 1000
DllCall(&quot;QueryPerformanceCounter&quot;, &quot;Int64*&quot;, CounterAfter)
DllCall(&quot;QueryPerformanceCounter&quot;, &quot;Int64*&quot;, CounterAfter := 0)
MsgBox &quot;Elapsed QPC time is &quot; . (CounterAfter - CounterBefore) / freq * 1000 &quot; ms&quot;</pre>
</div>

Expand Down Expand Up @@ -268,7 +268,8 @@ <h2>Examples</h2>

WatchScrollBar()
{
FocusedHwnd := ControlGetFocus("A")
FocusedHwnd := 0
try FocusedHwnd := ControlGetFocus("A")
if !FocusedHwnd <em>; No focused control.</em>
return
<em>; Display the vertical or horizontal scroll bar's position in a ToolTip:</em>
Expand Down Expand Up @@ -335,7 +336,7 @@ <h2>Examples</h2>
, "Int", 32, "Int", 32
, "Ptr", BufferAlloc(32*4, 0xFF)
, "Ptr", BufferAlloc(32*4, 0))
c[id] := {"default": h_default, "blank": h_blank}
c[id] := {default: h_default, blank: h_blank}
}
}
switch cmd
Expand Down Expand Up @@ -436,18 +437,18 @@ <h2>Examples</h2>
IID_ITaskbarList := "{56FDF342-FD6D-11d0-958A-006097C9A090}"
CLSID_TaskbarList := "{56FDF344-FD6D-11d0-958A-006097C9A090}"

<em>; Create the TaskbarList object and store its address in tbl.</em>
<em>; Create the TaskbarList object.</em>
tbl := <a href="ComObjCreate.htm">ComObjCreate</a>(CLSID_TaskbarList, IID_ITaskbarList)

activeHwnd := WinExist("A")

DllCall(vtable(tbl,3), "ptr", tbl) <em>; tbl.<a href="http://msdn.microsoft.com/en-us/library/bb774650.aspx">HrInit</a>()</em>
DllCall(vtable(tbl,5), "ptr", tbl, "ptr", activeHwnd) <em>; tbl.<a href="http://msdn.microsoft.com/en-us/library/bb774648.aspx">DeleteTab</a>(activeHwnd)</em>
DllCall(vtable(tbl.ptr,3), "ptr", tbl) <em>; tbl.<a href="http://msdn.microsoft.com/en-us/library/bb774650.aspx">HrInit</a>()</em>
DllCall(vtable(tbl.ptr,5), "ptr", tbl, "ptr", activeHwnd) <em>; tbl.<a href="http://msdn.microsoft.com/en-us/library/bb774648.aspx">DeleteTab</a>(activeHwnd)</em>
Sleep 3000
DllCall(vtable(tbl,4), "ptr", tbl, "ptr", activeHwnd) <em>; tbl.<a href="http://msdn.microsoft.com/en-us/library/bb774646.aspx">AddTab</a>(activeHwnd)</em>
DllCall(vtable(tbl.ptr,4), "ptr", tbl, "ptr", activeHwnd) <em>; tbl.<a href="http://msdn.microsoft.com/en-us/library/bb774646.aspx">AddTab</a>(activeHwnd)</em>

<em>; Non-wrapped interface pointers must be manually freed.</em>
ObjRelease(tbl)
ObjRelease(tbl.ptr)

vtable(ptr, n) {
<em>; NumGet(ptr, "ptr") returns the address of the object's virtual function
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/DriveEject.htm
Expand Up @@ -75,7 +75,7 @@ <h2>Examples</h2>
, &quot;UInt&quot;, hVolume
, &quot;UInt&quot;, 0x2D4808 <em>; IOCTL_STORAGE_EJECT_MEDIA</em>
, &quot;UInt&quot;, 0, &quot;UInt&quot;, 0, &quot;UInt&quot;, 0, &quot;UInt&quot;, 0
, &quot;UIntP&quot;, dwBytesReturned <em>; Unused.</em>
, &quot;UIntP&quot;, dwBytesReturned := 0 <em>; Unused.</em>
, &quot;UInt&quot;, 0)
DllCall("CloseHandle", &quot;UInt&quot;, hVolume)
}</pre>
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/FileAppend.htm
Expand Up @@ -79,7 +79,7 @@ <h2>Examples</h2>
<p><a href="#ExFTP">#3</a>: The following example demonstrates how to automate FTP uploading using the operating system's built-in FTP command.</p>
<pre>FTPCommandFile := A_ScriptDir "\FTPCommands.txt"
FTPLogFile := A_ScriptDir "\FTPLog.txt"
FileDelete FTPCommandFile <em>; In case previous run was terminated prematurely.</em>
try FileDelete FTPCommandFile <em>; In case previous run was terminated prematurely.</em>

FileAppend
(
Expand Down
6 changes: 4 additions & 2 deletions docs/commands/For.htm
Expand Up @@ -67,6 +67,7 @@ <h2>Examples</h2>
<p><a href="#ExBasic">#1</a>: List the properties owned by an object:</p>
<pre>colours := {red: 0xFF0000, blue: 0x0000FF, green: 0x00FF00}
<em>; The above expression could be used directly in place of "colours" below:</em>
s := ""
for k, v in colours.OwnProps()
s .= k "=" v "`n"
MsgBox s
Expand All @@ -75,7 +76,8 @@ <h2>Examples</h2>

<div class="ex" id="ExCOM">
<p><a href="#ExCOM">#2</a>: List all open Explorer and Internet Explorer windows, using the <a href="https://docs.microsoft.com/en-us/windows/win32/shell/shell">Shell</a> object.</p>
<pre>for window in ComObjCreate("Shell.Application").Windows
<pre>windows := ""
for window in ComObjCreate("Shell.Application").Windows
windows .= window.LocationName " :: " window.LocationURL "`n"
MsgBox windows</pre>
</div>
Expand All @@ -88,7 +90,7 @@ <h2>Examples</h2>

FibF() {
a := 0, b := 1
return (ByRef n) => (
return (ByRef n) =&gt; (
n := c := b, b += a, a := c,
true
)
Expand Down
1 change: 1 addition & 0 deletions docs/commands/Format.htm
Expand Up @@ -183,6 +183,7 @@ <h2>Examples</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>
s := ""
<em>; Simple substitution</em>
s .= Format("{2}, {1}!`r`n", "World", "Hello")
<em>; Padding with spaces</em>
Expand Down
4 changes: 2 additions & 2 deletions docs/commands/Hotkey.htm
Expand Up @@ -176,9 +176,9 @@ <h2 id="examples">Examples</h2>
HkGui.OnEvent("Escape", (*) =&gt; ExitApp())
HkGui.Show()

RegisterHotkey(this, *)
RegisterHotkey(thisCtrl, *)
{
Saved := this.Gui.Submit(false)
Saved := thisCtrl.Gui.Submit(false)
HotIf (*) =&gt; GetKeyState(Saved.Prefix)
Hotkey Saved.Suffix, (ThisHotkey) =&gt; MsgBox(ThisHotkey)
}</pre>
Expand Down
8 changes: 5 additions & 3 deletions docs/commands/InputHook.htm
Expand Up @@ -437,9 +437,11 @@ <h2>Examples</h2>
&amp;&amp; RegExMatch(WordList, "`nmi)^" prefix[0] "\K.*", Suffix)
Suffix := Suffix[0]

CaretGetPos cx, cy
ToolTip Suffix, cx + 15, cy

if CaretGetPos(cx, cy)
ToolTip Suffix, cx + 15, cy
else
ToolTip Suffix

<em>; Intercept Tab only while we're showing a Tooltip.</em>
ih.KeyOpt("{Tab}", Suffix = "" ? "-NS" : "+NS")
}
Expand Down
4 changes: 2 additions & 2 deletions docs/commands/IsObject.htm
Expand Up @@ -35,9 +35,9 @@ <h2>Related</h2>
<h2>Examples</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>object := {key: "value"}
<pre>obj := {key: "value"}

if IsObject(object)
if IsObject(obj)
MsgBox "This is an object."
else
MsgBox "This is not an object."</pre>
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/LoopParse.htm
Expand Up @@ -80,7 +80,7 @@ <h2>Examples</h2>

<div class="ex" id="ExClipboard">
<p><a href="#ExClipboard">#3</a>: This is the same as the example above except that it's for the clipboard. It's useful whenever the clipboard contains files, such as those copied from an open Explorer window (the program automatically converts such files to their file names):</p>
<pre>Loop parse, clipboard, "`n", "`r"
<pre>Loop parse, A_Clipboard, "`n", "`r"
{
Result := MsgBox("File number " A_Index " is " A_LoopField ".`n`nContinue?",, "y/n")
}
Expand Down
4 changes: 2 additions & 2 deletions docs/commands/LoopReg.htm
Expand Up @@ -104,7 +104,7 @@ <h2>Examples</h2>
<p><a href="#ExBasic">#2</a>: A working test script:</p>
<pre>Loop Reg, "HKCU\Software\Microsoft\Windows", "R KV" <em>; Recursively retrieve keys and values.</em>
{
if a_LoopRegType = &quot;key&quot;
if A_LoopRegType = &quot;key&quot;
value := &quot;&quot;
else
{
Expand All @@ -113,7 +113,7 @@ <h2>Examples</h2>
catch
value := &quot;*error*&quot;
}
Result := MsgBox(a_LoopRegName " = " value " (" a_LoopRegType ")`n`nContinue?",, "y/n")
Result := MsgBox(A_LoopRegName " = " value " (" A_LoopRegType ")`n`nContinue?",, "y/n")
}
Until Result = "No"</pre>
</div>
Expand Down
4 changes: 2 additions & 2 deletions docs/commands/OnClipboardChange.htm
Expand Up @@ -67,8 +67,8 @@ <h2>Examples</h2>
<pre>OnClipboardChange("ClipChanged")
return

ClipChanged(Type) {
ToolTip "Clipboard data type: " Type
ClipChanged(clip_type) {
ToolTip "Clipboard data type: " clip_type
Sleep 1000
ToolTip <em>; Turn off the tip.</em>
}</pre>
Expand Down
14 changes: 7 additions & 7 deletions docs/commands/OnError.htm
Expand Up @@ -69,7 +69,7 @@ <h2 id="Examples">Examples</h2>
<p><a href="#ExBasic">#1</a>: Logging errors to a text file instead of displaying them to the user.</p>
<pre>
OnError "LogError"
%cause% := error
i := Integer("cause_error")

LogError(exception, mode) {
FileAppend "Error on line " exception.Line ": " exception.Message "`n"
Expand All @@ -93,12 +93,12 @@ <h2 id="Examples">Examples</h2>
{
Errors := [] <em>; Array for accumulated errors.</em>
_cb := Func("AccumulateError").Bind(this.Errors)
Start() => OnError(this._cb, -1) <em>; Register our cb before others.</em>
Stop() => OnError(this._cb, 0) <em>; Unregister our cb.</em>
Last => this.Errors[-1] <em>; Most recent error.</em>
Count => this.Errors.Length <em>; Number of accumulated errors.</em>
__item[i] => this.Errors[i] <em>; Shortcut for indexing.</em>
__delete() => this.Stop() <em>; For tying to function scope.</em>
Start() =&gt; OnError(this._cb, -1) <em>; Register our cb before others.</em>
Stop() =&gt; OnError(this._cb, 0) <em>; Unregister our cb.</em>
Last =&gt; this.Errors[-1] <em>; Most recent error.</em>
Count =&gt; this.Errors.Length <em>; Number of accumulated errors.</em>
__item[i] =&gt; this.Errors[i] <em>; Shortcut for indexing.</em>
__delete() =&gt; this.Stop() <em>; For tying to function scope.</em>
}

<em>; This is the OnError callback function. 'errors' is given a value via Bind().</em>
Expand Down
1 change: 1 addition & 0 deletions docs/commands/OnMessage.htm
Expand Up @@ -112,6 +112,7 @@ <h2>Examples</h2>
{
X := lParam &amp; 0xFFFF
Y := lParam &gt;&gt; 16
Control := ""
thisGui := GuiFromHwnd(hwnd)
thisGuiControl := GuiCtrlFromHwnd(hwnd)
if thisGuiControl
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/RegExMatch.htm
Expand Up @@ -102,7 +102,7 @@ <h2>Examples</h2>
MsgBox RegExMatch(&quot;abc123123&quot;, &quot;123$&quot;) <em>; Shows 7 because the $ requires the match to be at the end.</em>
MsgBox RegExMatch(&quot;abc123&quot;, &quot;i)^ABC&quot;) <em>; Shows 1 because a match was achieved via the case-insensitive option.</em>
MsgBox RegExMatch(&quot;abcXYZ123&quot;, &quot;abc(.*)123&quot;, SubPat) <em>; Shows 1 and stores &quot;XYZ&quot; in SubPat[1].</em>
MsgBox RegExMatch(&quot;abc123abc456&quot;, &quot;abc\d+&quot;, &quot;&quot;, 2) <em>; Shows 7 instead of 1 due to StartingPosition 2 vs. 1.</em></pre>
MsgBox RegExMatch(&quot;abc123abc456&quot;, &quot;abc\d+&quot;,, 2) <em>; Shows 7 instead of 1 due to StartingPosition 2 vs. 1.</em></pre>
</div>

<div class="ex" id="ExObject">
Expand Down
8 changes: 4 additions & 4 deletions docs/commands/TreeView.htm
Expand Up @@ -380,14 +380,14 @@ <h2 id="Examples">Examples</h2>
SB.SetText(DirList[Item], 3)
}

Gui_Size(this, MinMax, Width, Height) <em>; Expand/Shrink ListView and TreeView in response to the user's resizing.</em>
Gui_Size(thisGui, MinMax, Width, Height) <em>; Expand/Shrink ListView and TreeView in response to the user's resizing.</em>
{
if MinMax = -1 <em>; The window has been minimized. No action needed.</em>
return
<em>; Otherwise, the window has been resized or maximized. Resize the controls to match.</em>
this["TV"].GetPos(,, TV_W)
this["TV"].Move(,,, Height - 30) <em>; -30 for StatusBar and margins.</em>
this["LV"].Move(,, Width - TV_W - 30, Height - 30)
thisGui["TV"].GetPos(,, TV_W)
thisGui["TV"].Move(,,, Height - 30) <em>; -30 for StatusBar and margins.</em>
thisGui["LV"].Move(,, Width - TV_W - 30, Height - 30)
}</pre>

</div>
Expand Down
4 changes: 2 additions & 2 deletions docs/commands/VarSetStrCapacity.htm
Expand Up @@ -80,10 +80,10 @@ <h2>Examples</h2>

if (A_Index = 1)
<em>; Alter the variable indirectly via DllCall.</em>
DllCall("wsprintf", <span class="red">"Ptr", StrPtr(buf)</span>, "Str", "0x%08x", "UInt", 4919)
DllCall("wsprintf", <span class="red">"Ptr", StrPtr(buf)</span>, "Str", "0x%08x", "UInt", 4919, "CDecl")
else
<em>; Use "str" to update the length automatically:</em>
DllCall("wsprintf", <span class="blue">"Str", buf</span>, "Str", "0x%08x", "UInt", 4919)
DllCall("wsprintf", <span class="blue">"Str", buf</span>, "Str", "0x%08x", "UInt", 4919, "CDecl")

<em>; Concatenate a string to demonstrate why the length needs to be updated:</em>
wrong_str := buf . "&lt;end&gt;"
Expand Down
3 changes: 2 additions & 1 deletion docs/commands/While.htm
Expand Up @@ -39,6 +39,7 @@ <h2>Examples</h2>
<pre>CoordMode "Mouse", "Screen"

~LButton::
{
MouseGetPos begin_x, begin_y
<strong>while</strong> GetKeyState(&quot;LButton&quot;)
{
Expand All @@ -47,7 +48,7 @@ <h2>Examples</h2>
Sleep 10
}
ToolTip
return</pre>
}</pre>
</div>

</body>
Expand Down

0 comments on commit c436ef8

Please sign in to comment.