Click here to Skip to main content
15,887,430 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hey Guys,

i'm using a CCommonDlg Dialog to show a FileOpen/Save Dialog in our Application.
My forerunner in this company implemented this Dialog and i have to add some functionality now.

He had done a lot of stuff and methods in this, but the main part is in the DoModal() Function.
Here he calls ::GetOpenFileName() or ::GetSaveFileName() and pass an OPENFILENAME structure as parameter:

INT nResult;
if( m_bOpenFileDialog )
    nResult = ::GetOpenFileName( &m_ofn );
else
    nResult = ::GetSaveFileName( &m_ofn );


My "problem" is now, that in the OPENFILENAME structure is already an initial filename set.
When the dialog now shows, the file-chooser shows the beginning of the file list and not the previous in m_ofn specified initial file name.
The User has to scroll down to the selected file like this:
http://img842.imageshack.us/img842/7753/blvp.png[^].

Is there a way to automatically scroll to the selected item?

Thank you so much for answers!
Posted
Updated 31-Jan-14 2:57am
v2

try to get the ID or name of the list view per Spy++.

Use FindWindow to get the handle and than use the list view api by posting the LVM_SETSELECTIONMARK. A problem can be to find the right item. May you have to loop trough all...

http://msdn.microsoft.com/en-us/library/aa933027.aspx[^]
 
Share this answer
 
This article overlaps part of your question:

Implementing a Read-Only 'File Open' or 'File Save' Common Dialog[^]

Scroll down to the article's screenshot of a file open dialog. See the list view control?

http://www.codeproject.com/KB/dialog/DavidKotchanFileDialog/FileOpen_Layout.gif[^]

Obtain the window handle to the list view. The linked article has code to do that. With that handle, you can subclass the list view control inside the file open dialog. From there, you can manipulate the list control to have the file preselected for the user.

The MFC C++ wrapper for the SysListView32 control includes searching items, selecting an item, and determining whether an item is visible.
 
Share this answer
 
Comments
C3D1 19-Feb-14 4:17am    
The Article you submitted look good and i think this is the way i should do it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900