Contents Up Previous Next

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
wxSTRINGIZE
wxSTRINGIZE_T
wxSUPPRESS_GCC_PRIVATE_DTOR_WARNING
wxULL
wxVaCopy
::wxWriteResource
__WXFUNCTION__


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

name

dynlib


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 (implemented for MSW and GTK only currently, always returns NULL in the other ports).

Include files

<wx/window.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 (currently everywhere but MS Windows).

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 (currently everywhere but MS Windows).

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, const wxString& accelerator = wxEmptyString)

Returns label that should be used for given id element.

Parameters

id

withCodes

accelerator

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& url, int flags = 0)

Open the url in user's default browser. If flags parameter contains wxBROWSER_NEW_WINDOW flag, a new window is opened for the URL (currently this is only supported under Windows).

Returns true if the application was successfully launched.

Note that for some configurations of the running user, the application which is launched to open the given URL may be URL-dependent (e.g. a browser may be used for local URLs while another one may be used for remote URLs).

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& str, int flags = wxStrip_All)

Strips any menu codes from str and returns the result.

By default, the functions strips both the mnemonics character ('&') which is used to indicate a keyboard shortkey, and the accelerators, which are used only in the menu items and are separated from the main text by the \t (TAB) character. By using flags of wxStrip_Mnemonics or wxStrip_Accel to strip only the former or the latter part, respectively.

Notice that in most cases wxMenuItem::GetLabelFromText or wxControl::GetLabelText can be used instead.

Include files

<wx/utils.h>


wxSTRINGIZE

wxSTRINGIZE(x)

Returns the string representation of the given symbol which can be either a literal or a macro (hence the advantage of using this macro instead of the standard preprocessor # operator which doesn't work with macros).

Notice that this macro always produces a char string, use wxSTRINGIZE_T to build a wide string Unicode build.

See also

wxCONCAT


wxSTRINGIZE_T

wxSTRINGIZE_T(x)

Returns the string representation of the given symbol as either an ASCII or Unicode string, depending on the current build. This is the Unicode-friendly equivalent of wxSTRINGIZE.


wxSUPPRESS_GCC_PRIVATE_DTOR_WARNING

wxSUPPRESS_GCC_PRIVATE_DTOR_WARNING(name)

GNU C++ compiler gives a warning for any class whose destructor is private unless it has a friend. This warning may sometimes be useful but it doesn't make sense for reference counted class which always delete themselves (hence destructor should be private) but don't necessarily have any friends, so this macro is provided to disable the warning in such case. The name parameter should be the name of the class but is only used to construct a unique friend class name internally. Example of using the macro:

    class RefCounted
    {
    public:
        RefCounted() { m_nRef = 1; }
        void IncRef() { m_nRef++ ; }
        void DecRef() { if ( !--m_nRef ) delete this; }

    private:
        ~RefCounted() { }

        wxSUPPRESS_GCC_PRIVATE_DTOR(RefCounted)
    };
Notice that there should be no semicolon after this macro.


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>


__WXFUNCTION__

__WXFUNCTION__()

This macro expands to the name of the current function if the compiler supports any of __FUNCTION__, __func__ or equivalent variables or macros or to NULL if none of them is available.