Window.Close

Window.Close ( 

number WndHandle,

number Method = CLOSEWND_SENDMESSAGE )

Example 1

Window.Close(app_handle, CLOSEWND_SENDMESSAGE);

Sends a close message to the program whose window handle is stored in the variable "app_handle."

Example 2

Window.Close(app_handle, CLOSEWND_TERMINATE);

Terminates the process of the program whose window handle is stored in the variable "app_handle."

Example 3

-- Get the titles and window handles of all open windows.
windows = Window.EnumerateTitles();

-- A variable containing text in the title you want to search for.
window_name = "Notepad";

-- Loop through the table of windows.
for handle, title in pairs(windows) do

    -- Check if the window title has the target text.
    result = String.Find(title, window_name, 1, false);

    -- if the string was found in the title, send the window a close message.
    if (result ~= -1) then
        Window.Close(handle, CLOSEWND_SENDMESSAGE);
    end
end

Finds all open windows with the string "Notepad" in the title and sends each of them a close message.

See also:  Related Actions