## Miscellaneous functions

wxCONCAT
wxDYNLIB_FUNCTION
wxEXPLICIT
::wxGetKeyState
wxLL
wxLongLongFmtSpec
::wxNewId
wxON_BLOCK_EXIT
wxON_BLOCK_EXIT_OBJ
::wxRegisterId
::wxDDECleanUp
::wxDDEInitialize
::wxEnableTopLevelWindows
::wxFindMenuItemId
::wxFindWindowByLabel
::wxFindWindowByName
::wxFindWindowAtPoint
::wxFindWindowAtPointer
::wxGetActiveWindow
::wxGetBatteryState
::wxGetDisplayName
::wxGetPowerType
::wxGetMousePosition
::wxGetMouseState
::wxGetResource
::wxGetStockLabel
::wxGetTopLevelParent
::wxLaunchDefaultBrowser
::wxLoadUserResource
::wxPostDelete
::wxPostEvent
::wxSetDisplayName
::wxStripMenuCodes
wxULL
wxVaCopy
::wxWriteResource

### wxCONCAT

wxCONCAT(x, y)

This macro returns the concatenation of two tokens x and y.

### wxDYNLIB_FUNCTION

wxDYNLIB_FUNCTION(type, name, dynlib)

When loading a function from a DLL you always have to cast the returned `void *` pointer to the correct type and, even more annoyingly, you have to repeat this type twice if you want to declare and define a function pointer all in one line

This macro makes this slightly less painful by allowing you to specify the type only once, as the first parameter, and creating a variable of this type named after the function but with `pfn` prefix and initialized with the function name from the wxDynamicLibrary dynlib.

Parameters

type

the type of the function

name

the name of the function to load, not a string (without quotes, it is quoted automatically by the macro)

dynlib

the library to load the function from

### wxEXPLICIT

`wxEXPLICIT` is a macro which expands to the C++ `explicit` keyword if the compiler supports it or nothing otherwise. Thus, it can be used even in the code which might have to be compiled with an old compiler without support for this language feature but still take advantage of it when it is available.

### ::wxGetKeyState

bool wxGetKeyState(wxKeyCode key)

For normal keys, returns `true` if the specified key is currently down.

For togglable keys (Caps Lock, Num Lock and Scroll Lock), returns `true` if the key is toggled such that its LED indicator is lit. There is currently no way to test whether togglable keys are up or down.

Even though there are virtual key codes defined for mouse buttons, they cannot be used with this function currently.

Include files

<wx/utils.h>

### wxLL

wxLongLong_t wxLL(number)

This macro is defined for the platforms with a native 64 bit integer type and allows to define 64 bit compile time constants:

        #ifdef wxLongLong_t
            wxLongLong_t ll = wxLL(0x1234567890abcdef);
        #endif

Include files

<wx/longlong.h>

See also

wxULL, wxLongLong

### wxLongLongFmtSpec

This macro is defined to contain the `printf()` format specifier using which 64 bit integer numbers (i.e. those of type `wxLongLong_t`) can be printed. Example of using it:

        #ifdef wxLongLong_t
            wxLongLong_t ll = wxLL(0x1234567890abcdef);
            printf("Long long = %" wxLongLongFmtSpec "x\n", ll);
        #endif

See also

wxLL

Include files

<wx/longlong.h>

### ::wxNewId

long wxNewId()

Generates an integer identifier unique to this run of the program.

Include files

<wx/utils.h>

### wxON_BLOCK_EXIT

wxON_BLOCK_EXIT0(func) wxON_BLOCK_EXIT1(func, p1) wxON_BLOCK_EXIT2(func, p1, p2)

This family of macros allows to ensure that the global function func with 0, 1, 2 or more parameters (up to some implementaton-defined limit) is executed on scope exit, whether due to a normal function return or because an exception has been thrown. A typical example of its usage:

        void *buf = malloc(size);
        wxON_BLOCK_EXIT1(free, buf);

Please see the original article by Andrei Alexandrescu and Petru Marginean published in December 2000 issue of C/C++ Users Journal for more details.

Include files

<wx/scopeguard.h>

See also

wxON_BLOCK_EXIT_OBJ

### wxON_BLOCK_EXIT_OBJ

wxON_BLOCK_EXIT_OBJ0(obj, method) wxON_BLOCK_EXIT_OBJ1(obj, method, p1) wxON_BLOCK_EXIT_OBJ2(obj, method, p1, p2)

This family of macros is similar to wxON_BLOCK_EXIT but calls a method of the given object instead of a free function.

Include files

<wx/scopeguard.h>

### ::wxRegisterId

void wxRegisterId(long id)

Ensures that ids subsequently generated by NewId do not clash with the given id.

Include files

<wx/utils.h>

### ::wxDDECleanUp

void wxDDECleanUp()

Called when wxWidgets exits, to clean up the DDE system. This no longer needs to be called by the application.

See also wxDDEInitialize.

Include files

<wx/dde.h>

### ::wxDDEInitialize

void wxDDEInitialize()

