To ask the user information via keyboard
-
Hello I want to ask information via keyboard the user. I did a dialog with edit control, this dialog let me to ask the name of the file when the user will kept information. I made this, but not run Code:
void CDlgResultados::OnBnClickedButton1()
{CDlgSaveLoad dlgSL1; if(dlgSL1.DoModal()==IDOK) { dlgSL1.GetDlgItemText(IDC\_EDIT1, nombre); } SaveToFile();
}
App is in mfc. The error appear in dlgSL1.GetDlgItemText(IDC_EDIT1, nombre);
-
Hello I want to ask information via keyboard the user. I did a dialog with edit control, this dialog let me to ask the name of the file when the user will kept information. I made this, but not run Code:
void CDlgResultados::OnBnClickedButton1()
{CDlgSaveLoad dlgSL1; if(dlgSL1.DoModal()==IDOK) { dlgSL1.GetDlgItemText(IDC\_EDIT1, nombre); } SaveToFile();
}
App is in mfc. The error appear in dlgSL1.GetDlgItemText(IDC_EDIT1, nombre);
(I will only give partial answer, just to get you going... look for tutorials/sample/example for more complete code and/or documentation) You cannot access dialog control before a DoModal (the controls are not created yet) or after a DoModal (the control were destroyed). In your dlgSL1 dialog code, add a CString variable and "attach" it to the CEdit (IDC_EDIT1) with DDX_Control with something like:
DDX_Control(pDX, IDC_EDIT1, m_YouStringVariable);
This can be done manually or with the wizard or the properies (I think); when that is working properly, you can set/get the variable from the parent dialog (in your case: CDlgResultados::OnBnClickedButton1)
if(dlgSL1.DoModal()==IDOK)
{
nombre= dlgSL1.m_YourStringVariable;
}Another way is to override the CDialog::OnOK in the CDlgSaveLoad class and in there, you can get the string from the CEdit and put it in an intermediate variable:
void CDlgSaveLoad::OnOK()
{
// m_YourEdit is a member variable of type CEdit
// m_YourStringVariable is a member variable of type CString.
m_YourEdit.GetWindowText(m_YourStringVariable);CDialog::OnOK();
}and the code in CDlgResultados::OnBnClickedButton1 will be similar as above. Max.
Watched code never compiles.
-
(I will only give partial answer, just to get you going... look for tutorials/sample/example for more complete code and/or documentation) You cannot access dialog control before a DoModal (the controls are not created yet) or after a DoModal (the control were destroyed). In your dlgSL1 dialog code, add a CString variable and "attach" it to the CEdit (IDC_EDIT1) with DDX_Control with something like:
DDX_Control(pDX, IDC_EDIT1, m_YouStringVariable);
This can be done manually or with the wizard or the properies (I think); when that is working properly, you can set/get the variable from the parent dialog (in your case: CDlgResultados::OnBnClickedButton1)
if(dlgSL1.DoModal()==IDOK)
{
nombre= dlgSL1.m_YourStringVariable;
}Another way is to override the CDialog::OnOK in the CDlgSaveLoad class and in there, you can get the string from the CEdit and put it in an intermediate variable:
void CDlgSaveLoad::OnOK()
{
// m_YourEdit is a member variable of type CEdit
// m_YourStringVariable is a member variable of type CString.
m_YourEdit.GetWindowText(m_YourStringVariable);CDialog::OnOK();
}and the code in CDlgResultados::OnBnClickedButton1 will be similar as above. Max.
Watched code never compiles.
+5 for the answer!
-
+5 for the answer!
Thank you very much. + 10 for the answer. Here is the answer :
void CDlgSaveLoad::OnBnClickedOk()
{
CDialogEx::OnOK();
m_Edit.GetWindowText(m_strData);
}void CDlgResultados::OnBnClickedButton1()
{
CDlgSaveLoad mDlg;
if ( mDlg.DoModal() == IDOK )
{
nombre= mDlg.getData();
}
SaveToFile();
} -
Thank you very much. + 10 for the answer. Here is the answer :
void CDlgSaveLoad::OnBnClickedOk()
{
CDialogEx::OnOK();
m_Edit.GetWindowText(m_strData);
}void CDlgResultados::OnBnClickedButton1()
{
CDlgSaveLoad mDlg;
if ( mDlg.DoModal() == IDOK )
{
nombre= mDlg.getData();
}
SaveToFile();
}Swap the two lines in
OnBnClickedOk
. and I assume thatnombre= mDlg.getData();
will return
m_strData
?Watched code never compiles.
-
Swap the two lines in
OnBnClickedOk
. and I assume thatnombre= mDlg.getData();
will return
m_strData
?Watched code never compiles.
Yes, I forgot write here the method :
public:
CString getData() const { return m_strData; } -
Yes, I forgot write here the method :
public:
CString getData() const { return m_strData; }I'm sorry, I have another question. When I show something in Edit control, it appear selected in hightlight blue, how can I modify it?? I'd like that only appear the text but not hightlight
-
I'm sorry, I have another question. When I show something in Edit control, it appear selected in hightlight blue, how can I modify it?? I'd like that only appear the text but not hightlight
antonio343 wrote:
When I show something in Edit control, it appear selected in hightlight blue, how can I modify it??
have a look at CEdit::SetSel[^] M.
Watched code never compiles.
-
antonio343 wrote:
When I show something in Edit control, it appear selected in hightlight blue, how can I modify it??
have a look at CEdit::SetSel[^] M.
Watched code never compiles.
Ok, but I didn't call this function in my code, and the text appear selected blue when I show the text. I don't want that the text appear selected I use to show and get the text GetDlgItemText/SetDlgItemText Could be this the problem?
-
Ok, but I didn't call this function in my code, and the text appear selected blue when I show the text. I don't want that the text appear selected I use to show and get the text GetDlgItemText/SetDlgItemText Could be this the problem?
I think that the problen is setfocus() I call this function an it select all the text. I need that the text will be showed without higlight