When copying files in the Windows Explorer, the names are stored in multiple clipboard formats. To retrieve the names you may use the pre-defined
CF_HDROP
format. Other formats are not pre-defined, but registered like
CFSTR_FILENAMEW
(single file name / first of list as wide char string),
CFSTR_FILENAMEA
(single file name / first of list as ANSI string in 8.3 format), and
CFSTR_SHELLIDLIST
. See also
Shell Clipboard Formats[
^] in the MSDN.
To get the first name from a CF_HDROP object:
TCHAR lpszFileName[MAX_PATH];
OpenClipboard();
HGLOBAL hGlobal = (HGLOBAL)GetClipboardData(CF_HDROP);
if (hGlobal)
{
HDROP hDrop = (HDROP)GlobalLock(hGlobal);
if (hDrop)
{
DragQueryFile(hDrop, 0, lpszFileName, MAX_PATH);
GlobalUnlock(hGlobal);
}
}
CloseClipboard();