Initializes the DDE system. May be called multiple times without harm.

This no longer needs to be called by the application: it will be called by wxWidgets if necessary.

See also wxDDEServer, wxDDEClient, wxDDEConnection, wxDDECleanUp.

Include files

<wx/dde.h>

### ::wxEnableTopLevelWindows

void wxEnableTopLevelWindows(bool enable = true)

This function enables or disables all top level windows. It is used by ::wxSafeYield.

Include files

<wx/utils.h>

### ::wxFindMenuItemId

int wxFindMenuItemId(wxFrame *frame, const wxString& menuString, const wxString& itemString)

Find a menu item identifier associated with the given frame's menu bar.

Include files

<wx/utils.h>

### ::wxFindWindowByLabel

wxWindow * wxFindWindowByLabel(const wxString& label, wxWindow *parent=NULL)

NB: This function is obsolete, please use wxWindow::FindWindowByLabel instead.

Find a window by its label. Depending on the type of window, the label may be a window title or panel item label. If parent is NULL, the search will start from all top-level frames and dialog boxes; if non-NULL, the search will be limited to the given window hierarchy. The search is recursive in both cases.

Include files

<wx/utils.h>

### ::wxFindWindowByName

wxWindow * wxFindWindowByName(const wxString& name, wxWindow *parent=NULL)

NB: This function is obsolete, please use wxWindow::FindWindowByName instead.

Find a window by its name (as given in a window constructor or Create function call). If parent is NULL, the search will start from all top-level frames and dialog boxes; if non-NULL, the search will be limited to the given window hierarchy. The search is recursive in both cases.

If no such named window is found, wxFindWindowByLabel is called.

Include files

<wx/utils.h>

### ::wxFindWindowAtPoint

wxWindow * wxFindWindowAtPoint(const wxPoint& pt)

Find the deepest window at the given mouse position in screen coordinates, returning the window if found, or NULL if not.

### ::wxFindWindowAtPointer

wxWindow * wxFindWindowAtPointer(wxPoint& pt)

Find the deepest window at the mouse pointer position, returning the window and current pointer position in screen coordinates.

### ::wxGetActiveWindow

wxWindow * wxGetActiveWindow()

Gets the currently active window (Windows only).

Include files

<wx/windows.h>

### ::wxGetBatteryState

wxBatteryState wxGetBatteryState()

Returns battery state as one of `wxBATTERY_NORMAL_STATE`, `wxBATTERY_LOW_STATE`, `wxBATTERY_CRITICAL_STATE`, `wxBATTERY_SHUTDOWN_STATE` or `wxBATTERY_UNKNOWN_STATE`. `wxBATTERY_UNKNOWN_STATE` is also the default on platforms where this feature is not implemented.

Include files

<wx/utils.h>

### ::wxGetDisplayName

wxString wxGetDisplayName()

Under X only, returns the current display name. See also wxSetDisplayName.

Include files

<wx/utils.h>

### ::wxGetPowerType

wxPowerType wxGetPowerType()

Returns the type of power source as one of `wxPOWER_SOCKET`, `wxPOWER_BATTERY` or `wxPOWER_UNKNOWN`. `wxPOWER_UNKNOWN` is also the default on platforms where this feature is not implemented.

Include files

<wx/utils.h>

### ::wxGetMousePosition

wxPoint wxGetMousePosition()

Returns the mouse position in screen coordinates.

Include files

<wx/utils.h>

### ::wxGetMouseState

wxMouseState wxGetMouseState()

Returns the current state of the mouse. Returns a wxMouseState instance that contains the current position of the mouse pointer in screen coordinants, as well as boolean values indicating the up/down status of the mouse buttons and the modifier keys.

Include files

<wx/utils.h>

wxMouseState has the following interface:

    class wxMouseState
    {
    public:
        wxMouseState();

        wxCoord     GetX();
        wxCoord     GetY();

        bool        LeftDown();
        bool        MiddleDown();
        bool        RightDown();

        bool        ControlDown();
        bool        ShiftDown();
        bool        AltDown();
        bool        MetaDown();
        bool        CmdDown();

        void        SetX(wxCoord x);
        void        SetY(wxCoord y);

        void        SetLeftDown(bool down);
        void        SetMiddleDown(bool down);
        void        SetRightDown(bool down);

        void        SetControlDown(bool down);
        void        SetShiftDown(bool down);
        void        SetAltDown(bool down);
        void        SetMetaDown(bool down);
    };

### ::wxGetResource

bool wxGetResource(const wxString& section, const wxString& entry, const wxString& *value, const wxString& file = NULL)

bool wxGetResource(const wxString& section, const wxString& entry, float *value, const wxString& file = NULL)

bool wxGetResource(const wxString& section, const wxString& entry, long *value, const wxString& file = NULL)

bool wxGetResource(const wxString& section, const wxString& entry, int *value, const wxString& file = NULL)

Gets a resource value from the resource database (for example, WIN.INI, or .Xdefaults). If file is NULL, WIN.INI or .Xdefaults is used, otherwise the specified file is used.

