Advertisement

loading a file

Started by May 22, 2003 07:29 AM
4 comments, last by snow21 21 years, 9 months ago
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:

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.
Brianmiserere nostri Domine miserere nostri
Advertisement
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?
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 *.*

Brianmiserere nostri Domine miserere nostri
Even if I use the example of MSDN I get the error message.
Try using this as filter: "All Files (*.*)|*.*||"

if it won''t help, you should look into program what caused assertion. Go through application stack until you get to you''re code.

This topic is closed to new replies.

Advertisement