I need to detect whether a specific window is minimized or not. For this purpose I have found two functions:
1.
function PAIsWindowMinimized(h: HWND): Boolean;
// Detects whether a window is minimized or not
var
wp: Winapi.Windows.WINDOWPLACEMENT;
begin
wp.length := SizeOf(Winapi.Windows.WINDOWPLACEMENT);
Winapi.Windows.GetWindowPlacement(h, @wp);
Result := wp.showCmd = Winapi.Windows.SW_SHOWMINIMIZED;
end;
2.
// Alternative (https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-isiconic):
Winapi.Windows.IsIconic(h);
Which of the two alternatives is preferable? Or are they equally good in all situations?
IsIconic()is the proper and documented way to check if a window is minimized:IsIconic function
Window Features
Using anything else is a hack at best. The fact that
IsIconic()andGetWindowPlacement()internally check the HWND for theWS_MINIMIZEwindow style is just an implementation detail. The overhead of using these functions rather than checking the window style manually is negligible.Stick with
IsIconic(), it is the API that Microsoft specifically provides for this exact purpose.