tags:

views:

25

answers:

1
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?

+1  A: 

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.

Bob Moore
I want to retrieved "user selected extension description". Please note that, there are two extension description for a same ".xls"
Yan Cheng CHEOK
There's no direct API, you'll have to retrieve the filter string as I described and parse it out.
Bob Moore
I use OPENFILENAME to retrieve the selected index : ofn.nFilterIndex
Yan Cheng CHEOK