This method returns information about a specific download and is
typically called in the context of a download event handler. The
dwFileId parameter identifies the download to be queried.
This identifier can be obtained either through download-related
event notifications, where it is provided as the lParam value,
or by calling the EnumDownloads method to enumerate
active and completed downloads.
The file identifier should be treated as an opaque value. While it
is guaranteed to be unique for the lifetime of the client session,
the underlying implementation simply assigns sequential values.
Applications must not depend on this behavior, as the specific
numbering scheme may change in future versions. Because the identifiers
are only unique within a single session, they cannot be used after the
browser instance has been detached or destroyed. If you need to track
downloads across sessions, you should use the file name or URL rather
than the internal identifier.
Information is returned in the WEBVIEW_DOWNLOAD_INFO
structure, which includes the download status, number of bytes copied,
total size, elapsed time, file name, and the source URL. If the
specified identifier does not correspond to a valid download, the
function will fail.
If you are only interested in the name of the local file used for
the specified download, you can use the GetDownloadPath
function.
INT nTotal = pWebView->EnumDownloads();
if (nTotal <= 0)
{
_tprintf(_T("No downloads found.\n"));
return;
}
DWORD *pIds = (DWORD*)malloc(nTotal * sizeof(DWORD));
if (!pIds)
return;
INT nCount = pWebView->EnumDownloads(pIds, nTotal);
for (INT nIndex = 0; nIndex < nCount; nIndex++)
{
WEBVIEW_DOWNLOAD_INFO fileInfo = { sizeof(fileInfo) };
if (pWebView->GetDownloadInfo(pIds[nIndex], &fileInfo))
{
_tprintf(_T("Download %u: %s (%llu/%llu bytes)\n"),
fileInfo.dwFileId,
fileInfo.szFileName,
fileInfo.uiBytesCopied.QuadPart,
fileInfo.uiBytesTotal.QuadPart);
}
}
free(pIds);