Flash 应用程序任务栏按钮?

Flash application's task bar button?

对于 Delphi 10 Seattle,我尝试使用以下代码使应用程序的 Windows 任务栏按钮闪烁:

procedure TForm1.Button1Click(Sender: TObject);
begin
  FlashWindow(Application.Handle, True); 
end;

或:

procedure TForm1.Button1Click(Sender: TObject);
var
  Flash: FLASHWINFO;
begin
  FillChar(Flash, SizeOf(Flash), 0);
  Flash.cbSize := SizeOf(Flash);
  Flash.hwnd := Application.Handle;
  Flash.dwFlags := FLASHW_ALL or FLASHW_TIMER;
  Flash.dwTimeout := 1000;
  FlashWindowEx(Flash);
end;

或:

procedure TForm1.Button1Click(Sender: TObject);
var
  Flash: FLASHWINFO;
begin
  FillChar(Flash, SizeOf(Flash), 0);
  Flash.cbSize := SizeOf(Flash);
  Flash.hwnd := Application.Handle;
  Flash.uCount := 5;
  Flash.dwTimeOut := 2000;
  Flash.dwFlags := FLASHW_ALL;
  FlashWindowEx(Flash);  
end;

OS: Windows 7 x64 SP1

不幸的是,这不起作用:任务栏按钮根本不闪烁。

我怎样才能使这个工作?

在您的 .dpr 文件中,您将看到以下行:

Application.MainFormOnTaskBar := True;

这意味着与任务栏按钮关联的 window 是主窗体的按钮。而不是 Application 对象的那个。因此,在您的代码中,将 Application.MainFormHandle 传递给 FlashWindowFlashWindowEx.