Link to home
Start Free TrialLog in
Avatar of RanBN
RanBN

asked on

CFileDialog - save preferences.

hi,
I'm implementing an advanced CFileDialog. I intend to run it a few times by a while loop. I initialize the "File Of Type" combo fieldto 4 optioins which I set their order. The user can pick one of the options, and after the user clicks OK I would like the field he picked to be the first option when the CFileDialog will be activated again. how do I save the preference of the box in the most elegant way?
an example will explain better:

CString aStr = _T("(*.a)|*.a|(*.b)|*.b|(*.c)|*.c|(*.d)|*.d||")
while (something)
{
// aStr filters the "file of type"
   CFileDialog aFileDlg(TRUE, NULL , NULL, OFN_ALLOWMULTISELECT, aStr);

if (aFileDlg.DoModal() == IDOK)
{
   ...
}

}// end of while  
the active option in the combo will be *.a, because this is what I initialized, but if the user picks *.b and clicked OK, I'd like it to be the active option in the next time CFileDialog is activated.

my intension was to keep the "File Of Type" data inside a singleton class. what should I do?
10x all,
RanBN.
Avatar of RanBN
RanBN

ASKER

Edited text of question.
for this you can make use of regitry. Under your application key create key for this dialog box. Then save the four option strings there. When you close the dialog box, then reset these four strings making the last selected string as first in list. So whenever you bring up the dialog box next time, read these option strings from registry and the first one in list will the one the user selected last time...
Hi,

Here is the working code,

static char BASED_CODE szFilter[] = "Map Files (*.a)|*.a| VSK (*.vsk)|*.vsk| Text (*.txt)|*.txt|";
      
CFileDialog fileDlg( TRUE,  
                            NULL,
            NULL,
            OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT |                             OFN_ALLOWMULTISELECT ,
            szFilter,
            NULL );      
fileDlg.m_ofn.nFilterIndex = m_Index;
if(fileDlg.DoModal() == IDOK)
{
       m_Index = fileDlg.m_ofn.nFilterIndex;
}

here m_Index is the variable used for persistance.

Check it out
Avatar of RanBN

ASKER

10x VinExpert,
your comment was the answer I needed..
RanBN.
ASKER CERTIFIED SOLUTION
Avatar of Vinayak Kumbar
Vinayak Kumbar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial