-
April 30th, 2004, 09:22 AM
#1
Need help with creating 'standard' file open dialog
Hi, I am aware there are several articles on "modifying" and "Enhancing" the standard fileOpen Dialog but I havent found anything on creating a fileopen dialog in the first place.
I dont know if you have to create all the combobox controls etc yourself or there is some pre-defined template.
Any pointers*?
-
April 30th, 2004, 09:37 AM
#2
MSDN -> Search for CFileDialog Enhancing.
If this will be not enouph then be more clear which additional features you want to implement in the standard File open/close dialog
-
April 30th, 2004, 10:09 AM
#3
It's easier than you think if you are using MFC:
Code:
CFileDialog fileDlg(TRUE, L"txt", L"foo.txt");
// Display the file dialog. When user clicks OK, fileDlg.DoModal()
// returns IDOK.
if( fileDlg.DoModal ()==IDOK )
{
CString filename = fileDlg.GetPathName();
...
}
For non-MFC it is slightly trickier, but straightforward:
Code:
OPENFILENAME ofn; // common dialog box structure
char szFile[260]; // buffer for file name
HWND hwnd; // owner window
HANDLE hf; // file handle
// Initialize OPENFILENAME
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFile = szFile;
// Set lpstrFile[0] to '\0' so that GetOpenFileName does not
// use the contents of szFile to initialize itself.
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = "Text\0*.TXT\0";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
// Display the Open dialog box.
if (GetOpenFileName(&ofn)==TRUE) {
...
ofn.lpstrFile contains the file name
}
-
April 30th, 2004, 10:13 AM
#4
Cool, its working now
It doesent like This part:
OFN_FILEMUSTEXIST| szFilters, this);
taken from
// szFilters is a text string that includes two file name filters:
// "*.my" for "MyType Files" and "*.*' for "All Files."
TCHAR CChildFrame::szFilters[]=
"_T(MyType Files (*.my)|*.my|All Files (*.*)|*.*||");
// Create an Open dialog; the default file name extension is ".my".
CFileDialog fileDlg (TRUE, _T("my"), _T("*.my"),
OFN_FILEMUSTEXIST| szFilters, this);
but i dont mind just using
map_open fileDlg (TRUE, _T("my"), _T("*.jpg"));// OFN_FILEMUSTEXIST| szFilters, this); and commenting out the "Type" filter
-
April 30th, 2004, 12:07 PM
#5
Originally posted by Vonny232
It doesent like This part:
OFN_FILEMUSTEXIST| szFilters, this);
Should be OFN_FILEMUSTEXIST , szFilters
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|