上一页 1 2 10、接下来,修改工程的源代码,以便在显示主窗口之前显示溅射对话框。这里需要在工程文件中插入语句,以便与Splash.dpr工程文件相匹配。工程源代码如下:
program Project3;
uses
Forms,
main in ‘main.pas‘ {MainForm},
splash in ‘splash.pas‘ {SplashForm};
{$R *.RES}
begin
SplashForm:=TSplashForm.Create(Application);
SplashForm.Show;
SplashForm.Update;
Application.CreateForm(TMainForm,MainForm);
SplashForm.Close;
Application.Run;
end. |
11、如果这时编译和运行程序,它就非常快速地显示和去除启动溅射对话框,以至用户可能没机会见到它。为了强迫对话框保持几秒钟的可见时间,请选取程序的MainForm。为窗体的OnCreate命令创建一个处理器。在关键词的前面添加一个名为stopTime的长整型变量。在begin和end之间插入两个语句:一个为对Windows GetTickCount函数的调用。来将stopTime设置为Windows已在运行的秒数;另一个语句为while语句,这个语句另外延迟2秒钟。程序清单如下:
unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TMainForm = class(TForm)
Exitbutton: TButton;
procedure ExitbuttonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
{$R *.DFM}
procedure TMainForm.ExitbuttonClick(Sender: TObject);
begin
close;
end;
procedure TMainForm.FormCreate(Sender: TObject);
var
stopTime:LongInt;
begin
stopTime:=GetTickCount div 1000;
while ((GetTickCount div 1000)<(stopTime+2)) do
Sleep(1);
end;
end. |
12、按F9编译、运行程序。
上一页 1 2 |