判断程序是否已经启动:
HANDLE hMutex = CreateMutex(NULL,true,"ProcessName"); // 用来判断程序是否已启动
if(hMutex != 0&&GetLastError() == ERROR_ALREADY_EXISTS) //已启动,退出
{
Application->MessageBox( "已登录!","提示",MB_OK|MB_ICONINFORMATION );
Application->Terminate();
exit(1);
}
登陆:在FormMain(主界面)的oncreate事件中引起登陆界面。
FormLogin = new TFormLogin(this); //登陆界面
if (FormLogin->ShowModal() == mrOk)
{
delete FormLogin;
FormLogin = NULL ;
}
else
{
delete FormLogin;
FormLogin = NULL ;
Application->MessageBox("数据库连接失败", "提示", MB_OK + MB_ICONINFORMATION);
Application->Terminate();
// Close();
return;
}
登录操作验证正确:ModalResult = mrOk;
退出: 在FormMain(主界面)的onclose事件中引起退出确认。
if( Application->MessageBox("确定要退出系统?","警告",MB_OKCANCEL)!=IDOK)
{
Action = caNone;
return;
}
在请求退出的地方直接写上 Close()即可。
提示框:
只有提示:Application->MessageBox("数据库连接失败", "提示", MB_OK + MB_ICONINFORMATION);
带有选项:Application->MessageBox("确定要退出系统?","警告",MB_OKCANCEL)
登陆操作中的快捷方式:
在用户名TEdit中打回车定位到密码(onkeydown):
if(Key == 13) //Enter键
{
if(!Edit_UserName->Text.IsEmpty())
{
Edit_Password->SelectAll();
Edit_Password->SetFocus();
}
}
在密码TEdit中打回车登陆验证(onkeydown):
if(Key == 13) //Enter键
{
Button_confirmClick(Edit_Password);
}
有关配置信息的操作:
AnsiString strFileName = ExtractFilePath(Application->ExeName)+"DBConfig.ini";
TIniFile *pIniFile = new TIniFile(strFileName);
int n = pIniFile->ReadInteger("中括号里的","变量",默认值)); //读出
pIniFile->WriteString("APPServerName", "sn", NameNeeded ); //写入
delete pIniFile;
pIniFile = NULL;