//工程文件,不全
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;
AddAboutMenu(application.Handle);
//{
LoadSetting;
//显示闪现窗体并检查密码
if not (ShowSplashForm and CheckPassWord) then
begin
ReleaseMutex(hMutex);
application.Terminate;
exit;
end;
//}
Application.CreateForm(TMDIMainForm, MDIMainForm);
Application.Run;
//释放互斥对象
ReleaseMutex(hMutex);
end.
//登录窗体
//------------------------------------------------------------------------------
//Login.pas,Login.dfm
//登录窗体
//------------------------------------------------------------------------------
unit LogIn;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, Forms,
Dialogs, ExtCtrls,Global, Child, StdCtrls,
Buttons, TFlatEditUnit, TFlatButtonUnit,MainDM;
type
TLogInForm = class(TChildForm)
bOK: TFlatButton;
bCancel: TFlatButton;
tUserName: TFlatEdit;
tPassWord: TFlatEdit;
labUserName: TLabel;
labPassWord: TLabel;
procedure bOKClick(Sender: TObject);
procedure bCancelClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
private
{ Private declarations }
public
CheckOK:boolean;
{ Public declarations }
end;
function CheckPassWord(UserName:string=''):boolean;
implementation
uses MDIMain;
{$R *.dfm}
const
CM_MSG_CLOSE = WM_USER+402;
function CheckPassWord(UserName:string=''):boolean;
//检查密码函数,建立LogIn窗体
var
Handled : Boolean;
Msg : TMsg;
CanExit : Boolean;
begin
Application.Title:=SAppName;
with TLogInForm.Create(Application) do
begin
if length(UserName)>0 then
begin
Caption:=SCheckPassWord;
tUserName.Text:=UserName;
tUserName.Enabled:=false;
end;
Show;
CanExit:=False;
//{
while not CanExit do
if PeekMessage(Msg,0,0,0,PM_REMOVE) then
if (Msg.message = CM_MSG_CLOSE) then
CanExit:=True
else
begin
Handled := False;
if Assigned(Application.OnMessage) then
Application.OnMessage(Msg,Handled);
TranslateMessage(Msg);
DispatchMessage(Msg);
end
else
WaitMessage;
//}
result:=CheckOK;
end;
end;
procedure TLogInForm.bOKClick(Sender: TObject);
//确认密码
begin
inherited;
if length(tusername.text)>0 then
begin
if MainDMForm.ADSUser.Locate(sfield_username,tusername.Text,[]) then
begin
if MainDMForm.ADSUser[SField_PassWord]=tpassword.Text then
begin
sUserName:=MainDMForm.ADSUser[SField_UserName];
iUserGrade:=MainDMForm.ADSUser[SField_UserGrade];
CheckOK:=true;
close;
end else
begin
msgbox(sepassword,caption,mb_iconstop);
tpassword.SetFocus;
end;
end else
begin
msgbox(format(seusername,[tusername.text]),caption,mb_iconstop);
tusername.SetFocus;
end;
end else
begin
sUserName:=SNoUserName;
iUserGrade:=4;
CheckOK:=true;
Close;
end;
end;
procedure TLogInForm.bCancelClick(Sender: TObject);
//退出
begin
inherited;
CheckOK:=false;
Close;
end;
procedure TLogInForm.FormActivate(Sender: TObject);
//如果保存了用户名,则使用
begin
inherited;
if bSaveUserName and (length(susername)>0) then
begin
tUsername.Text:=susername;
tPassword.SetFocus;
end;
end;
procedure TLogInForm.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
inherited;
PostMessage(Handle,CM_MSG_CLOSE,0,0);
end;
end.