Yes I'm finally trying to do some MFC programming and finding out that...it's really not that difficult. So I'm smacking myself for not having tried it earlier.
I'm having one problem however with CFileDialog. I'm using the OFN_ALLOWMULTISELECT option in my common dialog box. I'd like to then retrieve all the selected file names from the dialog box.
According to MFC docs all you need to do is this:
1. Call POSITION GetStartPosition() to get the starting position
2. Call GetNextPathName(POSITION &pos) to get the next file name.
My questions are:
Does pos auto-increment inside of CFileDialog or do I have to increment it. For some reason my dialog is crashing miserably when I attempt to iterate through the list.
Code:
...
CFileDialog *AddFile=new CFileDialog(true,"*.bmp",NULL,OFN_FILEMUSTEXIST | OFN_ALLOWMULTISELECT,"BMP files (*.bmp)|*.bmp|");
int result=AddFile->DoModal();
//If user pressed ok or dialog succeeded
if (result==IDOK)
{
//Get start position
POSITION pos=AddFile->GetStartPosition();
//Setup CString for what user picked
CString UserChoice;
//Get path from dialog
UserChoice=AddFile->GetNextPathName(pos);
//Setup success/fail variable
bool bFailed=false;
//CString for comparison if path already in list
CString AlreadyInList;
while (UserChoice)
{
//Iterate through list box items amd check to see if path
//already in list
for (int i=0;i<m_lbFileList.GetCount();i++)
{
m_lbFileList.GetText(i,AlreadyInList);
if (UserChoice.Compare(AlreadyInList)==0)
{
UserChoice+=" is already in the list.";
::MessageBox(0,UserChoice,0,0);
bFailed=true;
}
}
//If path is not in list...add it to list box here
if (!bFailed)
{
m_lbFileList.AddString(UserChoice);
bFailed=false;
}
//pos++ ?????????????
UserChoice=AddFile->GetNextPathName(pos);
}
}
//Cleanup
if (AddFile) delete AddFile;
...
I still hate GUI programming but it is becoming necessary to create nifty tools and editors for my games.
Any help would be greatly appreciated.