Version: 3.3.0

#include <wx/icon.h>

+ Inheritance diagram for wxIcon:

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, wxIconBundle, wxDC::DrawIcon, wxCursor

Public Member Functions

 wxIcon ()
 Default ctor. More...
 
 wxIcon (const wxIcon &icon)
 Copy ctor. More...
 
 wxIcon (const char bits[], int width, int height)
 Creates an icon from an array of bits. More...
 
 wxIcon (const char *const *bits)
 Creates a bitmap from XPM data. More...
 
 wxIcon (const wxString &name, wxBitmapType type=wxICON_DEFAULT_TYPE, int desiredWidth=-1, int desiredHeight=-1)
 Loads an icon from a file or resource. More...
 
 wxIcon (const wxIconLocation &loc)
 Loads an icon from the specified location. More...
 
virtual ~wxIcon ()
 Destructor. More...
 
bool CreateFromHICON (WXHICON icon)
 Attach a Windows icon handle. More...
 
wxIcon ConvertToDisabled (unsigned char brightness=255) const
 Returns disabled (dimmed) version of the icon. More...
 
void CopyFromBitmap (const wxBitmap &bmp)
 Copies bmp bitmap to this icon. More...
 
int GetDepth () const
 Gets the colour depth of the icon. More...
 
int GetHeight () const
 Gets the height of the icon in physical pixels. More...
 
double GetLogicalHeight () const
 Gets the height of the icon in logical pixels. More...
 
wxSize GetLogicalSize () const
 Gets the size of the icon in logical pixels. More...
 
double GetLogicalWidth () const
 Gets the width of the icon in logical pixels. More...
 
double GetScaleFactor () const
 Gets the scale factor of this icon. More...
 
wxSize GetSize () const
 Gets the size of the icon in physical pixels. More...
 
int GetWidth () const
 Gets the width of the icon in physical pixels. More...
 
virtual bool IsOk () const
 Returns true if icon data is present. More...
 
bool LoadFile (const wxString &name, wxBitmapType type=wxICON_DEFAULT_TYPE, int desiredWidth=-1, int desiredHeight=-1)
 Loads an icon from a file or resource. More...
 
void SetDepth (int depth)
 
void SetHeight (int height)
 
void SetWidth (int width)
 
wxIconoperator= (const wxIcon &icon)
 Assignment operator, using Reference Counting. More...
 
- Public Member Functions inherited from wxGDIObject
 wxGDIObject ()
 Default constructor. More...
 
- Public Member Functions inherited from wxObject
 wxObject ()
 Default ctor; initializes to nullptr the internal reference data. More...
 
 wxObject (const wxObject &other)
 Copy ctor. More...
 
virtual ~wxObject ()
 Destructor. More...
 
virtual wxClassInfoGetClassInfo () const
 This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar). More...
 
wxObjectRefDataGetRefData () const
 Returns the wxObject::m_refData pointer, i.e. the data referenced by this object. More...
 
bool IsKindOf (const wxClassInfo *info) const
 Determines whether this class is a subclass of (or the same class as) the given class. More...
 
bool IsSameAs (const wxObject &obj) const
 Returns true if this object has the same data pointer as obj. More...
 
void Ref (const wxObject &clone)
 Makes this object refer to the data in clone. More...
 
void SetRefData (wxObjectRefData *data)
 Sets the wxObject::m_refData pointer. More...
 
void UnRef ()
 Decrements the reference count in the associated data, and if it is zero, deletes the data. More...
 
void UnShare ()
 This is the same of AllocExclusive() but this method is public. More...
 
void operator delete (void *buf)
 The delete operator is defined for debugging versions of the library only, when the identifier __WXDEBUG__ is defined. More...
 
void * operator new (size_t size, const wxString &filename=nullptr, int lineNum=0)
 The new operator is defined for debugging versions of the library only, when the identifier __WXDEBUG__ is defined. More...
 

Additional Inherited Members

- Protected Member Functions inherited from wxObject
void AllocExclusive ()
 Ensure that this object's data is not shared with any other object. More...
 
virtual wxObjectRefDataCreateRefData () const
 Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it. More...
 
virtual wxObjectRefDataCloneRefData (const wxObjectRefData *data) const
 Creates a new instance of the wxObjectRefData-derived class specific to this object and initializes it copying data. More...
 
- Protected Attributes inherited from wxObject
wxObjectRefDatam_refData
 Pointer to an object which is the object's reference-counted data. More...
 

Constructor & Destructor Documentation

◆ wxIcon() [1/6]

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() [2/6]

wxIcon::wxIcon ( const wxIcon icon)

