I've enabled OFN_ALLOWMULTISELECT in my CFileDialog and
its working only if I select 8 files or less.. I used the
code below:
CFileDialog fd(true, "log", "*.log", OFN_ALLOWMULTISELECT
| OFN_FILEMUSTEXIST | OFN_HIDEREADONLY |
OFN_EXTENSIONDIFFERENT, "Log Files(*.log)", NULL);
if(fd.DoModal() == IDOK)
{
CString str;
POSITION pos;
pos = fd.GetStartPosition();
while(pos)
{
str = fd.GetNextPathName(pos);
// m_cListFiles is a CListBox object
if(m_cListFiles.FindString(0, str) == LB_ERR)
m_cListFiles.AddString(str);
}
}
Is there something wrong with this code that prevents
selecting more than 8 files?
Thanx in advance..
>
>Hi,
>
>I've enabled OFN_ALLOWMULTISELECT in my CFileDialog and
>its working only if I select 8 files or less.. I used the
>code below:
You need to allocate enough space in the lpstrFile member of the
OPENFILENAME structure that's the m_ofn member variable of the
CFileDialog. lpstrFile points to the area of memory that will contain
the names of the selected files. You also set the nMaxFile to the
length of the area that you allocated for lpstrFile.
CFileDialog fd(true, "log", "*.log", OFN_ALLOWMULTISELECT
| OFN_FILEMUSTEXIST | OFN_HIDEREADONLY |
OFN_EXTENSIONDIFFERENT, "Log Files(*.log)", NULL);
fd.m_ofn.lpstrFile = malloc(1000 * sizeof(TCHAR));
fd.m_ofn.nMaxFile = 1000;
--
Tim Slattery
MS MVP(DTS)
Slatt...@bls.gov
You need to specify a (sufficiently large) buffer as the dialog's
dlg.m_ofn.lpstrFile parameter before calling DoModal.
Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
I got the following error when I tried to do that (used
the same code as posted):
error C2440: '=' : cannot convert from 'void *' to 'char *'
Conversion from 'void*' to pointer to non-'void' requires
an explicit cast
I'm new to malloc() and memory things.. plz help.
Thanx
#define MAXMULTIPATH 600000
TCHAR* m_pszFileName;
in the ctor:
CMyFileDialog::CMyFileDialog(BOOL bOpenFileDialog, LPCTSTR lpszDefExt,
LPCTSTR lpszFileName,
DWORD dwFlags, LPCTSTR lpszFilter, CWnd* pParentWnd) :
CFileDialog(bOpenFileDialog, lpszDefExt, lpszFileName, dwFlags, lpszFilter,
pParentWnd)
{
:
:
if (m_ofn.Flags & OFN_ALLOWMULTISELECT)
{
m_pszFileName = new TCHAR[MAXMULTIPATH];
memset(pszFileName , 0, MAXMULTIPATH);
}
else
m_pszFileName = 0;
:
:
}
.. and in...
INT_PTR CMyFileDialog::DoModal()
{
ASSERT(this);
if (m_ofn.Flags & OFN_ALLOWMULTISELECT)
{
m_ofn.lpstrFile = m_pszFileName;
m_ofn.nMaxFile = MAXMULTIPATH;
}
return CFileDialog::DoModal();
}
..and..
CMyFileDialog::~CXDlg2()
{
if (m_pszFileName)
delete []m_pszFileName;
}
Rail
--------------------------------------------
Recording Engineer/Software Developer
Rail Jon Rogut Software
http://home.earthlink.net/~railro
mailto:rai...@earthlink.net
"Abed" <prg_...@hotmail.com> wrote in message
news:075301c2b5b4$2a8e6130$8df82ecf@TK2MSFTNGXA02...
CMyFileDialog::~CXDlg2() <============
{
if (m_pszFileName)
delete []m_pszFileName;
}
should read:
CMyFileDialog::~CMyFileDialog() <=========
>I got the following error when I tried to do that (used
>the same code as posted):
>
>error C2440: '=' : cannot convert from 'void *' to 'char *'
>Conversion from 'void*' to pointer to non-'void' requires
>an explicit cast
You simply need to cast the result of malloc:
fd.m_ofn.lpstrFile = (char *)malloc(1000 * sizeof(TCHAR));
> "Abed" <prg_...@hotmail.com> wrote:
>
>>error C2440: '=' : cannot convert from 'void *' to 'char *'
Sure you can, just try.
Should read 'I could convert...... ,but, I choose not to'.
Its a 'blody' feature. Hehe. Perhaps it should only be enforced in
pointer arithmetic.
*Just going bonkers behind my keyboard over here.*