Contents Up Previous Next

wxIcon: wxBitmap

An icon is a small rectangular bitmap usually used for denoting a minimized application. It is optional (but desirable) to associate a pertinent icon with a frame. Obviously icons in X and MS Windows are created in a different manner, and colour icons in X are difficult to arrange. Therefore, separate icons will 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 X, this will ensure that fresh X resources are allocated for this frame. In MS 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.

The following shows the conditional compilation required to define an icon in X and in MS Windows. The alternative is to use the string version of the icon constructor, which loads a file under X and a resource under MS Windows, but has the disadvantage of requiring the X icon file to be available at run-time. If anyone can invent a scheme or macro which does the following more elegantly and platform-independently, I'd like to see it!

#ifdef wx_x
#include "aiai.xbm"
#endif
#ifdef wx_msw
  wxIcon *icon = new wxIcon("aiai");
#endif
#ifdef wx_x
  wxIcon *icon = new wxIcon(aiai_bits, aiai_width, aiai_height);
#endif
See also wxDC::DrawIcon, wxBitmap.

wxIcon::wxIcon
wxIcon::~wxIcon
wxIcon::GetHeight
wxIcon::GetWidth


wxIcon::wxIcon

void wxIcon(void)

Default constructor.

void wxIcon(char ** data)

Construct an icon by specifying the bits in an included .XPM file (X only). Only available if USE_XPM_IN_X is enabled in wx_setup.h.

void wxIcon(char bits[], int width, int height)

Construct an icon by specifying the bits in an included .XBM file (X only).

For example:

#ifdef wx_x
#include "aiai.xbm"
#endif

#ifdef wx_x
  test_icon = new wxIcon(aiai_bits, aiai_width, aiai_height);
#endif
void wxIcon(char *iconName, long flags)

Constructor. An icon can be created by passing an array of bits (X only) or by passing a string name. icon_name refers to a filename in X, a resource name in MS Windows.

Construct a cursor by passing a string resource name or filename. Under Motif, flags defaults to wxBITMAP_TYPE_XBM | wxBITMAP_DISCARD_COLOURMAP. Under Windows, it defaults to wxBITMAP_TYPE_ICO_RESOURCE | wxBITMAP_DISCARD_COLOURMAP.

Under X, the permitted icon types in the flags bitlist are:

wxBITMAP_TYPE_BMP Load a Windows bitmap file (if USE_IMAGE_LOADING_IN_X is enabled in wx_setup.h).
wxBITMAP_TYPE_GIF Load a GIF bitmap file (if USE_IMAGE_LOADING_IN_X is enabled in wx_setup.h).
wxBITMAP_TYPE_XBM Load an X bitmap file.
wxBITMAP_TYPE_XPM Load an XPM (colour pixmap) file. Only available if USE_XPM_IN_X is enabled in wx_setup.h.

Under Windows, the permitted types are:

is enabled in wx_setup.h).
wxBITMAP_TYPE_ICO Load a cursor from a .ico icon file (only if USE_RESOURCE_LOADING_IN_MSW.
wxBITMAP_TYPE_ICO_RESOURCE Load a Windows resource (as specified in the .rc file).


wxIcon::~wxIcon

void ~wxIcon(void)

Destroys the icon. Do not explicitly delete an icon pointer which has been passed to a frame - the frame will delete the icon when it is destroyed. If assigning a new icon to a frame, the old icon will be destroyed.


wxIcon::GetHeight

int GetHeight(void)

Returns the height of the icon.


wxIcon::GetWidth

int GetWidth(void)

Returns the width of the icon.