Home > Software engineering >  CMFCEditBrowseCtrl controls how to get file path
CMFCEditBrowseCtrl controls how to get file path

Time:09-28

I want to use MFCEditBrowseCtrl control to get the file path through the following steps to see such a piece of code on the net, I put it in the void CDrawDialog: : OnEnChangeMfceditbrowse1 (), but a scan window will pop up twice, I think because the operation of this control itself comes with pop-up on MSDN also didn't find the related code, a great god, genuflect is begged grateful!
CFileDialog FileDlg (TRUE);
If (IDOK==FileDlg. DoModal ())
{
Path=FileDlg. GetPathName ();
}

CodePudding user response:

//the Create dialog to open multiple files. 
CFileDialog DLG (TRUE, _T (" TXT "), _T (" *.txt), OFN_ALLOWMULTISELECT);

//Create buffer for file names.
Const DWORD numberOfFileNames=100;
Const DWORD fileNameMaxLength=MAX_PATH + 1;
Const DWORD bufferSize=(numberOfFileNames * fileNameMaxLength) + 1;
TCHAR * filenamesBuffer=new TCHAR [bufferSize];

//Initialize beginning and end of buffer.
FilenamesBuffer [0]=NULL;
FilenamesBuffer] [bufferSize - 1=NULL;

//the Attach buffer to OPENFILENAME member.
DLG. M_ofn. LpstrFile=filenamesBuffer;
DLG. M_ofn. NMaxFile=bufferSize;

//Create an array for file names.
Cstrings fileNameArray [numberOfFileNames];
If (DLG) DoModal ()==IDOK)
{
//Retrieve the file name (s).
The POSITION fileNamesPosition=DLG. GetStartPosition ();
Int iCtr=0;
While (fileNamesPosition!=NULL)
{
FileNameArray (iCtr)=DLG. GetNextPathName (fileNamesPosition);
ICtr++;
}
}
//Release the file names buffer.
The delete [] filenamesBuffer;



CodePudding user response:

Look good high-end, indeed as expected is a professional, but I tried it on, the browse the file dialog box will pop up twice, and before you feel thinking with me on the use of that a few words not much difference

CodePudding user response:

To answer your "minimal sample" question:
Use MFC App Wizard to generate Dialog App.
In the resource editor, drag the MFC EditBrowse Control onto the dialog.
Right - click that control, select the Add Event Handler... ; The select EN_CHANGE in the Message type: list and (optionally) change the Function handler name:.
(Optionally) right - click on the control again and select Add Variable... ; Check the Control variable checkbox if it was UN - checked; Type a Variable name:, for example m_browser.
This will add
DDX_Control (symbol, IDC_MFCEDITBROWSE1 m_browser);
To void CMFCDlgDlg: : DoDataExchange (CDataExchange * symbol),
ON_EN_CHANGE (IDC_MFCEDITBROWSE1, & amp; CMFCDlgDlg: : OnEnChangeMfceditbrowse1)
To the message map, and this method:
Void CMFCDlgDlg: : OnEnChangeMfceditbrowse1 ()
{
}
I have added this code to the demo that it works:
Void CMFCDlgDlg: : OnEnChangeMfceditbrowse1 ()
{
Cstrings STR.
M_browser. GetWindowTextW (STR);
}
  • Related