Lua:getWindowClassName

From Cheat Engine
Revision as of 00:28, 27 June 2026 by Leunsel (talk | contribs) (Major overhaul of the post.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

<> Lua API Reference

function getWindowClassName(windowhandle) : string

Returns the class name of the specified window.

Function Parameters

Parameter Type Description
windowhandle Integer The handle of the window to query.

Returns

String — The class name of the specified window.

Examples

Get the class name of the main form

1 local form = getMainForm()
2 local windowHandle = form.Handle
3 
4 local className = getWindowClassName(windowHandle)
5 
6 print(className)

Get the class name of a created form

1 local form = createForm(false)
2 form.Caption = "Class Name Test"
3 
4 local className = getWindowClassName(form.Handle)
5 
6 print("Window class name: " .. tostring(className))
7 
8 form.destroy()

Use with the foreground window

1 local windowHandle = getForegroundWindow()
2 
3 if windowHandle ~= nil and windowHandle ~= 0 then
4   local className = getWindowClassName(windowHandle)
5 
6   print("Foreground window class: " .. tostring(className))
7 end

Compare a window class name

1 local windowHandle = getForegroundWindow()
2 
3 if windowHandle ~= nil and windowHandle ~= 0 then
4   local className = getWindowClassName(windowHandle)
5 
6   if className == "TCEForm" then
7     print("The foreground window is a Cheat Engine form")
8   end
9 end

Get class name and process ID

1 local windowHandle = getForegroundWindow()
2 
3 if windowHandle ~= nil and windowHandle ~= 0 then
4   local className = getWindowClassName(windowHandle)
5   local processID = getWindowProcessID(windowHandle)
6 
7   print("Class: " .. tostring(className))
8   print("PID: " .. tostring(processID))
9 end

Guard against an invalid window handle

1 local windowHandle = 0
2 
3 if windowHandle ~= nil and windowHandle ~= 0 then
4   local className = getWindowClassName(windowHandle)
5 
6   print(className)
7 else
8   print("Invalid window handle")
9 end

Main Pages

Core Lua documentation entry points

Lua
Script Engine

Form Related Classes