Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


getWindowlist() returns titles only, no PIDs or handles

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
xxhehe
Expert Cheater
Reputation: 0

Joined: 11 Mar 2015
Posts: 166

PostPosted: Sun Jul 26, 2026 6:25 am    Post subject: getWindowlist() returns titles only, no PIDs or handles Reply with quote

The celua.txt documentation says getWindowlist() returns a table formatted as {pid, {id, caption}}. But my actual output is a list of window titles, without process IDs or handles. Is this a bug?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 475

Joined: 09 May 2003
Posts: 25980
Location: The netherlands

PostPosted: Sun Jul 26, 2026 7:03 am    Post subject: This post has 1 review(s) Reply with quote

it returns a list of PID's and each pid contains an indexed list of windowtitles.

no handles no, just a pid and an id you can use to traverse the list

e.g: pid 22656 has a list of 8 windownames, pid 25220 has a list of 25 windownames, etc...

this may make it more clear:
Code:

for pid,list in pairs(getWindowList()) do
  printf("processid %x has the following windows:", pid)
  for i=1,#list do
    printf("  %d = %s", i, list[i])
  end
  print("")
end

_________________
Tools give you results. Knowledge gives you control.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
xxhehe
Expert Cheater
Reputation: 0

Joined: 11 Mar 2015
Posts: 166

PostPosted: Sun Jul 26, 2026 11:22 pm    Post subject: Reply with quote

Dark Byte wrote:
it returns a list of PID's and each pid contains an indexed list of windowtitles.

no handles no, just a pid and an id you can use to traverse the list

e.g: pid 22656 has a list of 8 windownames, pid 25220 has a list of 25 windownames, etc...

this may make it more clear:
Code:

for pid,list in pairs(getWindowList()) do
  printf("processid %x has the following windows:", pid)
  for i=1,#list do
    printf("  %d = %s", i, list[i])
  end
  print("")
end


The celua.txt documentation says getWindowlist() returns a table in the format { PID, { ID, Caption } }. But my actual output is a dictionary keyed by PID, with each value being an array of window title strings.

Test this with:

for pid, list in pairs(getWindowList()) do
printf("processid %x has the following windows:", pid)
for i = 1, #list do
printf(" %d = %s", i, list[i])
end
print("")
end

The result shows only title strings. No ID field is present.

Three questions:

Is this a doc bug, or did the API change?

What does the spec's "id" actually refer to—index position, window handle (HWND), or something else? If it's an index, is it stable across CE versions, and can I use it to retrieve the handle or other properties?

Since I currently can't get handles, class names, or visibility from this API, I maintain a blacklist in my script to filter out irrelevant windows (IME, tray icons, etc.):


local blacklist = {
"Default IME", "MSCTFIME UI", "GDI+ Window", "DDE Window", "MCI","MSCTFIME",
"__wglDummyWindowFodder", "wglDummy", "DummyWindow",
"CTrayNotifyIcon Helper Window",
"TrayNotifyIcon",
"BluetoothNotificationAreaIconWindowClass",
"NvContainerWindowClass",
".NET-BroadcastEventWindow","MediaContextNotificationWindow",
"SystemResourceNotifyWindow","AppBarDetectFullScreen",
"TRAYAGENTWINDOW",
"UDiskVirtualWindow", "Window_tsvulfw_man_window_0","BroadcastListenerWindow","UxdService",
"CalcMsgPumpWnd",
"MS_WebcheckMonitor","DDE Server Window",
"NVOGLDC invisible",
"CiceroUIWndFrame",
"QTrayIconMessageWindow",
"WinEventWindow",
"_WINDOWTOP_INTERNAL_UI_",
"BroadcastListenerWindow",
"com.pot-app.desktop-siw",
"ms_sqlce_se_notify_wndproc",
"次级窗口","Secondary Window",
}



This works, but it's fragile. I have to maintain the blacklist manually and can't distinguish windows with identical titles.

Will you consider extending getWindowlist() to return {title, hwnd} per entry, or adding a separate API like getWindowInfo() for fuller window data?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 475

