## Resource functions

Resource functions

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 is just an unfortunate clash of terminology.

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

See also wxWindow::LoadFromResource for loading from resource data.

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

### ::wxResourceAddIdentifier

bool wxResourceAddIdentifier(const wxString& 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()

Clears the wxWindows resource table.

### ::wxResourceCreateBitmap

wxBitmap * wxResourceCreateBitmap(const wxString& 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 const wxString\& project_resource = "bitmap(name = 'project_resource',\
      bitmap = ['project', wxBITMAP_TYPE_BMP_RESOURCE, 'WINDOWS'],\
      bitmap = ['project.xpm', wxBITMAP_TYPE_XPM, 'X']).";

then this function can be called as follows:

      wxBitmap *bitmap  = wxResourceCreateBitmap("project_resource");

### ::wxResourceCreateIcon

wxIcon * wxResourceCreateIcon(const wxString& 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 const wxString\& project_resource = "icon(name = 'project_resource',\
      icon = ['project', wxBITMAP_TYPE_ICO_RESOURCE, 'WINDOWS'],\
      icon = ['project', wxBITMAP_TYPE_XBM_DATA, 'X']).";

then this function can be called as follows:

      wxIcon *icon = wxResourceCreateIcon("project_resource");

### ::wxResourceCreateMenuBar

wxMenuBar * wxResourceCreateMenuBar(const wxString& resource)

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

    static const wxString\& 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(const wxString& 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(const wxString& 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 = [1000, wxStaticBox, 'Groupbox', '0', 'group6', 5, 4, 380, 262,
          [11, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0]],
      control = [1001, wxTextCtrl, '', 'wxTE_MULTILINE', 'text3',
          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(const wxString& 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 *s, 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:

    dialog(name = 'dialog1',
      style = 'wxCAPTION | wxDEFAULT_DIALOG_STYLE',
      title = 'Test dialog box',
      x = 312, y = 234, width = 400, height = 300,
      modal = 0,
      control = [1000, wxStaticBox, 'Groupbox', '0', 'group6', 5, 4, 380, 262,
          [11, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0]],
      control = [1001, wxTextCtrl, '', 'wxTE_MULTILINE', 'text3',
          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(const wxString& name, char *xbm_data, int width, int height, wxResourceTable *table = NULL)

bool wxResourceRegisterBitmapData(const wxString& 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.