如果是,你可以在创建主窗口前先显示对话框,并设定返回值,如果输入的用户名和密码正确,则返回OK,显示主窗口。在BOOL COAApp::InitInstance()函数中加入如下代码:
CLoginDlg login
if (login.DoModal()==IDOK)
{
CSingleDocTemplate* pDocTemplate
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(COADoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(COAView))
AddDocTemplate(pDocTemplate)
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo
ParseCommandLine(cmdInfo)
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE
// The one and only window has been initialized, so show and update it.
m_pMainWnd->SetWindowText("XXXX系统")
m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED)
m_pMainWnd->UpdateWindow()
}
CString PassWord,NameCString strSQL="SELECT * FROM people"
GetDlgItem(IDC_EDIT1)->GetWindowText(Name)
GetDlgItem(IDC_EDIT2)->GetWindowText(PassWord)
m_pRecordset->Open(_bstr_t(strSQL),m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText)
m_name=(char*)_bstr_t(m_pRecordset->GetCollect("Pname"))
m_no=(char*)_bstr_t(m_pRecordset->GetCollect("Pno"))
m_pRecordset->Close()
if(PassWord==m_no&&Name==m_name)
{
send()
CDialog::OnOK()
}
else
{
AfxMessageBox("用户名或密码错误")
}
我的是Access数据库。不过原理一样的。 m_name和m_no你自己在代码里加上你自己的用户名和密码就可以了。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)