View Full Version : mfc open dialg question
mesman00
July 27th, 2004, 20:07
i'm using the CFileDialog class to create an open dialog box. here is my question. i wanna set the file filter types, but i am unsure how to do it. i know i need to use the m_ofn struct, and the lpstrFilter member flag. but i don't know how to initialize the flag so it displays properly in the combo box of the open dialog box. i want to use the flag to filter out the following two file types:
structured report files with the .dcm extension
text files with the .txt extension
these two things should be the two options in the combo box. so, how should i initialize the lpstrFilter flag. the name of my CFileDialog object is m_OpenDialog. thus
m_OpenDialog->m_ofn.lpstrFiler = ?
what should be in place of the ?
smcd
July 27th, 2004, 21:50
This should do it:
m_ofn.lpstrFilter="Text Files(*.txt)\0*.txt\0Structured Report Files(*.dcm)\0*.dcm\0\0";
The stuff in ( ) aren't necessary, but it is nice to see the extension for each file type anyhow... it's a matter of personal preference.
The format in general is:
Description \NULL Extension Filter \NULL ... and the last entry ends with 2 NULL
You can specify more than one extension at a time, for example:
"Any valid file\0*.txt;*.dcm\0\0"
Just separate each extension filter with a semicolon.
mesman00
July 28th, 2004, 22:32
thanks, couldn't find that anywhere on msdn.
smcd
July 29th, 2004, 01:17
You can look up OPENFILENAME in google, click the first link, if you need more information about other member items.
Doomulation
August 25th, 2004, 08:19
*cough* revives thread *cough* :whistling
In MFC's class, you use extensions such as this:
"*.ext|description|*.new ext|description||"
At the end you use two |.
With pure win32, you use \0.
I hope you already didn't know that...
smcd
August 25th, 2004, 08:31
*cough* revives thread *cough* :whistling
In MFC's class, you use extensions such as this:
"*.ext|description|*.new ext|description||"
At the end you use two |.
With pure win32, you use \0.
I hope you already didn't know that...
I don't use MFC! Muwhahahaha! :evil:
zenogais
August 25th, 2004, 09:06
Actually, here's a little snippet which might help you from NeoGameBoy:
afx_msg VOID MFCWindow::OnFileOpen()
{
//======================================== ====================
// Prompt the user for the ROM file to load.
//======================================== ====================
TCHAR filter[] = "Gameboy ROM (*.GB)|*.GB|Gameboy Color ROM (*.GBC)|*.GBC||";
CFileDialog fileDialog(true, 0, 0, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, filter, this);
fileDialog.DoModal();
//======================================== ====================
// Load the ROM file into memory.
//======================================== ====================
CString file = fileDialog.GetPathName();
MessageBox(file);
mGameboy.loadGame( file.GetBuffer() );
file.ReleaseBuffer();
}
Doomulation
August 25th, 2004, 12:21
Damn, I think I swapped them again :yucky:
So confusing and hard to remember... :blush:
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.