Copy ctor.

◆ wxIcon() [3/6]

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
bitsSpecifies an array of pixel values.
widthThe width of the image.
heightThe height of the image.

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

Availability:  only available for the wxMSW, wxOSX/Cocoa ports.

◆ wxIcon() [4/6]

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);
wxIcon()
Default ctor.

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__)
wxIcon icon(sample_xpm);
#endif
#if defined(__WXMSW__)
wxIcon icon("sample");
#endif
An icon is a small rectangular bitmap usually used for denoting a minimized application.
Definition: icon.h:53
#define wxICON(iconName)
This macro loads an icon from either application resources (on the platforms for which they exist,...
Definition: gdicmn.h:1256

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

◆ wxIcon() [5/6]

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
nameThis can refer to a resource name or a filename under MS Windows and X. Its meaning is determined by the type parameter.
typeMay 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.
desiredWidthSpecifies the desired width of the icon. This parameter only has an effect in Windows where icon resources can contain several icons of different sizes.
desiredHeightSpecifies 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() [6/6]

wxIcon::wxIcon ( const wxIconLocation loc)

Loads an icon from the specified location.

◆ ~wxIcon()

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

◆ ConvertToDisabled()

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

Returns disabled (dimmed) version of the icon.

This method is available in wxIcon only under wxMSW, other ports only have it in wxBitmap. You can always use wxImage::ConvertToDisabled() and create the icon from wxImage manually however.

Availability:  only available for the wxMSW port.
Since
2.9.0

◆ CopyFromBitmap()

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()

◆ CreateFromHICON()

bool wxIcon::CreateFromHICON ( WXHICON  icon)

Attach a Windows icon handle.

This wxMSW-specific method allows assigning a native Windows HICON (which must be cast to WXHICON opaque handle type) to wxIcon. Notice that this means that the HICON will be destroyed by wxIcon when it is destroyed.

Returns
true if successful.
Availability:  only available for the wxMSW port.
Since
2.9.5

◆ GetDepth()

int wxIcon::GetDepth ( ) const

Gets the colour depth of the icon.

A value of 1 indicates a monochrome icon.

◆ GetHeight()

int wxIcon::GetHeight ( ) const

Gets the height of the icon in physical pixels.

See also
GetWidth(), GetLogicalHeight()

◆ GetLogicalHeight()

double wxIcon::GetLogicalHeight ( ) const

Gets the height of the icon in logical pixels.

See wxBitmap::GetLogicalHeight().

Since
3.1.6

◆ GetLogicalSize()

wxSize wxIcon::GetLogicalSize ( ) const

Gets the size of the icon in logical pixels.

See wxBitmap::GetLogicalSize().

Since
3.1.6

◆ GetLogicalWidth()

double wxIcon::GetLogicalWidth ( ) const

Gets the width of the icon in logical pixels.

See wxBitmap::GetLogicalWidth().

Since
3.1.6

◆ GetScaleFactor()

double wxIcon::GetScaleFactor ( ) const

Gets the scale factor of this icon.

See wxBitmap::GetScaleFactor().

Since
3.1.6

◆ GetSize()

wxSize wxIcon::GetSize ( ) const

Gets the size of the icon in physical pixels.

See also
GetLogicalSize()

◆ GetWidth()

int wxIcon::GetWidth ( ) const

Gets the width of the icon in physical pixels.

See also
GetHeight(), GetLogicalWidth()

◆ IsOk()

virtual bool wxIcon::IsOk ( ) const
virtual

Returns true if icon data is present.

◆ LoadFile()

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
nameEither a filename or a Windows resource name. The meaning of name is determined by the type parameter.
typeOne 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.
desiredWidthSpecifies the desired width of the icon. This parameter only has an effect in Windows where icon resources can contain several icons of different sizes.
desiredHeightSpecifies 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.

◆ operator=()

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

Assignment operator, using Reference Counting.

Parameters
iconIcon to assign.

◆ SetDepth()

void wxIcon::SetDepth ( int  depth)
Deprecated:
This function is deprecated since version 3.1.2, dimensions and depth can only be set at construction time.

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

Parameters
depthIcon depth.

◆ SetHeight()

void wxIcon::SetHeight ( int  height)
Deprecated:
This function is deprecated since version 3.1.2, dimensions and depth can only be set at construction time.

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

Parameters
heightIcon height in pixels.

◆ SetWidth()

void wxIcon::SetWidth ( int  width)
Deprecated:
This function is deprecated since version 3.1.2, dimensions and depth can only be set at construction time.

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

Parameters
widthIcon width in pixels.