-
August 28th, 2008, 02:58 PM
#1
CFileDialog dynamically change filter list
Is there any way to dynamically update the filter list (i.e. "Save as type") once a CFileDialog is already created?
Here is a brief run down of what I'm trying to do. Our program uses a profile system which allows you to select from a bunch of options and then save them as a file type which you can then select from the save dialog. Right now I accomplish this by simply building the filter list using the profiles before the save dialog is created, which is easy. However my boss has just requested that I add feature which allows users to create a new profile directly from within the save dialog. I have got it all working except that I can't figure out a way to add the newly created profile to the CFileDialogs filter list. Our save dialog is using an derived class with an overlay template for additional UI elements, so I have almost full control over it. But I can't seem to figure out any way to add file types to the filter list dynamically. Does anyone know how to accomplish this?
Thanks,
Dan
-
August 28th, 2008, 03:11 PM
#2
Re: CFileDialog dynamically change filter list
Have you tried modifying m_ofn.lpstrFilter?
-
August 29th, 2008, 01:20 AM
#3
Re: CFileDialog dynamically change filter list
That's what I do now before the dialog is displayed with DoModal. However I need to update the list after the dialog is already being displayed. There may be some message I can send which reparses the m_ofn.lpstrFilter string, but if there is I don't know what it is.
Dan
-
August 29th, 2008, 01:30 AM
#4
Re: CFileDialog dynamically change filter list
-
August 29th, 2008, 02:25 AM
#5
Re: CFileDialog dynamically change filter list
He's doing the same thing I am right now, which is construct the filter list in the DoModal function. What I want to do is change the filter list after the dialog is already being displayed. (i.e. after DoModal)
Dan
-
August 29th, 2008, 03:51 AM
#6
Re: CFileDialog dynamically change filter list
Did you try to directly modify the content of cmb1 combobox of the CFileDialog template?
Victor Nijegorodov
-
August 29th, 2008, 03:53 AM
#7
Re: CFileDialog dynamically change filter list
I did, and I can add text to it. However if I actually select the new item the program crashes. Presumably there is something stored in the ItemData or ItemDataPtr the dialog needs, but I'm not sure what it is.
Dan
-
August 29th, 2008, 03:59 AM
#8
Re: CFileDialog dynamically change filter list
Well, then why not to check what data other combobox items have?
Another guess: perhaps, all combo items must correspond to m_ofn.lpstrFilter string entries?
Victor Nijegorodov
-
August 29th, 2008, 04:31 AM
#9
Re: CFileDialog dynamically change filter list
I tested the other combo items and found that the ItemData is set to a BSTR with "*.ext", where ext is the file extension. So basically I can do this...
CComboBox *pWndFilesOfTypeCombo = (CComboBox*)GetParent()->GetDlgItem(cmb1);
int index = pWndFilesOfTypeCombo->AddString(_T("Filter (*.ext)"));
CString filter("*.ext");
pWndFilesOfTypeCombo->SetItemData(index, (DWORD)filter.AllocSysString());
And it seems to work.
Thanks for helping me in the right direction.
Dan
-
August 29th, 2008, 04:34 AM
#10
Re: CFileDialog dynamically change filter list
You are welcome!
And thank you for the useful information about "ItemData set to a BSTR ..."!
Victor Nijegorodov
-
September 25th, 2009, 02:20 AM
#11
Re: CFileDialog dynamically change filter list
Good day,
I have a similar problem.
I have a CFileDialog used to "Save As..." and i want to get a pointer to the "file_extension"ComboBox to see what the user selected by calling pComboBox->GetCurSel.
How is this accomplished?
Thanx in advance,
stakon
PS.
I know i can get the selected Extension with the various get methods, but i want to have multiple times the same extension in my CFileDialog.
EDIT: I used the code above and it is working well. I hadn't realized that "cmb1" is actually a defined variable name in file "dlgs.h"
Last edited by stakon; September 25th, 2009 at 04:10 AM.
-
September 25th, 2009, 11:57 AM
#12
Re: CFileDialog dynamically change filter list
You could use something like this...
CComboBox *pWndFilesOfTypeCombo = (CComboBox*)GetParent()->GetDlgItem(cmb1);
int index = pWndFilesOfTypeCombo->GetCurSel();
CString ext;
ext.SetSysString((BSTR)pWndFilesOfTypeCombo->GetItemData(index));
That will get you the index of the selected item and the extension of that selection.
Dan
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|