[CLIPBRD] Support CF_HDROP format (#5622)

This allows to see what files are being copied into clipboard.
CORE-19140
This commit is contained in:
Katayama Hirofumi MZ 2023-08-27 19:41:13 +09:00 committed by GitHub
parent 657f728767
commit f90a1956a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 1 deletions

View file

@ -358,6 +358,13 @@ static void OnPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
break;
}
case CF_HDROP:
{
GetClientRect(hWnd, &rc);
HDropFromClipboard(hdc, &rc);
break;
}
default:
{
GetClientRect(hWnd, &rc);

View file

@ -164,7 +164,8 @@ UINT GetAutomaticClipboardFormat(void)
CF_DSPBITMAP,
CF_DSPMETAFILEPICT,
CF_DSPENHMETAFILE,
CF_PALETTE
CF_PALETTE,
CF_HDROP
};
return GetPriorityClipboardFormat(uFormatList, ARRAYSIZE(uFormatList));

View file

@ -331,6 +331,45 @@ void PlayEnhMetaFileFromClipboard(HDC hdc, const RECT *lpRect)
PlayEnhMetaFile(hdc, hEmf, lpRect);
}
static LPWSTR AllocStrCat(LPWSTR psz, LPCWSTR cat)
{
INT cch;
LPWSTR pszNew;
if (psz == NULL)
return _wcsdup(cat);
cch = lstrlenW(psz) + lstrlenW(cat) + 1;
pszNew = realloc(psz, cch * sizeof(WCHAR));
if (!pszNew)
return psz;
lstrcatW(pszNew, cat);
return pszNew;
}
void HDropFromClipboard(HDC hdc, const RECT *lpRect)
{
LPWSTR pszAlloc = NULL;
WCHAR szFile[MAX_PATH + 2];
HDROP hDrop = (HDROP)GetClipboardData(CF_HDROP);
UINT iFile, cFiles = DragQueryFileW(hDrop, 0xFFFFFFFF, NULL, 0);
RECT rc = *lpRect;
FillRect(hdc, &rc, (HBRUSH)(COLOR_WINDOW + 1));
for (iFile = 0; iFile < cFiles; ++iFile)
{
DragQueryFileW(hDrop, iFile, szFile, _countof(szFile));
lstrcatW(szFile, L"\r\n");
pszAlloc = AllocStrCat(pszAlloc, szFile);
}
DrawTextW(hdc, pszAlloc, -1, &rc,
DT_LEFT | DT_NOPREFIX | DT_EXTERNALLEADING | DT_WORD_ELLIPSIS);
free(pszAlloc);
}
BOOL RealizeClipboardPalette(HDC hdc)
{
BOOL Success;

View file

@ -17,4 +17,5 @@ void BitBltFromClipboard(PAINTSTRUCT ps, SCROLLSTATE state, DWORD dwRop);
void SetDIBitsToDeviceFromClipboard(UINT uFormat, PAINTSTRUCT ps, SCROLLSTATE state, UINT fuColorUse);
void PlayMetaFileFromClipboard(HDC hdc, const RECT *lpRect);
void PlayEnhMetaFileFromClipboard(HDC hdc, const RECT *lpRect);
void HDropFromClipboard(HDC hdc, const RECT *lpRect);
BOOL RealizeClipboardPalette(HDC hdc);