Solved

CFileDialog

Posted on 1997-04-09
7
572 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
[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
  • 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
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!

 

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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

691 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