Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get path text from CMFCEditBrowseCtrl?

I'm working on MFC win32 project. I have dialog with 2 CMFCEditBrowseCtrl controls. After user specifies files on these controls, how to get 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 "Debug Assertion Failed" error on last line...

Update 2:

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

The same "Debug Assertion Failed" error. I will try to get text while dialog not dissmissed.

Update 3 (solved):

I managed to get path text by implementing callback

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

And in handler method:

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

So your thought about getting text while dialog are not closed yet was right. Please update your answer thus I could mark it as solution.

like image 707
M.Y. Avatar asked Oct 08 '22 23:10

M.Y.


1 Answers

CMFCEditBrowseCtrl is extended from CEdit and you can use GetWindowText / SetWindowText to access the currently displayed filename.

Update

Just do:

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

The failed assertion could be due to any number of reasons (trace into it to see the cause). You may have to grab the text in the dialog code before the dialog closes.

like image 130
uesp Avatar answered Oct 13 '22 11:10

uesp