Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Problem getting edit box value in a Modal Dialog

mcmxxxmcmxxx Member Posts: 5
[italic]Hello Everyone,

I'm not familiar with Visual C++, so would really appreciate help from you guys.

From Dialog A (Class A), I have a button that will open Dialog B (Class B). Dialog B has an edit box and the value in this editbox I need to verify when I press the OK button of Dialog B. Unfortunately, I can't get the value. Below is part of my code.[/italic]


#include "stdafx.h"
#include "ClassA.h"
#include "ClassB.h"

BOOL CClassA::OnButtonA()
{
CDialog aboutDlg(IDD_DIALOG_B);
int nRet = -1;
nRet = aboutDlg.DoModal();
aboutDlg.SetActiveWindow();

switch (nRet)
{
case -1:
AfxMessageBox("Dialog box could not be created!");
break;
case IDOK:
{
CString checkValue;
CClassB getValue;
checkValue = getValue.GetPasswordValue();
MessageBox(checkValue, "Get Password Value", MB_OK);
break;
}

case IDCANCEL:
break;

default:
break;
}
}

*************************

#include "stdafx.h"
#include "adstoolkit.h"
#include "ClassB.h"

// CClassB dialog

CClassB::CClassB(CWnd* pParent /*=NULL*/)
: CDialog(CClassB::IDD, pParent)
{
//{{AFX_DATA_INIT(CEngVerifyPassword)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}


void CEngVerifyPassword::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CEngVerifyPassword)
DDX_Text(pDX, IDC_EDIT_PASSWORD, m_editPassword);
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CClassB, CDialog)
//{{AFX_MSG_MAP(CEngVerifyPassword)
ON_BN_CLICKED(IDCANCEL, OnCancel)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()


// CClassB message handlers
BOOL CClassB::OnInitDialog()
{
CDialog::OnInitDialog();
return TRUE;
}

void CClassB::OnCancel()
{
CDialog::OnCancel();
}

void CCClassB::OnOK()
{
CDialog::OnOK();
}

CString CClassB::GetPasswordValue()
{
return m_editPassword;
}

[italic]I can't get the value at edit box IDC_EDIT_PASSWORD (m_editPassword). Any idea what seems to be the problem...

Thank you very much,
maria[/italic]

