Hi You can use the Return value of CFileDialog::DoModa(), Function. If it is IDOK the user selected a file and closed the dialog by clicking on open button and if it is IDCANCEL the dialog was closed using cancel button or X button.
if(FileDialog.DoModal() == IDOK)
CString strFilePath = FileDialog.GetPathName();
In case if you want to know allow multiple file selection Use The code,
if (FileDialog.DoModal() == IDOK)
POSITION pos = FileDialog.GetStartPosition();
while (pos != NULL)
CString strFilePath = FileDialog.GetNextPathName(pos);
Check MSDN for More info.