[2992]
サンプル
wmlhq
開発が停滞しているようだから、ヒントをあげます。
typedef BOOL (FAR * ENUMFILEPROC)(LPCTSTR lpszFileTitle, LPWIN32_FIND_DATA lpw32fd, LPARAM lParam)
BOOL EnumFiles(LPCTSTR lpszSpec, ENUMFILEPROC lpfn, LPARAM lParam)
{
WIN32_FIND_DATA w32fd;
HANDLE hFind = FindFirstFile(lpszSpec, &w32fd);
if(hFind != INVALID_HANDLE_VALUE) {
do {
// Ignore _T(".") and _T("..").
if(PathIsTrivial(lpszSpec, &w32fd))
continue;
if(!(*lpfn)(lpszSpec, &w32fd, lParam))
break;
} while(FindNextFile(hFind, &w32fd));
return FindClose(hFind);
}
return FALSE;
}
BOOL EnumDirListFiles(LPCTSTR lpszDir, ENUMFILEPROC lpfn, LPARAM lParam)
{
int cchDirLen = hq_strlen(lpszDir);
if(lpszDir[cchDirLen - 1] == '\\')
cchDirLen--;
int cchMax = cchDirLen + (2 + 1); // hq_strlen("\\*") == 2.
LPTSTR lpszSpec = (LPTSTR)hq_malloc(cchMax * sizeof(TCHAR));
if(lpszSpec != NULL) {
hq_strcpy(lpszSpec, lpszDir);
hq_strcpy(lpszSpec + cchDirLen, _T("\\*"));
BOOL fResult = EnumFiles(lpszSpec, lpfn, lParam);
hq_free(lpszSpec);
return TRUE;
}
return FALSE;
}
// BOOL EnumDropedFileProc(LPCTSTR lpszFile, OPTIONAL LPPOINT lppt, LPARAM lParam);
typedef BOOL (FAR * ENUMDROPEDFILEPROC)(LPCTSTR lpszFile, OPTIONAL LPPOINT lppt, LPARAM lParam);
BOOL EnumDroppedFiles(HDROP hdrop, ENUMDROPEDFILEPROC lpfn, LPARAM lParam)
{
if(hdrop == NULL) {
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
DWORD dwError = 0;
int cchMax = MAX_PATH;
LPTSTR lpszFile = (LPTSTR)hq_malloc(cchMax * sizeof(TCHAR));
if(lpszFile != NULL) {
POINT pt;
LPPOINT lppt = (DragQueryPoint(hdrop, &pt) ? &pt : NULL);
UINT cFiles = DragQueryFile(hdrop, 0xFFFFFFFF, NULL, 0);
for(UINT uIndex = 0 ; uIndex < cFiles ; uIndex++) {
int cchMaxNew = DragQueryFile(hdrop, uIndex, NULL, 0) + 1;
if(cchMax < cchMaxNew) {
cchMax = cchMaxNew;
lpszFile = (LPTSTR)hq_realloc(lpszFile, cchMaxNew * sizeof(TCHAR));
}
if(DragQueryFile(hdrop, uIndex, lpszFile, cchMax)) {
if(!(*lpfn)(lpsz, lppt, lParam))
break;
} else dwError = GetLastError();
} else dwError = GetLastError();
hq_free(lpszFile);
} else dwError = GetLastError();
SetLastError(dwError);
return dwError != 0;
}