?
Solved

CFileDialog

Posted on 1997-04-09
7
Medium Priority
?
578 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 200 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
Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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 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…

762 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