Joined: 09 May 2003
Posts: 25980
Location: The netherlands

PostPosted: Mon Jul 27, 2026 6:09 am    Post subject: Reply with quote

It's according to document. It returns a table containing pid's and each pid entry contains a. indexed list of titles. The id is the index

Use getWindow to enumerate all windows

_________________
Tools give you results. Knowledge gives you control.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
AylinCE
Grandmaster Cheater Supreme
Reputation: 39

Joined: 16 Feb 2017
Posts: 1583

PostPosted: Mon Jul 27, 2026 7:44 am    Post subject: Reply with quote

I think you can find what you're looking for in the module code linked below:

https://forum.cheatengine.org/viewtopic.php?t=623937

Examine it and test it by adding "print()" inside some for loops to see what it does.

EDIT:
Or you can try this code and modify it as needed:

Code:
-- Scans all running processes and returns a PID -> Executable mapping table
function getProcessMap()
    local sl = createStringList()
    getProcesslist(sl)
    local processMap = {}
    for i = 0, sl.count - 1 do
        local text = sl[i]
        local pidHex = string.sub(text, 1, 8)
        local name = string.sub(text, 10)
        local pid = tonumber(pidHex, 16)
        if pid then
            processMap[pid] = name
        end
    end
    sl.Destroy()
    return processMap
end

function getWindowInfo(targetExe, onlyMainWindows)
    -- Default to true if parameter is not provided
    if onlyMainWindows == nil then onlyMainWindows = true end

    local procMap = getProcessMap()
    local windowList = {}

    -- 1. Map PIDs and first found HWND/Title information based on the target EXE filter
    local pidWindowMap = {}
    local hwnd = executeCodeLocalEx("user32.GetTopWindow", 0)

    while hwnd and hwnd ~= 0 do
        local pid = getWindowProcessID(hwnd)
        local caption = getWindowCaption(hwnd)
        local className = getWindowClassName(hwnd)

        -- System IME and invalid title filters
        local isValidCaption = caption and caption ~= "" and caption ~= "Default IME" and className ~= "IME" and className ~= "MSCTFIME UI"

        if onlyMainWindows then
            -- Collect only windows with valid captions
            if isValidCaption then
                local exeName = procMap[pid]
                local isMatch = (not targetExe or targetExe == "") or (exeName and exeName:lower() == targetExe:lower())

                if isMatch then
                    table.insert(windowList, {
                        pid   = pid,
                        exe   = exeName or "Unknown",
                        hwnd  = hwnd,
                        title = caption
                    })
                end
            end
        else
            -- Store only the first encountered valid HWND and Title for that PID
            if not pidWindowMap[pid] and isValidCaption then
                pidWindowMap[pid] = {
                    hwnd  = hwnd,
                    title = caption
                }
            end
        end

        hwnd = executeCodeLocalEx("user32.GetWindow", hwnd, 2) -- GW_HWNDNEXT
    end

    -- 2. If onlyMainWindows = false, iterate through ALL PIDs to construct the list
    if not onlyMainWindows then
        for pid, exeName in pairs(procMap) do
            local isMatch = (not targetExe or targetExe == "") or (exeName:lower() == targetExe:lower())

            if isMatch then
                local winData = pidWindowMap[pid]
                table.insert(windowList, {
                    pid   = pid,
                    exe   = exeName or "Unknown",
                    hwnd  = winData and winData.hwnd or 0,
                    title = winData and winData.title or "Unknown"
                })
            end
        end
    end

    return windowList
end
--====================================--

-- Use:

-- Parameters: getWindowInfo(targetExe, onlyMainWindows)
-- targetExe: "chrome.exe", "appname.exe" or "" (For all processes)
-- onlyMainWindows:
--   true  -> Returns only main windows/tabs with a valid caption/title.
--   false -> Scans all PIDs, assigns 0 and "Unknown" to processes without a window/title.

local results = getWindowInfo("chrome.exe", true)  -- false or true ..
-- or getWindowInfo("", false) -- false or true ..

for i, win in ipairs(results) do
    print(string.format("[%d] PID: %d | EXE: %s | HWND: 0x%X | Title: %s",
        i, win.pid, win.exe, win.hwnd, win.title))
