Link to home
Start Free TrialLog in
Avatar of BRIMER
BRIMER

asked on

CFileDialog

How can you get a Cfiledialog to highligth the first file when you open a filedialog
Avatar of rajesh032097
rajesh032097

Hi,
Can you elaborate on "highlight the first file"?
ASKER CERTIFIED SOLUTION
Avatar of rhgaracci
rhgaracci

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Avatar of BRIMER

ASKER

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 ?



You awarded the points, thank you, but was your problem solved?
Avatar of BRIMER

ASKER

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 ?

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.