终止前显示窗口 [英] show window before terminate
问题描述
我有一个delphi应用程序,该应用程序在启动时检查进程是否已经在运行,如果正在运行,则将数据传递给该进程并终止当前进程。问题:终止当前进程时,应用程序窗口在终止前会闪烁一秒钟。所有代码都在应用程序初始化中,甚至在创建主表单之前就已完成,因此我不了解它如何瞬间显示表单。我已经尝试了很多事情,例如使窗口不可见,似乎没有任何作用。
I have a delphi application that, on startup, checks to see if a process is already running, if it is running, I pass data over to that process and terminate the current process. The problem: In terminating the current process, the window of the app flashes for a split second prior to termination. All the code is in the application initialization, before that main form is even created, so I don't understand how it could show the form for a split second. I have tried numerous things like making the window invisible, nothing seems to work. Is there something I am doing wrong.
推荐答案
您显然没有足够快地终止。我会做类似的事情
You are apparently not terminating soon enough. I'd do something like
program Project1;
uses
Forms,
Windows,
Unit1 in 'Unit1.pas' {Form1};
{$R *.res}
function PrevInstance: boolean;
begin
...
end;
procedure PassData;
begin
...
end;
begin
if PrevInstance then
begin
PassData;
Exit;
end;
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
更新:我相信您会做类似的事情
Update: I believe you do something like
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure MyInitProc;
begin
if true then Application.Terminate;
end;
initialization
InitProc := @MyInitProc;
end.
这将不有效,因为 Application。终止
不会立即终止应用程序。相反,它只是发布 WM_QUIT
消息。在完成所有初始化之后,将收到此消息并采取措施。
This will not work, because Application.Terminate
doesn't terminate the application immediately. Instead, it simply posts a WM_QUIT
message. This message will be received and acted upon after all initialisation is completed.
这篇关于终止前显示窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!