end

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
xxhehe
Expert Cheater
Reputation: 0

Joined: 11 Mar 2015
Posts: 166

PostPosted: Fri Jul 31, 2026 9:41 pm    Post subject: Reply with quote

AylinCE wrote:
I think you can find what you're looking for in the module code linked below:

https://forum.cheatengine.org/viewtopic.php?t=623937

Examine it and test it by adding "print()" inside some for loops to see what it does.

EDIT:
Or you can try this code and modify it as needed:

Code:
-- Scans all running processes and returns a PID -> Executable mapping table
function getProcessMap()
    local sl = createStringList()
    getProcesslist(sl)
    local processMap = {}
    for i = 0, sl.count - 1 do
        local text = sl[i]
        local pidHex = string.sub(text, 1, 8)
        local name = string.sub(text, 10)
        local pid = tonumber(pidHex, 16)
        if pid then
            processMap[pid] = name
        end
    end
    sl.Destroy()
    return processMap
end

function getWindowInfo(targetExe, onlyMainWindows)
    -- Default to true if parameter is not provided
    if onlyMainWindows == nil then onlyMainWindows = true end

    local procMap = getProcessMap()
    local windowList = {}

    -- 1. Map PIDs and first found HWND/Title information based on the target EXE filter
    local pidWindowMap = {}
    local hwnd = executeCodeLocalEx("user32.GetTopWindow", 0)

    while hwnd and hwnd ~= 0 do
        local pid = getWindowProcessID(hwnd)
        local caption = getWindowCaption(hwnd)
        local className = getWindowClassName(hwnd)

        -- System IME and invalid title filters
        local isValidCaption = caption and caption ~= "" and caption ~= "Default IME" and className ~= "IME" and className ~= "MSCTFIME UI"

        if onlyMainWindows then
            -- Collect only windows with valid captions
            if isValidCaption then
                local exeName = procMap[pid]
                local isMatch = (not targetExe or targetExe == "") or (exeName and exeName:lower() == targetExe:lower())

                if isMatch then
                    table.insert(windowList, {
                        pid   = pid,
                        exe   = exeName or "Unknown",
                        hwnd  = hwnd,
                        title = caption
                    })
                end
            end
        else
            -- Store only the first encountered valid HWND and Title for that PID
            if not pidWindowMap[pid] and isValidCaption then
                pidWindowMap[pid] = {
                    hwnd  = hwnd,
                    title = caption
                }
            end
        end

        hwnd = executeCodeLocalEx("user32.GetWindow", hwnd, 2) -- GW_HWNDNEXT
    end

    -- 2. If onlyMainWindows = false, iterate through ALL PIDs to construct the list
    if not onlyMainWindows then
        for pid, exeName in pairs(procMap) do
            local isMatch = (not targetExe or targetExe == "") or (exeName:lower() == targetExe:lower())

            if isMatch then
                local winData = pidWindowMap[pid]
                table.insert(windowList, {
                    pid   = pid,
                    exe   = exeName or "Unknown",
                    hwnd  = winData and winData.hwnd or 0,
                    title = winData and winData.title or "Unknown"
                })
            end
        end
    end

    return windowList
end
--====================================--

-- Use:

-- Parameters: getWindowInfo(targetExe, onlyMainWindows)
-- targetExe: "chrome.exe", "appname.exe" or "" (For all processes)
-- onlyMainWindows:
--   true  -> Returns only main windows/tabs with a valid caption/title.
--   false -> Scans all PIDs, assigns 0 and "Unknown" to processes without a window/title.

local results = getWindowInfo("chrome.exe", true)  -- false or true ..
-- or getWindowInfo("", false) -- false or true ..

for i, win in ipairs(results) do
    print(string.format("[%d] PID: %d | EXE: %s | HWND: 0x%X | Title: %s",
        i, win.pid, win.exe, win.hwnd, win.title))
end


Thank you very much!! The window recognition in recentFiles.lua now uses user32 enumeration, so the blacklist is no longer needed.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites