--- cut here: begin --------------------------------------------------
/*
* Close TSE Pro Windows
*
* This SAL program for TSE Pro uses the Windows API to find and close
* any windows that contain "TSE Pro" in their title.
*/
#define WM_CLOSE 0x0010 // Windows message constant for closing a window
#define GW_HWNDNEXT 2 // GetWindow command to get next window
#define GW_HWNDFIRST 0 // GetWindow command to get first child window
// Windows API function declarations
dll "<user32.dll>"
integer proc GetWindow(integer hwnd, integer uCmd): "GetWindow"
integer proc GetDesktopWindow(): "GetDesktopWindow"
integer proc GetTopWindow(integer hWnd): "GetTopWindow"
integer proc SendMessage(integer hwnd, integer msg, integer wParam, integer lParam): "SendMessageA"
integer proc GetWindowText(integer hwnd, var string lpString, integer nMaxCount): "GetWindowTextA"
integer proc IsWindow(integer hwnd): "IsWindow"
integer proc GetWindowThreadProcessId(integer hwnd, var integer lpdwProcessId): "GetWindowThreadProcessId"
integer proc IsWindowVisible(integer hwnd): "IsWindowVisible"
end
dll "<kernel32.dll>"
integer proc GetCurrentProcessId(): "GetCurrentProcessId"
end
// Main procedure
proc Main()
integer hwnd = 0 // Window handle
integer nextHwnd = 0 // Next window handle
integer windowClosed = FALSE // Flag to track if any window was closed
integer procId = 0 // Process ID
integer ourProcId = 0 // Our process ID
string windowTitle[255] = "" // Window title buffer
integer closedCount = 0 // Count of closed windows
integer foundAny = FALSE // Flag to track if any windows were found
integer skipWindow = FALSE // Flag to check if we should skip current window
// Get our own process ID to avoid closing our own windows
ourProcId = GetCurrentProcessId()
// Display initial message
// Warn("Searching for TSE Pro windows...")
// Start with no windows closed
windowClosed = FALSE
// Loop until no more windows are closed
repeat
// Reset flag for this iteration
windowClosed = FALSE
// Get desktop window first, then the first top-level window
hwnd = GetDesktopWindow()
hwnd = GetTopWindow(hwnd)
// Warn("First hwnd: " + Str(hwnd))
// Loop through all top-level windows
while hwnd <> 0
// Save next window handle before potentially closing this one
nextHwnd = GetWindow(hwnd, GW_HWNDNEXT)
// Default is to process this window
skipWindow = FALSE
// Skip if window is not visible
if not IsWindowVisible(hwnd)
skipWindow = TRUE
endif
// Check if it's our own window
if not skipWindow
// Get window's process ID
GetWindowThreadProcessId(hwnd, procId)
// Skip our own process windows
if procId == ourProcId
skipWindow = TRUE
endif
endif
// Process window if not skipped
if not skipWindow
// Get the window title
windowTitle = ""
GetWindowText(hwnd, windowTitle, sizeof(windowTitle))
// Debug message to show what windows we're examining
// Warn("Checking window: '" + windowTitle + "' (handle: " + Str(hwnd) + ")")
// Check if the window title contains "TSE Pro", using case-insensitive search
if length(windowTitle) > 0 and (pos("TSE Pro", windowTitle) > 0 or pos("tse pro", windowTitle) > 0)
// Found a TSE Pro window
foundAny = TRUE
// Display message about closing the window
// Warn("Found TSE Pro window: '" + windowTitle + "', closing...")
// Send WM_CLOSE message to the window
SendMessage(hwnd, WM_CLOSE, 0, 0)
// Wait a bit to let the window close
// delay(100) // Increased delay for better reliability
// Check if window was closed
if not IsWindow(hwnd)
windowClosed = TRUE
closedCount = closedCount + 1
// Warn("Window closed successfully.")
else
Warn("Failed to close window.")
endif
// Break out of the window loop to restart the search
// This is needed because window handles may change after closing a window
break
endif
endif
// Move to the next window
hwnd = nextHwnd
endwhile
until not windowClosed
// Final message
if foundAny
if closedCount > 0
Warn("Closed " + str(closedCount) + " TSE Pro window(s).")
else
Warn("Found TSE Pro windows but failed to close them.")
endif
PurgeMacro( CurrMacroFilename() )
else
Warn("No TSE Pro windows found.")
endif
end
--- cut here: end ----------------------------------------------------