# wxIcon Class Reference
[Graphics Device Interface (GDI)]

`#include </home/work/projects/wx/2.9/wx/interface/wx/icon.h>`

Inheritance diagram for wxIcon:
[legend]

## Detailed Description

An icon is a small rectangular bitmap usually used for denoting a minimized application.

It differs from a wxBitmap in always having a mask associated with it for transparent drawing. On some platforms, icons and bitmaps are implemented identically, since there is no real distinction between a wxBitmap with a mask and an icon; and there is no specific icon format on some platforms (X-based applications usually standardize on XPMs for small bitmaps and icons). However, some platforms (such as Windows) make the distinction, so a separate class is provided.

Remarks:
  It is usually desirable to associate a pertinent icon with a frame. Icons can also be used for other purposes, for example with wxTreeCtrl and wxListCtrl. Icons have different formats on different platforms therefore separate icons will usually be created for the different environments. Platform-specific methods for creating a wxIcon structure are catered for, and this is an occasion where conditional compilation will probably be required. Note that a new icon must be created for every time the icon is to be used for a new window. In Windows, the icon will not be reloaded if it has already been used. An icon allocated to a frame will be deleted when the frame is deleted. For more information please see Bitmaps and Icons.

##

Library: wxCore
Category: Graphics Device Interface (GDI)

Predefined objects/pointers: wxNullIcon

See also:
  Bitmaps and Icons, Supported Bitmap File Formats, wxDC::DrawIcon, wxCursor

## Public Member Functions

| wxIcon ()
| Default ctor.
| wxIcon (const wxIcon &icon)
| Copy ctor.
| wxIcon (const char bits[], int width, int height)
| Creates an icon from an array of bits.
| wxIcon (const char *const *bits)
| Creates a bitmap from XPM data.
| wxIcon (const wxString &name, wxBitmapType type=wxICON_DEFAULT_TYPE, int desiredWidth=-1, int desiredHeight=-1)
| Loads an icon from a file or resource.
| wxIcon (const wxIconLocation &loc)
| Loads an icon from the specified location.
virtual | ~wxIcon ()
| Destructor.
wxIcon | ConvertToDisabled (unsigned char brightness=255) const
| Returns disabled (dimmed) version of the icon.
void | CopyFromBitmap (const wxBitmap &bmp)
| Copies bmp bitmap to this icon.
int | GetDepth () const
| Gets the colour depth of the icon.
int | GetHeight () const
| Gets the height of the icon in pixels.
int | GetWidth () const
| Gets the width of the icon in pixels.
virtual bool | IsOk () const
| Returns true if icon data is present.
bool | LoadFile (const wxString &name, wxBitmapType type=wxICON_DEFAULT_TYPE, int desiredWidth=-1, int desiredHeight=-1)
| Loads an icon from a file or resource.
void | SetDepth (int depth)
| Sets the depth member (does not affect the icon data).
void | SetHeight (int height)
| Sets the height member (does not affect the icon data).
void | SetWidth (int width)
| Sets the width member (does not affect the icon data).
wxIcon & | operator= (const wxIcon &icon)
| Assignment operator, using Reference Counting.

List of all members.

## Constructor & Destructor Documentation

wxIcon::wxIcon | ( |  | ) |

Default ctor.

Constructs an icon object with no data; an assignment or another member function such as LoadFile() must be called subsequently.

wxIcon::wxIcon | ( | const wxIcon & | icon | ) |

Copy ctor.

wxIcon::wxIcon | ( | const char | bits[],
|  | int | width,
|  | int | height |
| ) |  |  |

Creates an icon from an array of bits.

You should only use this function for monochrome bitmaps (depth 1) in portable programs: in this case the bits parameter should contain an XBM image.

For other bit depths, the behaviour is platform dependent: under Windows, the data is passed without any changes to the underlying CreateBitmap() API. Under other platforms, only monochrome bitmaps may be created using this constructor and wxImage should be used for creating colour bitmaps from static data.

Parameters:

  | bits | Specifies an array of pixel values.
  | width | The width of the image.
  | height | The height of the image.

wxPerl Note: In wxPerl use Wx::Icon->newBits(bits, width, height, depth = -1);

Availability: only available for the wxMSW, wxOSX ports.

wxIcon::wxIcon | ( | const char *const * | bits | ) |

Creates a bitmap from XPM data.

To use this constructor, you must first include an XPM file. For example, assuming that the file mybitmap.xpm contains an XPM array of character pointers called mybitmap:

            #include "mybitmap.xpm"
            ...
            wxIcon *icon = new wxIcon(mybitmap);

