How to bring my application to the front?

后端 未结 8 663
孤城傲影
孤城傲影 2020-12-08 15:32

I know all the reasons why it is a bad idea. I dislike it if an application steals input focus, but this is for purely personal use and I want it to happen; it will not dist

相关标签:
8条回答
  • 2020-12-08 16:05

    Assuming that there are no other StayOnTop applications running you can temporarily set your forms FormStyle to be fsStayOnTop and then do an Application Restore and BringToFront and then change the formstyle back to whatever it was.

    tmpFormStyle := Application.MainForm.FormStyle;
    Application.MainForm.FormStyle := fsStayOnTop;
    Application.Restore; // optional
    Application.BringToFront;
    Application.MainForm.FormStyle := tmpFormStyle;
    

    Again, this only works if there are no other stayontop applications.

    0 讨论(0)
  • 2020-12-08 16:05
    function WinActivate(const AWinTitle: string): boolean;
    var
      _WindowHandle: HWND;
    begin
      Result := false;
      _WindowHandle := FindWindow(nil, PWideChar(AWinTitle));
      if _WindowHandle <> 0 then
      begin
        if IsIconic(_WindowHandle) then
          Result := ShowWindow(_WindowHandle, SW_RESTORE)
        else
          Result := SetForegroundWindow(_WindowHandle);
      end;
    end;
    
    if WinActivate(self.Caption) then
      ShowMessage('This works for me in Windows 10');
    
    0 讨论(0)
提交回复
热议问题