Cordial greetings colleagues, it turns out that I am developing an MFC Dll C ++, which contains a script with certain functions and I have a dialog box created, since I need that from this dialog box, the user can by keyboard enter values to a variable , the question is how to do, so that what is entered in the edit text, which is in the dialog box, is saved in a specific variable, and then you can use that value stored in that variable, for some procedure, attached image of the dialog box created and the code that contains the edit text of this.
The dialog box has the name of input, and the name of the class of this is Input Box.
Attached code of the file CajaEntrada.CPP
// CajaEntrada.cpp: archivo de implementación
//
#include "stdafx.h"
#include "NPL2017.h"
#include "CajaEntrada.h"
#include "afxdialogex.h"
// Cuadro de diálogo de CajaEntrada
IMPLEMENT_DYNAMIC(CajaEntrada, CDialog)
CajaEntrada::CajaEntrada(CWnd* pParent /*= nullptr*/)
: CDialog(input, pParent)
,entrada(_T("Ingresa un valor"))
{
}
CajaEntrada::~CajaEntrada()
{
}
void CajaEntrada::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CajaEntrada, CDialog)
ON_EN_CHANGE(txtentrada, &CajaEntrada::OnEnChangetxtentrada)
END_MESSAGE_MAP()
// Controladores de mensajes de CajaEntrada
void CajaEntrada::OnEnChangetxtentrada()
{
// TODO: Si éste es un control RICHEDIT, el control no
// enviará esta notificación a menos que se invalide CDialog::OnInitDialog()
// función y llamada CRichEditCtrl().SetEventMask()
// con la marca ENM_CHANGE ORed en la máscara.
// TODO: Agregue aquí el controlador de notificación de controles
}
Attached code of the file CajaEntrada.h.
#pragma once
// Cuadro de diálogo de CajaEntrada
class CajaEntrada : public CDialog
{
DECLARE_DYNAMIC(CajaEntrada)
public:
CajaEntrada(CWnd* pParent = nullptr); // Constructor estándar
virtual ~CajaEntrada();
// Datos del cuadro de diálogo
#ifdef AFX_DESIGN_TIME
enum { IDD = input };
#endif
protected:
virtual void DoDataExchange(CDataExchange* pDX); // Compatibilidad con DDX/DDV
DECLARE_MESSAGE_MAP()
public:
CString entrada;
afx_msg void OnEnChangetxtentrada();
};
The name of the edit text that belongs to the dialog box is txtentrada, and the variable that is assigned to it is the CString entry. how can I save in this variable what is entered by keyboard in the edit text? and how could I visually check what is being saved? I also attach the code of how to initialize this dialog box which I think is not very well done, but it is the only one that has worked so far to be able to initialize it, this code can be found in the file NPL2017.CPP.
class CExample : public CWinApp {
public:
BOOL InitInstance();
};
class CExampleDlg : public CDialog {
public:
enum { IDD = input };
CExampleDlg();
~CExampleDlg();
};
CExampleDlg::CExampleDlg() :CDialog(CExampleDlg::IDD) {
}
CExampleDlg::~CExampleDlg() {
}
BOOL CExample::InitInstance() {
CExampleDlg myDlg;
m_pMainWnd = &myDlg;
myDlg.DoModal();
return TRUE;
}
CExample MyApp;