Tuesday, March 3, 2009

[VC++] Open file dialog using GetFileNameFromBrowse()

You may be familiar with the File Open Dialog in application such as notepad, do you know how to make the same ? Its simple with a shell API GetFileNameFromBrowse() which is a wrapper of GetOpenFileName(). See the below code and see the appearance of the File open dialog in vista,
wchar_t wszFilepath[MAX_PATH] = L"C:\\";

if( GetFileNameFromBrowse( GetSafeHwnd(),
wszFilepath, // Default File Path
MAX_PATH, // Size of file path
NULL, // Working Directory
NULL, // Default Extension
L"*.*", // Filters
L"Open Me" ))// Dialog Title
{
// Show user selected file name/path in a message box
MessageBox( CString( wszFilepath ));
}
See the File Open dialog shown on excuting the above code

No comments: