Contents Up Previous Next

wxWindows resource functions

wxWindows resource system

This section details functions for manipulating wxWindows (.WXR) resource files and loading user interface elements from resources.


Please note that this use of the word 'resource' is different from that used when talking about initialisation file resource reading and writing, using such functions as wxWriteResource and wxGetResource. It's just an unfortunate clash of terminology.

For an overview of the wxWindows resource mechanism, see the wxWindows resource system.

See also wxPanel::LoadFromResource for panel and dialog loading from resource data.

::wxResourceAddIdentifier
::wxResourceClear
::wxResourceCreateBitmap
::wxResourceCreateIcon
::wxResourceCreateMenuBar
::wxResourceGetIdentifier
::wxResourceParseData
::wxResourceParseFile
::wxResourceParseString
::wxResourceRegisterBitmapData
::wxResourceRegisterIconData


::wxResourceAddIdentifier

Bool wxResourceAddIdentifier(char *name, int value)

Used for associating a name with an integer identifier (equivalent to dynamically #defining a name to an integer). Unlikely to be used by an application except perhaps for implementing resource functionality for interpreted languages.


::wxResourceClear

void wxResourceClear(void)

Clears the wxWindows resource table.


::wxResourceCreateBitmap

wxBitmap * wxResourceCreateBitmap(char *resource)

Creates a new bitmap from a file, static data, or Windows resource, given a valid wxWindows bitmap resource identifier. For example, if the .WXR file contains the following:

static char *aiai_resource = "bitmap(name = 'aiai_resource',\
  bitmap = ['aiai', wxBITMAP_TYPE_BMP_RESOURCE, 'WINDOWS'],\
  bitmap = ['aiai.xpm', wxBITMAP_TYPE_XPM, 'X']).";
then this function can be called as follows:

  wxBitmap *bitmap  = wxResourceCreateBitmap("aiai_resource");

::wxResourceCreateIcon

wxIcon * wxResourceCreateIcon(char *resource)

Creates a new icon from a file, static data, or Windows resource, given a valid wxWindows icon resource identifier. For example, if the .WXR file contains the following:

static char *aiai_resource = "icon(name = 'aiai_resource',\
  icon = ['aiai', wxBITMAP_TYPE_ICO_RESOURCE, 'WINDOWS'],\
  icon = ['aiai', wxBITMAP_TYPE_XBM_DATA, 'X']).";
then this function can be called as follows:

  wxIcon *icon = wxResourceCreateIcon("aiai_resource");

::wxResourceCreateMenuBar

wxMenuBar * wxResourceCreateMenuBar(char *resource)

Creates a new menu bar given a valid wxWindows menubar resource identifier. For example, if the .WXR file contains the following:

static char *menuBar11 = "menu(name = 'menuBar11',\
  menu = \
  [\
    ['&File', 1, '', \
      ['&Open File', 2, 'Open a file'],\
      ['&Save File', 3, 'Save a file'],\
      [],\
      ['E&xit', 4, 'Exit program']\
    ],\
    ['&Help', 5, '', \
      ['&About', 6, 'About this program']\
    ]\
  ]).";
then this function can be called as follows:

  wxMenuBar *menuBar = wxResourceCreateMenuBar("menuBar11");

::wxResourceGetIdentifier

int wxResourceGetIdentifier(char *name)

Used for retrieving the integer value associated with an identifier. A zero value indicates that the identifier was not found.

See wxResourceAddIdentifier.


::wxResourceParseData

Bool wxResourceParseData(char *resource, wxResourceTable *table = NULL)

Parses a string containing one or more wxWindows resource objects. If the resource objects are global static data that are included into the C++ program, then this function must be called for each variable containing the resource data, to make it known to wxWindows.

resource should contain data in the following form:

dialog(name = 'dialog1',
  style = 'wxCAPTION | wxDEFAULT_DIALOG_STYLE',
  title = 'Test dialog box',
  x = 312, y = 234, width = 400, height = 300,
  modal = 0,
  control = [wxGroupBox, 'Groupbox', '0', 'group6', 5, 4, 380, 262,
      [11, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0]],
  control = [wxMultiText, 'Multitext', 'wxVERTICAL_LABEL', 'multitext3',
      156, 126, 200, 70, 'wxWindows is a multi-platform, GUI toolkit.',
      [11, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0],
      [11, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0]]).
This function will typically be used after including a .wxr file into a C++ program as follows:

#include "dialog1.wxr"
Each of the contained resources will declare a new C++ variable, and each of these variables should be passed to wxResourceParseData.


::wxResourceParseFile

Bool wxResourceParseFile(char *filename, wxResourceTable *table = NULL)

Parses a file containing one or more wxWindows resource objects in C++-compatible syntax. Use this function to dynamically load wxWindows resource data.


::wxResourceParseString

Bool wxResourceParseString(char *resource, wxResourceTable *table = NULL)

Parses a string containing one or more wxWindows resource objects. If the resource objects are global static data that are included into the C++ program, then this function must be called for each variable containing the resource data, to make it known to wxWindows.

resource should contain data with the following form:

static char *dialog1 = "dialog(name = 'dialog1',\
  style = 'wxCAPTION | wxDEFAULT_DIALOG_STYLE',\
  title = 'Test dialog box',\
  x = 312, y = 234, width = 400, height = 300,\
  modal = 0,\
  control = [wxGroupBox, 'Groupbox', '0', 'group6', 5, 4, 380, 262,\
      [11, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0]],\
  control = [wxMultiText, 'Multitext', 'wxVERTICAL_LABEL', 'multitext3',\
      156, 126, 200, 70, 'wxWindows is a multi-platform, GUI toolkit.',\
      [11, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0],\
      [11, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0]]).";
This function will typically be used after calling wxLoadUserResource to load an entire .wxr file into a string.


::wxResourceRegisterBitmapData

Bool wxResourceRegisterBitmapData(char *name, char *xbm_data, int width, int height, wxResourceTable *table = NULL)

Bool wxResourceRegisterBitmapData(char *name, char **xpm_data)

Makes #included XBM or XPM bitmap data known to the wxWindows resource system. This is required if other resources will use the bitmap data, since otherwise there is no connection between names used in resources, and the global bitmap data.


::wxResourceRegisterIconData

Another name for wxResourceRegisterBitmapData.