Solved

CFileDialog

Posted on 1997-04-09
7
556 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

11 Experts available now in Live!

Get 1:1 Help Now