Click here to Skip to main content
15,881,089 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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:

C++
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);
Posted
Updated 26-Aug-18 22:18pm
v2
Comments
Member 13927859 24-Aug-18 9:32am    
then in IntClient.cpp :
Jochen Arndt 24-Aug-18 9:55am    
The common scenario would be showing the dialog from InitInstance() before creating and showing the main frame. If the dialog does not return IDOK, return from InitInstance() with FALSE to terminate the application.

Your shown code does not make really sense. Such a login dialog usually has and input field and OK and Cancel buttons. Override the default OK handler. Within the handler perform the check by reading the text of the input field. If that is valid call CDialog::OnOK() and return. Otherwise just return without calling CDialog::OnOK() or optionally (e.g. after a specific number of attempts) call CDialog::OnCancel().
Member 13927859 24-Aug-18 10:34am    
what I m asking for , is that even the psw is incorrect , I can access to main window . how can I set the psw as the key to access or cancel the main window .
The code as bellow is which I have wrote in InitInstance.
KarstenK 24-Aug-18 12:27pm    
consider that the user has mistyped, fergotten the password or is an new user. Thats whay I would show the main interface but mainly disabled and only some helping function where enabled

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;
}
 
Share this answer
 
Comments
Afzaal Ahmad Zeeshan 24-Aug-18 9:59am    
Does this solve the problem? Or is it extra code to support your question?
Richard MacCutchan 24-Aug-18 12:00pm    
You need to set a value inside your CDialog object to indicate what the application should do on return from DoModal.
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);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900