CWebView::SetIcon Method  
 
BOOL SetIcon(
  HINSTANCE hResInst,  
  LPCTSTR lpszIconName,  
  UINT uResId,  
  DWORD dwFlags  
);
BOOL SetIcon(
  LPCTSTR lpszIconName,  
  DWORD dwFlags  
);

The SetIcon method sets custom large and small icons for the host window.

Parameters

hResInst
Handle to the module instance that contains the icon resource. If this parameter is NULL, the lpszIconName parameter should specify the path to an icon file.
lpszIconName
A null-terminated string that specifies the name of the icon resource or a path to an icon file. If this parameter is not NULL, it takes precedence over uResId.
uResId
An unsigned integer which specifies the numeric identifier of the icon resource within the module. This is used when lpszIconName is NULL.
dwFlags
An unsigned integer which specifies which icons to update. This must be one or more of the values shown in the following table.
Value Description
WEBVIEW_ICON_BIG Update the large window icon.
WEBVIEW_ICON_SMALL Update the small window icon.
WEBVIEW_ICON_BOTH Update both large and small icons.
WEBVIEW_ICON_DPI_AWARE Choose the system-recommended small icon size for the current DPI when possible.

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

The SetIcon method updates the large and/or small icons associated with the host window created using the Create or Create method. This is equivalent to sending the WM_SETICON message to the host window, but automatically handles both the large and small icons and supports DPI-aware sizing when requested.

If the hRetInst parameter is not NULL, either a string resource name (lpszIconName) or a numeric resource identifier (uResId) can be specified to identify the icon. If both are provided, the string resource name takes precedence. The resource must exist in the module instance specified by hResInst. If neither lpszIconName nor uResId resolves to a valid icon, the method fails.

if the hResInst parameter is NULL, the lpszIconName parameter must specify the name of a file which contains the icon and the uResId parameter is ignored. It is recommended that you provide an absolute path to the icon file. If the path includes environment variables surrounded with percent (%) symbols, those variables will be automatically expanded. The file must use the standard Windows icon format.

The dwFlags parameter determines which icons are updated. You can set the large icon (used in the Alt-Tab interface and title bar), the small icon (shown in the window caption and taskbar), or both. If WEBVIEW_ICON_DPI_AWARE is specified, the system will choose an appropriate small icon size based on the current display scaling.

Windows icons are stored in the standard .ico file format, which can contain one or more images at different resolutions and color depths. When you compile icons into your application's resources and reference them by name or identifier, Windows will automatically select the most appropriate image for the current display settings. This allows a single icon resource to provide 16x16, 32x32, 48x48, or higher-resolution images within the same file.

The operating system chooses which image to use based on context and DPI scaling. For example, a 16x16 version may be displayed in a window caption or taskbar, while a 32x32 or 48x48 version may be shown in the Alt-Tab interface or Windows Explorer. If WEBVIEW_ICON_DPI_AWARE is specified, the system can pick a small-icon size that best matches the current DPI rather than always defaulting to 16x16.

Calling this method does not destroy the icon resource itself; ownership remains with the module that loaded it. If you dynamically create icons at runtime using CreateIcon or LoadImage, you are responsible for releasing them with DestroyIcon if they are no longer needed.

This method can only be used with windows created by this library, it cannot be used with windows you attach the browser to using the Attach method.

Example

// Define the path to the application's icon file
LPCTSTR pszIconFile = _T("%LocalAppData%\\MyApp\\MyApp.ico");

if (pWebView->Create(_T("about:blank"))
{
    // Set both large and small icons for the WebView host window
    pWebView->SetIcon(pszIconFile, WEBVIEW_ICON_BOTH | WEBVIEW_ICON_DPI_AWARE);
}

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