Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CFileDialog - save preferences.

Posted on 1999-07-26
5
Medium Priority
?
279 Views
Last Modified: 2013-11-20
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.
0
Comment
Question by:RanBN
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 

Author Comment

by:RanBN
ID: 1311443
Edited text of question.
0
 
LVL 23

Expert Comment

by:naveenkohli
ID: 1311444
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...
0
 
LVL 8

Expert Comment

by:VinExpert
ID: 1311445
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
0
 

Author Comment

by:RanBN
ID: 1311446
10x VinExpert,
your comment was the answer I needed..
RanBN.
0
 
LVL 8

Accepted Solution

by:
VinExpert earned 80 total points
ID: 1311447
Hi,

I am happy as it worked.
The answer is the comment that I have written above.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question