const
LSFW_LOCK = 1 ;
LSFW_UNLOCK = 2 ;
function LockSetForegroundWindow(uLockCode: DWORD): BOOL; stdcall;
var
Form1: TForm1;
implementation
function LockSetForegroundWindow; external ' user32.dll ' name ' LockSetForegroundWindow ' ;
... {$R *.dfm}
... { TForm1 }
function wdSetForegroundWindow(Handle: THandle): Boolean;
begin
if ((Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion > 4 )) // up win 2000
or ((Win32Platform = VER_PLATFORM_WIN32_WINDOWS) and // up win 98
((Win32MajorVersion > 4 ) or
((Win32MajorVersion = 4 ) and
(Win32MinorVersion > 0 )))) then
LockSetForegroundWindow(LSFW_UNLOCK);
Result : = SetForegroundWindow(Handle);
end;
procedure TForm1.tmr1Timer(Sender: TObject);
begin
// Timer的Timer事件
Application.Restore;
wdSetForegroundWindow(Handle);
end;
强制窗口最前显示,摘自Raize组件包中TRzTrayIcon.RestoreApp过程
Application.Restore;
ShowWindow( Application.Handle, sw_Restore );
SetForegroundWindow( Application.Handle );
procedure TRzTrayIcon.RestoreApp;
begin
if FMenuVisible then
Exit;
FManualRestore := True;
try
Application.Restore;
if FEnabled then
begin
ShowWindow( Application.Handle, sw_Restore );
SetForegroundWindow( Application.Handle );
end;
DoRestoreApp;
finally
FManualRestore := False;
end;
end;