Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CFileDialog OFN_ALLOWMULTISELECT

155 views
Skip to first unread message

Abed

unread,
Jan 6, 2003, 11:59:46 AM1/6/03
to

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:

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..

Tim Slattery

unread,
Jan 6, 2003, 12:30:05 PM1/6/03
to
"Abed" <prg_...@hotmail.com> wrote:

>
>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

David Lowndes

unread,
Jan 6, 2003, 12:27:13 PM1/6/03
to
>I've enabled OFN_ALLOWMULTISELECT in my CFileDialog and
>its working only if I select 8 files or less.

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

Abed

unread,
Jan 6, 2003, 1:48:13 PM1/6/03
to
>.
>

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

Rail Jon Rogut

unread,
Jan 6, 2003, 2:40:30 PM1/6/03
to
I have a class derived from CFileDialog, I use:

#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...

Rail Jon Rogut

unread,
Jan 6, 2003, 2:48:02 PM1/6/03
to
Whoops.. I didn't rename something..

CMyFileDialog::~CXDlg2() <============
{
if (m_pszFileName)
delete []m_pszFileName;
}

should read:

CMyFileDialog::~CMyFileDialog() <=========

Tim Slattery

unread,
Jan 6, 2003, 4:07:20 PM1/6/03
to
"Abed" <prg_...@hotmail.com> wrote:


>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));

Sam

unread,
Jan 6, 2003, 10:34:52 PM1/6/03
to

Tim Slattery wrote:

> "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.*

0 new messages