.. include:: headings.inc


.. _window ids:

=================================================
|phoenix_title|  **Window IDs Overview**
=================================================


Various controls and other parts of wxPython need an ID. Sometimes the
ID may be directly provided by the user or have a predefined value,
such as ``wx.ID_OPEN``. Often, however, the value of the ID is
unimportant and is created automatically by calling
:meth:`wx.Window.NewControlId` or by passing ``wx.ID_ANY`` as the ID of an
object.

There are two ways to generate an ID. One way is to start at a negative number, and for each new ID, return the 
next smallest number. This is fine for systems that can use the full range of negative numbers for IDs, as 
this provides more than enough IDs and it would take a very very long time to run out and wrap around. 
However, some systems cannot use the full range of the ID value. Windows, for example, can only use 16 bit
IDs, and only has about 32000 possible automatic IDs that can be generated by :meth:`wx.Window.NewControlId`. 
If the program runs long enough, depending on the program itself, using this first method would cause the IDs
to wrap around into the positive ID range and cause possible clashes with any directly specified ID values.

The other way is to keep track of the IDs returned by :meth:`wx.Window.NewControlId` and don't return them again
until the ID is completely free and not being used by any other objects. This will make sure that the ID values 
do not clash with one another. This is accomplished by keeping a reference count for each of the IDs that can 
possibly be returned by :meth:`wx.Window.NewControlId`. Other IDs are not reference counted.


.. seealso:: :ref:`wx.IdManager`, :meth:`wx.Window.NewControlId`, :meth:`wx.Window.UnreserveControlId`

