Reputation: 42870
CFileDialog fileDialog(
FALSE, // We are save as file dialog.
_T("*.txt"), // Default save as text format.
_T("hello"),
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
_T("Text Files (*.*)|*.txt|Excel Files (*.xls)|*.xls|Excel Details Files|(*.xls)||"),
this);
// Returns me "xls".
const CString fileExtension = fileDialog.GetFileExt();
// Returns me "Excel Files" or "Excel Details Files"
???
What is the correct way for me to obtain the file extension description?
Upvotes: 2
Views: 2085
Reputation: 6894
You're trying to retrieve the description you sent to the API yourself...? You could retrieve it from the internal OPENFILENAME structure using the member CFileDialog::GetOFN and look at the lpstrFilter member of the structure, but you'd have to parse the string yourself.
But the API SHGetFileInfo should be able to retrieve the registered file type description for the operating system. Pass "*.xls" (or whatever extension you want) to it.
Upvotes: 1