窗口自己激活自己

来源:互联网 发布:java我的世界编程 编辑:程序博客网 时间:2024/04/30 01:00

const
  LSFW_LOCK     
= 1;
  LSFW_UNLOCK   
= 2;
  function LockSetForegroundWindow(uLockCode: DWORD): BOOL; stdcall;
var
  Form1: TForm1;
implementation
  function LockSetForegroundWindow; external  
'user32.dll' name 'LockSetForegroundWindow';
...

{ 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;