flash窗体dpr文件~~~(100分)

  • 主题发起人 主题发起人 小p
  • 开始时间 开始时间

小p

Unregistered / Unconfirmed
GUEST, unregistred user!
现做一flash窗体,在dpr中加入如下代码
frm_flash:=tfrm_flash.Create(application);
frm_flash.Show;
while frm_flash.Timer1.Enabled do
begin
frm_flash.Update;
application.ProcessMessages;
end;
frm_flash.Close;
frm_flash.Free;
请逐句给予解释,谢谢!
 
frm_flash:=tfrm_flash.Create(application);
//建立窗体好象不好,最好是create(nil);
frm_flash.Show;
//显示窗体
while frm_flash.Timer1.Enabled do
//判断定时器是否触发了退出事件
begin
frm_flash.Update;
//更新窗体
application.ProcessMessages;
//等程序处理其它事件
end;
frm_flash.Close;
//关闭
frm_flash.Free;
//释放

总结,上面的代码实在不怎么样,会造成CPU占用率太高
 
那你可以教教我怎么才能做一个好点的flash窗体啊?
 
//------------------------------------------------------------------------------
//工程文件
//------------------------------------------------------------------------------

program StockManage;

uses
Forms,
Windows,
Messages,
MDIMain in 'MDIMain.pas' {MDIMainForm},
MainDM in 'MainDM.pas' {MainDMForm: TDataModule},
Splash in 'Splash.pas' {SplashForm},
LogIn in 'LogIn.pas' {LogInForm},
Global in 'Global.pas';

{$R *.res}
var
hMutex,hApp:HWND;
begin
Application.Initialize;
//建立互斥对象
hMutex:=CreateMutex(nil,False,PChar(SAppName));
If GetLastError=ERROR_ALREADY_EXISTS Then
begin
//已经运行,找到句柄
hApp:=FindWindow('TApplication',PChar(SAppName));
//激活
if IsIconic(hApp) then
PostMessage(hApp,WM_SYSCOMMAND,SC_RESTORE,0);
SetForegroundWindow(hApp);
//释放互斥对象
ReleaseMutex(hMutex);
Application.Terminate;
exit;
end;
Application.HintPause :=500;
Application.HintHidePause :=10000;
Application.ShowMainForm :=False;
Application.OnMessage := MDIMainForm.AppMessageHandler;
//{
//显示闪现窗体并检查密码
if not (ShowSplashForm and CheckPassWord) then
begin
ReleaseMutex(hMutex);
application.Terminate;
exit;
end;
//}
Application.CreateForm(TMDIMainForm, MDIMainForm);
Application.Run;
//释放互斥对象
ReleaseMutex(hMutex);
end.

//------------------------------------------------------------------------------
//Splash.pas,Splash.dfm
//闪现窗体,并联接数据库
//------------------------------------------------------------------------------

unit Splash;

interface

uses
Windows, Messages, SysUtils, Classes, Controls, Forms,
Dialogs, ExtCtrls,Global,ADODB, MainDM, Graphics, StdCtrls;

type
TSplashForm = class(TForm)
dlgOpen: TOpenDialog;
imgBack: TImage;
private
{ Private declarations }
public
{ Public declarations }
end;

function ShowSplashForm:boolean;

var
SplashForm: TSplashForm;

implementation

{$R *.dfm}
function ShowSplashForm:boolean;
//显示闪现窗口,同时连接数据库,如果失败则选择其它数据库
function OpenDBFile:boolean;
//选择数据库
begin
result:=true;
SplashForm.dlgopen.FileName:=sDataBaseName;
if SplashForm.dlgopen.Execute then
sDataBaseName:=SplashForm.dlgopen.FileName
else
result:=false;
Application.ProcessMessages;
end;
begin
Screen.Cursor:=crHourGlass;
result:=true;
SplashForm:=TSplashForm.Create(Application);
SplashForm.Show;
SplashForm.Refresh;
if length(sDataBaseName)=0 then
sDataBaseName:=ExtractFilePath(application.ExeName)
+SDefDataBaseName;
if not FileExists(sDataBaseName) then
result:=OpenDBFile;
while result do
try
MainDMForm:=TMainDMForm.Create(Application);
with MainDMForm do
begin
if CNMain.Connected then CNMain.Close;
CNMain.ConnectionString:=format(
SConnectionString,[sDataBaseName,GetPassWord]);
CNMain.Open;
end; //with
except
msgbox(SEOpenDBFile,SAppName,mb_iconstop);
result:=OpenDBFile;
end; //try
if not result then exit;
Application.ProcessMessages;
// Sleep(3000); //延时修改这里
Screen.Cursor:=crDefault;
SplashForm.Close;
SplashForm.Free;
end;

end.
 
后退
顶部