var
hAppHandle: hwnd;
function EnumWindowCallback(hWnd: hWnd; lParam: lParam): BOOL; stdcall;
implementation
{$R *.fmx}
function EnumWindowCallback(hWnd: hWnd; lParam: lParam): BOOL; stdcall;
const
FMXClassName = 'TFMAppClass';
var
ProcessID: DWORD;
ClassName: string;
ClassNameLength: NativeInt;
begin
// XE4 (possibly others) has a phantom TFMAppClass window
if (GetWindowThreadProcessId(hWnd, ProcessID) = GetCurrentThreadId) and
(ProcessID = GetCurrentProcessId) then
begin
// Thanks to the ubiquitous David Heffernan... http://stackoverflow.com/questions/7096542/collect-all-active-window-class-names
SetLength(ClassName, 256);
ClassNameLength := GetClassName(hWnd, PChar(ClassName), Length(ClassName));
if ClassNameLength = 0 then
RaiseLastOSError;
SetLength(ClassName, ClassNameLength);
if ClassName = FMXClassName then
begin
// Found. store and return false to stop enumerating
hAppHandle := hWnd;
Exit(False);
end;
end;
Result := True; // Fallthrough, keep iterating
end;
procedure TwndCasovac5.Blikni;
begin
if IsIconic(hAppHandle) then begin
ShowWindow(hAppHandle, SW_SHOWNOACTIVATE);
end;
SetWindowPos(hAppHandle, HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOMOVE or SWP_NOACTIVATE or SWP_NOSIZE);
SetWindowPos(hAppHandle, HWND_NOTOPMOST, 0, 0, 0, 0,
SWP_NOMOVE or SWP_NOACTIVATE or SWP_NOSIZE);
end;
procedure TwndCasovac5.FormCreate(Sender: TObject);
begin
// find app handle
EnumWindows(@EnumWindowCallback, 0);
end;