[V2 B] Example error for CallbackCreate Topic is solved

Share your ideas as to how the documentation can be improved.
arcticir
Posts: 694
Joined: 17 Nov 2013, 11:32

[V2 B] Example error for CallbackCreate

29 Sep 2021, 07:14

The example in the documentation seems to only fetch the last data.

Code: Select all

EnumAddress := CallbackCreate(EnumWindowsProc, "Fast")  ; Fast-mode is okay because it will be called only from this thread.

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

; Pass control to EnumWindows(), which calls the callback repeatedly:
DllCall("EnumWindows", "Ptr", EnumAddress, "Ptr", 0)
MsgBox Output  ; Display the information accumulated by the callback.
    
EnumWindowsProc(hwnd, lParam)
{
    global Output := ""
    win_title := WinGetTitle(hwnd)
    win_class := WinGetClass(hwnd)
    if win_title
        Output .= "HWND: " hwnd "`tTitle: " win_title "`tClass: " win_class "`n"
    return true  ; Tell EnumWindows() to continue until all windows have been enumerated.
}
This is modified to get all of them.

Code: Select all

EnumAddress := CallbackCreate(EnumWindowsProc, "Fast")  ; Fast-mode is okay because it will be called only from this thread.

DetectHiddenWindows True  ; Due to fast-mode, this setting will go into effect for the callback too.
Output := ""
; Pass control to EnumWindows(), which calls the callback repeatedly:
DllCall("EnumWindows", "Ptr", EnumAddress, "Ptr", 0)
MsgBox Output  ; Display the information accumulated by the callback.
    
EnumWindowsProc(hwnd, lParam)
{
    global Output
    win_title := WinGetTitle(hwnd)
    win_class := WinGetClass(hwnd)
    if win_title
        Output .= "HWND: " hwnd "`tTitle: " win_title "`tClass: " win_class "`n"
    return true  ; Tell EnumWindows() to continue until all windows have been enumerated.
}
Last edited by gregster on 29 Sep 2021, 07:45, edited 1 time in total.
Reason: Topic moved from 'Bug Reports'.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: [V2 B] Example error for CallbackCreate

29 Sep 2021, 07:41

https://github.com/Lexikos/AutoHotkey_L ... b48434R124
looks like an unintentional change back from when concatenating to variable(.=) began requiring that they be initialized first

also this is the wrong forum to post in
User avatar
Ragnar
Posts: 615
Joined: 30 Sep 2013, 15:25

Re: [V2 B] Example error for CallbackCreate  Topic is solved

29 Sep 2021, 12:57

Thanks for reporting. Changes added in PR #492.

Return to “Suggestions on Documentation Improvements”

Who is online

Users browsing this forum: No registered users and 14 guests