Under X, if an application class (wxApp::GetClassName) has been defined, it is appended to the string /usr/lib/X11/app-defaults/ to try to find an applications default file when merging all resource databases.

The reason for passing the result in an argument is that it can be convenient to define a default value, which gets overridden if the value exists in the resource file. It saves a separate test for that resource's existence, and it also allows the overloading of the function for different types.

See also wxWriteResource, wxConfigBase.

Include files

<wx/utils.h>

### ::wxGetStockLabel

wxString wxGetStockLabel(wxWindowID id, bool withCodes = true, wxString accelerator = wxEmptyString)

Returns label that should be used for given id element.

Parameters

id

given id of the wxMenuItem, wxButton, wxToolBar tool, etc.

withCodes

if false then strip accelerator code from the label; usefull for getting labels without accelerator char code like for toolbar tooltip or under platforms without traditional keyboard like smartphones

accelerator

optional accelerator string automatically added to label; useful for building labels for wxMenuItem

Include files

<wx/stockitem.h>

### ::wxGetTopLevelParent

wxWindow * wxGetTopLevelParent(wxWindow *win)

Returns the first top level parent of the given window, or in other words, the frame or dialog containing it, or `NULL`.

Include files

<wx/window.h>

### ::wxLaunchDefaultBrowser

bool wxLaunchDefaultBrowser(const wxString& sUrl)

Launches the user's default browser and tells it to open the location at `sUrl`.

Returns true if the application was successfully launched.

Include files

<wx/utils.h>

### ::wxLoadUserResource

wxString wxLoadUserResource(const wxString& resourceName, const wxString& resourceType="TEXT")

Loads a user-defined Windows resource as a string. If the resource is found, the function creates a new character array and copies the data into it. A pointer to this data is returned. If unsuccessful, NULL is returned.

The resource must be defined in the `.rc` file using the following syntax:

    myResource TEXT file.ext

where `file.ext` is a file that the resource compiler can find.

This function is available under Windows only.

Include files

<wx/utils.h>

### ::wxPostDelete

void wxPostDelete(wxObject *object)

Tells the system to delete the specified object when all other events have been processed. In some environments, it is necessary to use this instead of deleting a frame directly with the delete operator, because some GUIs will still send events to a deleted window.

Now obsolete: use wxWindow::Close instead.

Include files

<wx/utils.h>

### ::wxPostEvent

void wxPostEvent(wxEvtHandler *dest, wxEvent& event)

In a GUI application, this function posts event to the specified dest object using wxEvtHandler::AddPendingEvent. Otherwise, it dispatches event immediately using wxEvtHandler::ProcessEvent. See the respective documentation for details (and caveats).

Include files

<wx/app.h>

### ::wxSetDisplayName

void wxSetDisplayName(const wxString& displayName)

Under X only, sets the current display name. This is the X host and display name such as "colonsay:0.0", and the function indicates which display should be used for creating windows from this point on. Setting the display within an application allows multiple displays to be used.

See also wxGetDisplayName.

Include files

<wx/utils.h>

### ::wxStripMenuCodes

wxString wxStripMenuCodes(const wxString& in)

void wxStripMenuCodes(char *in, char *out)

NB: This function is obsolete, please use wxMenuItem::GetLabelFromText instead.

Strips any menu codes from in and places the result in out (or returns the new string, in the first form).

Menu codes include & (mark the next character with an underline as a keyboard shortkey in Windows and Motif) and \t (tab in Windows).

Include files

<wx/utils.h>

### wxULL

wxLongLong_t wxULL(number)

This macro is defined for the platforms with a native 64 bit integer type and allows to define unsigned 64 bit compile time constants:

        #ifdef wxLongLong_t
            unsigned wxLongLong_t ll = wxULL(0x1234567890abcdef);
        #endif

Include files

<wx/longlong.h>

See also

wxLL, wxLongLong

### wxVaCopy

void wxVaCopy(va_list argptrDst, va_list argptrSrc)

This macro is the same as the standard C99 `va_copy` for the compilers which support it or its replacement for those that don't. It must be used to preserve the value of a `va_list` object if you need to use it after passing it to another function because it can be modified by the latter.

As with `va_start`, each call to `wxVaCopy` must have a matching `va_end`.

### ::wxWriteResource

bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file = NULL)

bool wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file = NULL)

bool wxWriteResource(const wxString& section, const wxString& entry, long value, const wxString& file = NULL)

bool wxWriteResource(const wxString& section, const wxString& entry, int value, const wxString& file = NULL)

Writes a resource value into the resource database (for example, WIN.INI, or .Xdefaults). If file is NULL, WIN.INI or .Xdefaults is used, otherwise the specified file is used.

Under X, the resource databases are cached until the internal function wxFlushResources is called automatically on exit, when all updated resource databases are written to their files.

Note that it is considered bad manners to write to the .Xdefaults file under Unix, although the WIN.INI file is fair game under Windows.

See also wxGetResource, wxConfigBase.

Include files

<wx/utils.h>