CWebView::GetDownloadInfo Method  
 
BOOL GetDownloadInfo(
  DWORD dwFileId,  
  WEBVIEW_DOWNLOAD_INFO *lpInfo  
);

The GetDownloadInfo method returns information about the status of the specified download.

Parameters

dwFileId
An unsigned integer value which uniquely identifies the download. This value cannot be zero.
lpInfo
A pointer to a WEBVIEW_DOWNLOAD_INFO structure which will contain information about the specified download when the method returns. The dwSize member of this structure must be initialized to the size of the structure prior to being passed to this method.

Return Value

If the method succeeds, the return value is non-zero. If the method fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

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.

Example

// Get the total number of downloads
INT nTotal = pWebView->EnumDownloads();

if (nTotal <= 0)
{
    _tprintf(_T("No downloads found.\n"));
    return;
}

// Allocate a buffer for the identifiers
DWORD *pIds = (DWORD*)malloc(nTotal * sizeof(DWORD));
if (!pIds)
    return;

INT nCount = pWebView->EnumDownloads(pIds, nTotal);

// Enumerate each download and print basic info
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);

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: cshtmv12.lib
Unicode: Implemented as Unicode and ANSI versions

See Also