Comments

  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : [code]
    : #include "stdafx.h"
    : #include "ClassA.h"
    : #include "ClassB.h"
    :
    : BOOL CClassA::OnButtonA()
    : {
    : CDialog aboutDlg(IDD_DIALOG_B);
    : int nRet = -1;
    : nRet = aboutDlg.DoModal();
    : aboutDlg.SetActiveWindow();
    :
    : switch (nRet)
    : {
    : case -1:
    : AfxMessageBox("Dialog box could not be created!");
    : break;
    : case IDOK:
    : {
    : CString checkValue;
    : CClassB getValue;
    : checkValue = getValue.GetPasswordValue();
    : MessageBox(checkValue, "Get Password Value", MB_OK);
    : break;
    : }
    :
    : case IDCANCEL:
    : break;
    :
    : default:
    : break;
    : }
    : }
    :
    : *************************
    :
    : #include "stdafx.h"
    : #include "adstoolkit.h"
    : #include "ClassB.h"
    :
    : // CClassB dialog
    :
    : CClassB::CClassB(CWnd* pParent /*=NULL*/)
    : : CDialog(CClassB::IDD, pParent)
    : {
    : //{{AFX_DATA_INIT(CEngVerifyPassword)
    : // NOTE: the ClassWizard will add member initialization here
    : //}}AFX_DATA_INIT
    : }
    :
    :
    : void [color=Red]CEngVerifyPassword[/color]::DoDataExchange(CDataExchange* pDX)
    [color=Red]// Looks like it should be "CClassB" up ^^^ here[/color]
    : {
    : CDialog::DoDataExchange(pDX);
    : //{{AFX_DATA_MAP(CEngVerifyPassword)
    : DDX_Text(pDX, IDC_EDIT_PASSWORD, m_editPassword);
    : // NOTE: the ClassWizard will add DDX and DDV calls here
    : //}}AFX_DATA_MAP
    : }
    :
    : BEGIN_MESSAGE_MAP(CClassB, CDialog)
    : //{{AFX_MSG_MAP(CEngVerifyPassword)
    : ON_BN_CLICKED(IDCANCEL, OnCancel)
    : //}}AFX_MSG_MAP
    : END_MESSAGE_MAP()
    :
    :
    : // CClassB message handlers
    : BOOL CClassB::OnInitDialog()
    : {
    : CDialog::OnInitDialog();
    : return TRUE;
    : }
    :
    : void CClassB::OnCancel()
    : {
    : CDialog::OnCancel();
    : }
    :
    : void [color=Red]CCClassB[/color]::OnOK() [color=Red]// typo?[/color]
    : {
    : CDialog::OnOK();
    : }
    :
    : CString CClassB::GetPasswordValue()
    : {
    : return m_editPassword;
    : }
    [/code]
  • mcmxxxmcmxxx Member Posts: 5
    Thanks, do you know what else seems to be the problem...

    ****************************************

    : #include "stdafx.h"
    : #include "ClassA.h"
    : #include "ClassB.h"
    :
    : BOOL CClassA::OnButtonA()
    : {
    : CDialog aboutDlg(IDD_DIALOG_B);
    : int nRet = -1;
    : nRet = aboutDlg.DoModal();
    : aboutDlg.SetActiveWindow();
    :
    : switch (nRet)
    : {
    : case -1:
    : AfxMessageBox("Dialog box could not be created!");
    : break;
    : case IDOK:
    : {
    : CString checkValue;
    : CClassB getValue;
    : checkValue = getValue.GetPasswordValue();
    : MessageBox(checkValue, "Get Password Value", MB_OK);
    : break;
    : }
    :
    : case IDCANCEL:
    : break;
    :
    : default:
    : break;
    : }
    : }
    :
    : *************************
    :
    : #include "stdafx.h"
    : #include "adstoolkit.h"
    : #include "ClassB.h"
    :
    : // CClassB dialog
    :
    : CClassB::CClassB(CWnd* pParent /*=NULL*/)
    : : CDialog(CClassB::IDD, pParent)
    : {
    : //{{AFX_DATA_INIT(CEngVerifyPassword)
    : // NOTE: the ClassWizard will add member initialization here
    : //}}AFX_DATA_INIT
    : }
    :
    :
    : void CClassB::DoDataExchange(CDataExchange* pDX)
    [color=Blue]// sorry, typo... edited the class name so it could be easier to explain.[/color]
    : {
    : CDialog::DoDataExchange(pDX);
    : //{{AFX_DATA_MAP(CEngVerifyPassword)
    : DDX_Text(pDX, IDC_EDIT_PASSWORD, m_editPassword);
    : // NOTE: the ClassWizard will add DDX and DDV calls here
    : //}}AFX_DATA_MAP
    : }
    :
    : BEGIN_MESSAGE_MAP(CClassB, CDialog)
    : //{{AFX_MSG_MAP(CEngVerifyPassword)
    : ON_BN_CLICKED(IDCANCEL, OnCancel)
    : //}}AFX_MSG_MAP
    : END_MESSAGE_MAP()
    :
    :
    : // CClassB message handlers
    : BOOL CClassB::OnInitDialog()
    : {
    : CDialog::OnInitDialog();
    : return TRUE;
    : }
    :
    : void CClassB::OnCancel()
    : {
    : CDialog::OnCancel();
    : }
    :
    : void CClassB::OnOK() // typo?>> [color=Blue]yes another typo...[/color]: {
    : CDialog::OnOK();
    : }
    :
    : CString CClassB::GetPasswordValue()
    : {
    : return m_editPassword;
    : }


  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : : [code]:
    : : #include "stdafx.h"
    : : #include "ClassA.h"
    : : #include "ClassB.h"
    : :
    : : BOOL CClassA::OnButtonA()
    : : {
    : : CDialog aboutDlg(IDD_DIALOG_B);
    : : int nRet = -1;
    : : nRet = aboutDlg.DoModal();
    : : aboutDlg.SetActiveWindow();
    : :
    : : switch (nRet)
    : : {
    : : case -1:
    : : AfxMessageBox("Dialog box could not be created!");
    : : break;
    : : case IDOK:
    : : {
    : : CString checkValue;
    : : CClassB getValue;
    : : checkValue = getValue.GetPasswordValue();

    [color=Red]// The problem might be here ^^^. How do you launch the 'getValue'
    // dialog? Because without actually launching it (showing it with
    // DoModal) - you can't get this string back.[/color]

    : : MessageBox(checkValue, "Get Password Value", MB_OK);
    : : break;
    : : }
    : :
    : : case IDCANCEL:
    : : break;
    : :
    : : default:
    : : break;
    : : }
    : : }
    [/code]
  • mcmxxxmcmxxx Member Posts: 5
    Yay... thanks...
    If possible would you help and show me how to launch the dialog... really appreciate your help...

    thanks again....
  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : : : [code]: :
    : : : #include "stdafx.h"
    : : : #include "ClassA.h"
    : : : #include "ClassB.h"
    : : :
    : : : BOOL CClassA::OnButtonA()
    : : : {
    : : : CDialog aboutDlg(IDD_DIALOG_B);
    : : : int nRet = -1;
    : : : nRet = aboutDlg.DoModal();
    : : : aboutDlg.SetActiveWindow();
    : : :
    : : : switch (nRet)
    : : : {
    : : : case -1:
    : : : AfxMessageBox("Dialog box could not be created!");
    : : : break;
    : : : case IDOK:
    : : : {
    : : : CString checkValue;
    : : : CClassB getValue;
    : : : [color=Red]getValue.DoModal ();[/color]
    : : : checkValue = getValue.GetPasswordValue();
    : : : MessageBox(checkValue, "Get Password Value", MB_OK);
    : : : break;
    : : : }
    : : :
    : : : case IDCANCEL:
    : : : break;
    : : :
    : : : default:
    : : : break;
    : : : }
    : : : }
    : [/code]:
    :
  • mcmxxxmcmxxx Member Posts: 5
    Thank you very much for helping out.
    It's working now.... yehey...

    have a great day!!



Sign In or Register to comment.