다음을 통해 공유


CButton::SetIcon

Call this member function to associate a new icon with the button.

HICON SetIcon(
   HICON hIcon 
);

Parameters

  • hIcon
    The handle of an icon.

Return Value

The handle of an icon previously associated with the button.

Remarks

The icon will be automatically placed on the face of the button, centered by default. If the icon is too large for the button, it will be clipped on either side. You can choose other alignment options, including the following:

  • BS_TOP

  • BS_LEFT

  • BS_RIGHT

  • BS_CENTER

  • BS_BOTTOM

  • BS_VCENTER

Unlike CBitmapButton, which uses four bitmaps per button, SetIcon uses only one icon per the button. When the button is pressed, the icon appears to shift down and to the right.

Example

CButton myIconButton2;

// Create an icon button.
myIconButton2.Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_ICON, 
   CRect(10,10,60,50), pParentWnd, 1);

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

Requirements

Header: afxwin.h

See Also

Concepts

CButton Class

CButton Members

Hierarchy Chart

CButton::GetIcon

CBitmapButton::LoadBitmaps

Bitmaps