loading a file
Hi!
I''ve got a little problem.
I want to open a file through a dialog.
Can anybody help me and tell me what I have to do to create such a dialog or tell me where I can find a tutorial about this topic?
Thanx.
If you''re using MFC, you can use:
If you''re not using MFC, you can use the GetOpenFileName function, see MSDN for details.
CString BrowseForFile(CString initialDir, CString filter) { CString result; /* see msdn for how to use the filter */ CFileDialog dlg(TRUE, NULL, NULL, OFN_FILEMUSTEXIST, filter); dlg.m_ofn.lpstrInitialDir = initialDir; if(dlg.DoModal() == IDOK) { result = dlg.GetPathName(); } return result;}
If you''re not using MFC, you can use the GetOpenFileName function, see MSDN for details.
Thank you, that helped a lot.
But now, I have another problem: When I execute my programm, I get the following message:
Microsoft Visual C++ Debug Library
---------------------------
Debug Assertion Failed!
Program: H:\metricminds\Debug\metricminds.exe
File: afxwin1.inl
Line: 22
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
---------------------------
Abort Retry Ignore
When I choose ignore, the Dialog opens. How can I prevent the message?
But now, I have another problem: When I execute my programm, I get the following message:
Microsoft Visual C++ Debug Library
---------------------------
Debug Assertion Failed!
Program: H:\metricminds\Debug\metricminds.exe
File: afxwin1.inl
Line: 22
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
---------------------------
Abort Retry Ignore
When I choose ignore, the Dialog opens. How can I prevent the message?
What are you using for initialDir and filter? I suspect your filter string isn''t correct. MSDN uses this as an example of it''s format:
"Chart Files (*.xlc)|*.xlc|Worksheet Files (*.xls)|*.xls|Data Files (*.xlc;*.xls)|*.xlc; *.xls|All Files (*.*)|*.*||"
I think you can pass NULL for your filter if you want *.*
"Chart Files (*.xlc)|*.xlc|Worksheet Files (*.xls)|*.xls|Data Files (*.xlc;*.xls)|*.xlc; *.xls|All Files (*.*)|*.*||"
I think you can pass NULL for your filter if you want *.*
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement