DragQueryFile filename problem
Hi, this is a really basic problem, but I hope someone can show me the correct way :)
I am handling dropped files and want to get the filename aswell as the full path...
int nFiles;
char szTemp64x[500] = {0};
char path[1024] = {0};
GetDlgItemText(hwnd, IDC_PATH, path, 1024);
switch (message)
{
case WM_DROPFILES:
nFiles = DragQueryFile((HDROP) wParam, 0xFFFFFFFF, (LPSTR) NULL, 0);
for (int i = 0; i < nFiles; i++)
{
DragQueryFile((HDROP) wParam, i, szTemp64x, 499);
char* pFile = strrchr(szTemp64x, '\\');
pFile++;
strcat(path, pFile);
UploadFile((unsigned char *)szTemp64x, (unsigned char *)path);
//Refresh files in selected dir
}
DragFinish((HDROP)wParam);
break;
}
It works OK, however if i was dopping 3 files at once for example
file#1.txt
file#1.txtfile#2.txt
file#1.txtfile#2.txtfile#3.txt
is the output i get. Is there a way to reset pFile? I assume thats the issue...
Thanks :)
[1118 byte] By [
gbrooks3] at [2007-11-20 11:35:26]

# 1 Re: DragQueryFile filename problem
What are you trying to do with pFile?
Try something like
UINT nNumOfFiles = DragQueryFile(hDropInfo, 0xFFFFFFFF, NULL, NULL);
if (nNumOfFiles > 0)
{
for (int i=0; i<nNumOfFiles; ++i)
{
CString strFile;
UINT nFilenameSize = DragQueryFile(hDropInfo, i, NULL, NULL);
DragQueryFile(hDropInfo, i, strFile.GetBuffer(nFilenameSize+1), nFilenameSize+1);
strFile.ReleaseBuffer();
// strFile contains the full path...
}
}
Marc G at 2007-11-9 13:32:49 >

# 2 Re: DragQueryFile filename problem
Another version, CString is MFC specific but above is perfect minimal code, I did not test following but is from one of my projects:
HDROP hDrop
hDrop = (HDROP)wParam;
UINT nCnt = DragQueryFile(hDrop, (UINT)-1, NULL, 0);
for(int nIndex = 0; nIndex < nCnt; ++nIndex) {
UINT nSize;
if(0 == (nSize = DragQueryFile(hDrop, nIndex, NULL, 0)))
continue;
TCHAR *pszFileName = new TCHAR[++nSize];
if(DragQueryFile(hDrop, nIndex, pszFileName, nSize)) {
next file name is in 'pszFileName', use this
}
delete [] pszFileName;
}
DragFinish(hDrop);
regards
# 3 Re: DragQueryFile filename problem
file#1.txt
file#1.txtfile#2.txt
file#1.txtfile#2.txtfile#3.txt
is the output i get. Is there a way to reset pFile? I assume thats the issue...pFile is not your problem. The problem is that you never clean up the path. This must help:
strcat(path, pFile);
UploadFile((unsigned char *)szTemp64x, (unsigned char *)path);
//Refresh files in selected dir
path[0] = '\0'; // drop the path value before next iteration