Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

CFileDialog

Posted on 1997-04-09
7
Medium Priority
?
583 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
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.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

597 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