登录界面:从对话框到主窗口 [英] Login interface :from dialog box to main window

查看:92
本文介绍了登录界面:从对话框到主窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从一个对话框(登录界面)访问主窗口。

我的方案是检查psw是否正确,然后显示窗口框架(SDI) (如果PSW是正确的)通过单击Enter键盘(而不是OK按钮)。

我将使用对话框和SDI。

我的问题是如何特别设置访问条件,我在两个不同的区域工作。

在我的登录对话框中,我的代码如下:



我尝试过:



Hi , I try to access to main window from a dialog box which is the login interface.
My scenario is to check if the psw is correct ,then it shows the window frame (SDI) (if the PSW is correct) by clicking on "Enter" key board (not an OK button).
I will work with dialog box and SDI .
My problem is how to set the access condition specially , I work with two different area.
In my Login Dialog Box ,my code is as bellow :

What I have tried:

void CLoginDlg::OnLogin()
{
	UpdateData(TRUE);
	CWnd* pwndCtrl = GetFocus();

	int ctrl_ID = pwndCtrl->GetDlgCtrlID();
	CLoginDlg LoginDlg;
	switch (ctrl_ID)
	{
	case IDC_EDIT_PSW:
		UpdateData(TRUE);
		BOOL Access=FALSE ;
		if (m_Login == "123") // password
		{
			//AfxMessageBox(_T("Successful Login")); 
			return ;
		}
		else
		Access = false;
	//case IDOK :
	//OnOK();
	UpdateData(FALSE);

推荐答案

BOOL CIntClientApp::InitInstance()
{
	// InitCommonControlsEx() est requis sur Windows XP si le manifeste de l'application
	// spécifie l'utilisation de ComCtl32.dll version 6 ou ultérieure pour activer les
	// styles visuels.  Dans le cas contraire, la création de fenêtres échouera.
	INITCOMMONCONTROLSEX InitCtrls;
	InitCtrls.dwSize = sizeof(InitCtrls);
	// À définir pour inclure toutes les classes de contrôles communs à utiliser
	// dans votre application.
	InitCtrls.dwICC = ICC_WIN95_CLASSES;
	InitCommonControlsEx(&InitCtrls);

	CWinAppEx::InitInstance();


	// Initialiser les bibliothèques OLE
	if (!AfxOleInit())
	{
		AfxMessageBox(IDP_OLE_INIT_FAILED);
		return FALSE;
	}

	AfxEnableControlContainer();

	EnableTaskbarInteraction(FALSE);
	SetRegistryKey(_T("Applications locales générées par AppWizard"));
	LoadStdProfileSettings(4);  // Charge les options de fichier INI standard (y compris les derniers fichiers utilisés)


	InitContextMenuManager();

	InitKeyboardManager();

	InitTooltipManager();
	CMFCToolTipInfo ttParams;
	ttParams.m_bVislManagerTheme = TRUE;
	theApp.GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL,
		RUNTIME_CLASS(CMFCToolTipCtrl), &ttParams);

	// Inscrire les modèles de document de l'application.  Ces modèles
	//  lient les documents, fenêtres frame et vues entre eux
	CSingleDocTemplate* pDocTemplate;
	pDocTemplate = new CSingleDocTemplate(
		IDR_MAINFRAME,
		RUNTIME_CLASS(CIntClientDoc),
		RUNTIME_CLASS(CMainFrame),       // fenêtre frame SDI principale
		RUNTIME_CLASS(CIntClientView));
	  //  RUNTIME_CLASS(CFormView);
	if (!pDocTemplate)
		return FALSE;
	AddDocTemplate(pDocTemplate);
	//Affichage de la boite de dialogue "Login"
	CLoginDlg Dlg;
	Dlg.DoModal();
	//BOOL Access= FALSE;
	//if (Dlg.DoModal() == IDOK )//&& Access==TRUE)
	//{

	// Analyser la ligne de commande pour les commandes shell standard, DDE, ouverture de fichiers
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);
	// Commandes de dispatch spécifiées sur la ligne de commande.  Retournent FALSE si
	// l'application a été lancée avec /RegServer, /Register, /Unregserver ou /Unregister.
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;
	// The main window has been initialized, so show and update it
		m_pMainWnd->ShowWindow(SW_SHOW);
	    m_pMainWnd->MoveWindow(400, 50, 1000, 800);
	    m_pMainWnd->UpdateWindow();
	
	//}
	return TRUE;
}


我尝试使用此代码,但是,我可以使用错误的PSW访问第二个界面。





I try with this code , but also ,I can access to second interface with an incorrect PSW.


void CLoginDlg::OnLogin()
{
	UpdateData(TRUE);
	CWnd* pwndCtrl = GetFocus();

	int ctrl_ID = pwndCtrl->GetDlgCtrlID();
	CLoginDlg LoginDlg;
	switch (ctrl_ID)
	{
	case IDC_EDIT_PSW:
		UpdateData(TRUE);
		BOOL Access=FALSE ;
		if (m_Login == "123") // password
		{
			AfxMessageBox(_T("Successful Login"));
			
			CDialog::OnOK();
			return;
		}
		else
			CDialog::OnCancel();
	//case IDOK :
	//OnOK();
	UpdateData(FALSE);


这篇关于登录界面:从对话框到主窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