What's new

mfc open dialg question

mesman00

What's that...?
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

Active member
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.
 
Last edited:

smcd

Active member
You can look up OPENFILENAME in google, click the first link, if you need more information about other member items.
 

Doomulation

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

Active member
Doomulation said:
*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

New member
Actually, here's a little snippet which might help you from NeoGameBoy:

Code:
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();
}
 

Top