Solved

CFileDialog

Posted on 1997-04-09
7
559 Views
Last Modified: 2013-11-20
How can you get a Cfiledialog to highligth the first file when you open a filedialog
0
Comment
Question by:BRIMER
  • 4
  • 2
7 Comments
 
LVL 2

Expert Comment

by:rajesh032097
ID: 1300957
Hi,
Can you elaborate on "highlight the first file"?
0
 
LVL 1

Accepted Solution

by:
rhgaracci earned 100 total points
ID: 1300958
You need to derive a class from CFileDialog if you haven't done that already.  Then create use ClassWizard to create a message response member function for WM_INITDIALOG.  Class Wizard create the member function OnInitDialog() for you.

Edit the function to look like this:

BOOL CMyFileDlg::OnInitDialog()
{
      CFileDialog::OnInitDialog();
      
      CListBox listBox;
      listBox.Attach(GetDlgItem(lst1)->m_hWnd);
      listBox.GetCount();
      listBox.SetCurSel(0);
      listBox.Detach();
      
      return TRUE;  // return TRUE unless you set the focus to                          a control
                    // EXCEPTION: OCX Property Pages should         return FALSE
}

You will also need to add #include "dlgs.h" to the top of your .cpp file for this class.  dlgs.h contains the definition for lst1 which is the identifier for the file name list box.

0
 
LVL 1

Expert Comment

by:rhgaracci
ID: 1300959
You don't actually need the GetCount() function call.  I forgot to delete it from my source when I was testing this out.  You could also use straight Windows API calls instead of attaching and detaching the CListBox object.  I hope this works for you.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:BRIMER
ID: 1300960
I can not get it to work. I get "An Uhandled exception in ... Acces Violation"
listBox.Attach(GetDlgItem(lst1)->m_hWnd);
if I change the line to
listBox.Attach(GetParent()->GetDlgItem(lst1)->m_hWnd);
then I don't get the "An Uhandled exception in...", but I
don't get the result I want.
Maybe is it my construction of CMyFileDlg ?
Can I get the hole project ?



0
 
LVL 1

Expert Comment

by:rhgaracci
ID: 1300961
You awarded the points, thank you, but was your problem solved?
0
 

Author Comment

by:BRIMER
ID: 1300962
No the problem is not solved. I was sure it was solved, when
I saw you answer. But I can not get it to work. I am new to
the expert exchange (but it is the best thing I have found for
months), is it possible that you send your test direct to me,
so I can see why you can get it to work, and I can't
Is the 100 point you got OK ?

0
 
LVL 1

Expert Comment

by:rhgaracci
ID: 1300963
Hmmm, the code above worked for me.  It was hooked into a sample project with all sorts of other junk, so it is too big to send in its entirety.  First off, are you using VC++ version 4.1 or later?

I used class wizard to create the derived dialog class and to add the OnInitDialog() message response function.  Your .h file should look something like this:

class CMyFileDialog : public CFileDialog
{
   // constructor and other definitions go here...
};

The solution is specific to CFileDialog, and it may not work if you are using a non-standard dialog template (other than provided by MFC).  Also, are you running this app under Win95?  If so, it may not work correctly because the dialog is different.  In that case, you may need to do some extra work.

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
difference between String.subString() and String.subSequence() 6 177
ffmpeg - "rtsp://...... Operation not permitted" 4 74
changeXy challenge 13 68
Detect file exist or not 3 133
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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.

861 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now