Partager via


CStatic::SetIcon

Associates a new icon image with the static control.

HICON SetIcon(
   HICON hIcon 
);

Parameters

  • hIcon
    Handle of the icon to be drawn in the static control.

Return Value

The handle of the icon previously associated with the static control, or NULL if no icon was associated with the static control.

Remarks

The icon will be automatically drawn in the static control. By default, it will be drawn in the upper-left corner and the static control will be resized to the size of the icon.

You can use various window and static control styles, including the following:

  • SS_ICON   Use this style always for cursors and icons.

  • SS_CENTERIMAGE   Use to center in the static control. If the image is larger than the static control, it will be clipped. If it is smaller than the static control, the empty space around the image will be filled with the background color of the static control.

The CStatic object does not automatically delete the associated icon. You must delete the icon after use to avoid a memory leak.

Example

CStatic myStatic;

// Create a child icon static control.
myStatic.Create(_T("my static"), 
   WS_CHILD|WS_VISIBLE|SS_ICON|SS_CENTERIMAGE, CRect(10,10,150,50), 
   pParentWnd);

// If no icon is defined for the static control, define the icon 
// to the system error icon.
if (myStatic.GetIcon() == NULL)
   myStatic.SetIcon(::LoadIcon(NULL, IDI_ERROR));   

Requirements

Header: afxwin.h

See Also

Reference

CStatic Class

Hierarchy Chart

CStatic::GetIcon

STM_SETICON

Icons

Other Resources

CStatic Members