How to get path text from CMFCEditBrowseCtrl?

I am working on a win32 MFC project. I have a dialog with two CMFCEditBrowseCtrl controls. After the user indicates the files of these controls, how do I get the file paths from these controls?

Update: here is my code

SpecifyInputDialog dlg; // this is my dialog inherited from CDialogEx
dlg.DoModal();
CString strText;
dlg.inFileCtrl.GetWindowTextA(strText.GetBuffer(), 500); // inFileCtrl is CMFCEditBrowseCtrl object

Results in the "Debug Assertion Failed" error on the last line ...

Update 2:

CString strText;
dlg.inFileCtrl.GetWindowText(strText);

The same error is "Debugging Error". I will try to get the text until the dialog is tried.

Update 3 (solution):

I managed to get the path text by doing a callback

BEGIN_MESSAGE_MAP(SpecifyInputDialog, CDialogEx)
  ON_EN_CHANGE(IDC_MFCEDITBROWSE1, &SpecifyInputDialog::OnEnChangeMfceditbrowse1)
END_MESSAGE_MAP()  

And in the handler method:

void SpecifyInputDialog::OnEnChangeMfceditbrowse1()
{
    this->inFileCtrl.GetWindowText(this->inFileString);
}

So, your idea that the text was not yet closed during the dialogue was right. Please update your answer so that I could mark it as a solution.

+5
3

CMFCEditBrowseCtrl CEdit, GetWindowText/SetWindowText .

:

 CString strText;
 dlg.inFileCtrl.GetWindowText(strText);

( , ). , .

+4

dlg. ( ).GetWindowTextA AFTER DoModal - ( ) . MFC DDX ( CString) OnOk - .

0

, DoModal(), GetWindowTextA - , . MFC DDX. , SpecifyInputDialog, " " ( - "" ), " ". "" " ". CMFCEditBrowseCtrl CString. CString (, inFileText), - . :

SpecifyInputDialog dlg; // this is my dialog inherited from CDialogEx
dlg.DoModal();
CString strText;
strText = dlg.inFileText; // after the data exchange, this has what you need

DDX, , :

void SpecifyInputDialog::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
    DDX_Text(pDX, IDC_BROWSE, inFileText);
}
0
source

All Articles