A macro, wxICON, is available which creates an icon using an XPM on the appropriate platform, or an icon resource on Windows.

            wxIcon icon(wxICON(sample));

            // Equivalent to:
            #if defined(__WXGTK__) || defined(__WXMOTIF__)
            wxIcon icon(sample_xpm);
            #endif

            #if defined(__WXMSW__)
            wxIcon icon("sample");
            #endif

wxPerl Note: In wxPerl use Wx::Icon->newFromXPM(data).

wxIcon::wxIcon | ( | const wxString & | name,
|  | wxBitmapType | type = `wxICON_DEFAULT_TYPE`,
|  | int | desiredWidth = `-1`,
|  | int | desiredHeight = `-1` |
| ) |  |  |

Loads an icon from a file or resource.

Parameters:

  | name | This can refer to a resource name or a filename under MS Windows and X. Its meaning is determined by the type parameter.
  | type | May be one of the wxBitmapType values and indicates which type of bitmap should be loaded. See the note in the class detailed description. Note that the wxICON_DEFAULT_TYPE constant has different value under different wxWidgets ports. See the icon.h header for the value it takes for a specific port.
  | desiredWidth | Specifies the desired width of the icon. This parameter only has an effect in Windows where icon resources can contain several icons of different sizes.
  | desiredHeight | Specifies the desired height of the icon. This parameter only has an effect in Windows where icon resources can contain several icons of different sizes.

See also:
  LoadFile()

wxIcon::wxIcon | ( | const wxIconLocation & | loc | ) |

Loads an icon from the specified location.

virtual wxIcon::~wxIcon | ( |  | ) | `[virtual]`

Destructor.

See Object Destruction for more info.

If the application omits to delete the icon explicitly, the icon will be destroyed automatically by wxWidgets when the application exits.

Warning:
  Do not delete an icon that is selected into a memory device context.

## Member Function Documentation

wxIcon wxIcon::ConvertToDisabled | ( | unsigned char | brightness = `255` | ) | const

Returns disabled (dimmed) version of the icon.

MSW only.

Since:
  2.9.0

Reimplemented from wxBitmap.

void wxIcon::CopyFromBitmap | ( | const wxBitmap & | bmp | ) |

Copies bmp bitmap to this icon.

Under MS Windows the bitmap must have mask colour set.

See also:
  LoadFile()

int wxIcon::GetDepth | ( |  | ) | const`[virtual]`

Gets the colour depth of the icon.

A value of 1 indicates a monochrome icon.

Reimplemented from wxBitmap.

int wxIcon::GetHeight | ( |  | ) | const`[virtual]`

Gets the height of the icon in pixels.

See also:
  GetWidth()

Reimplemented from wxBitmap.

int wxIcon::GetWidth | ( |  | ) | const`[virtual]`

Gets the width of the icon in pixels.

See also:
  GetHeight()

Reimplemented from wxBitmap.

virtual bool wxIcon::IsOk | ( |  | ) | const`[virtual]`

Returns true if icon data is present.

Reimplemented from wxBitmap.

bool wxIcon::LoadFile | ( | const wxString & | name,
|  | wxBitmapType | type = `wxICON_DEFAULT_TYPE`,
|  | int | desiredWidth = `-1`,
|  | int | desiredHeight = `-1` |
| ) |  |  |

Loads an icon from a file or resource.

Parameters:

  | name | Either a filename or a Windows resource name. The meaning of name is determined by the type parameter.
  | type | One of the wxBitmapType values; see the note in the class detailed description. Note that the wxICON_DEFAULT_TYPE constant has different value under different wxWidgets ports. See the icon.h header for the value it takes for a specific port.
  | desiredWidth | Specifies the desired width of the icon. This parameter only has an effect in Windows where icon resources can contain several icons of different sizes.
  | desiredHeight | Specifies the desired height of the icon. This parameter only has an effect in Windows where icon resources can contain several icons of different sizes.

Returns:
  true if the operation succeeded, false otherwise.

wxIcon& wxIcon::operator= | ( | const wxIcon & | icon | ) |

Assignment operator, using Reference Counting.

Parameters:

  | icon | Icon to assign.

void wxIcon::SetDepth | ( | int | depth | ) | `[virtual]`

Sets the depth member (does not affect the icon data).

Parameters:

  | depth | Icon depth.

Reimplemented from wxBitmap.

void wxIcon::SetHeight | ( | int | height | ) | `[virtual]`

Sets the height member (does not affect the icon data).

Parameters:

  | height | Icon height in pixels.

Reimplemented from wxBitmap.

void wxIcon::SetWidth | ( | int | width | ) | `[virtual]`

Sets the width member (does not affect the icon data).

Parameters:

  | width | Icon width in pixels.

Reimplemented from wxBitmap.

|  | [ top ]