#endif // wxUSE_GUI
+// ---------------------------------------------------------------------------
+// global data
+// ---------------------------------------------------------------------------
+
+extern WXDLLIMPEXP_DATA_BASE(HINSTANCE) wxhInstance;
+
// ---------------------------------------------------------------------------
// define things missing from some compilers' headers
// ---------------------------------------------------------------------------
#define wxZeroMemory(obj) memset((void*) & obj, 0, sizeof(obj))
#endif
+// This one is a macro so that it can be tested with #ifdef, it will be
+// undefined if it cannot be implemented for a given compiler.
+// Vc++, bcc, dmc, ow, mingw, codewarrior (and rsxnt) have _get_osfhandle.
+// Cygwin has get_osfhandle. Others are currently unknown, e.g. Salford,
+// Intel, Visual Age.
+#if defined(__WXWINCE__)
+ #define wxGetOSFHandle(fd) ((HANDLE)fd)
+#elif defined(__CYGWIN__)
+ #define wxGetOSFHandle(fd) ((HANDLE)get_osfhandle(fd))
+#elif defined(__VISUALC__) \
+ || defined(__BORLANDC__) \
+ || defined(__DMC__) \
+ || defined(__WATCOMC__) \
+ || (defined(__GNUWIN32__) || defined(__MINGW32__)) \
+ || (defined(__MWERKS__) && defined(__MSL__))
+ #define wxGetOSFHandle(fd) ((HANDLE)_get_osfhandle(fd))
+#endif
+
#if wxUSE_GUI
#include <wx/gdicmn.h>
DECLARE_NO_COPY_CLASS(GlobalPtr)
};
+// register the class when it is first needed and unregister it in dtor
+class ClassRegistrar
+{
+public:
+ // ctor doesn't register the class, call Initialize() for this
+ ClassRegistrar() { m_registered = -1; }
+
+ // return true if the class is already registered
+ bool IsInitialized() const { return m_registered != -1; }
+
+ // return true if the class had been already registered
+ bool IsRegistered() const { return m_registered == 1; }
+
+ // try to register the class if not done yet, return true on success
+ bool Register(const WNDCLASS& wc)
+ {
+ // we should only be called if we hadn't been initialized yet
+ wxASSERT_MSG( m_registered == -1,
+ _T("calling ClassRegistrar::Register() twice?") );
+
+ m_registered = ::RegisterClass(&wc) ? 1 : 0;
+ if ( !IsRegistered() )
+ {
+ wxLogLastError(_T("RegisterClassEx()"));
+ }
+ else
+ {
+ m_clsname = wc.lpszClassName;
+ }
+
+ return m_registered == 1;
+ }
+
+ // get the name of the registered class (returns empty string if not
+ // registered)
+ const wxString& GetName() const { return m_clsname; }
+
+ // unregister the class if it had been registered
+ ~ClassRegistrar()
+ {
+ if ( IsRegistered() )
+ {
+ if ( !::UnregisterClass(m_clsname, wxhInstance) )
+ {
+ wxLogLastError(_T("UnregisterClass"));
+ }
+ }
+ }
+
+private:
+ // initial value is -1 which means that we hadn't tried registering the
+ // class yet, it becomes true or false (1 or 0) when Initialize() is called
+ int m_registered;
+
+ // the name of the class, only non empty if it had been registered
+ wxString m_clsname;
+};
+
// ---------------------------------------------------------------------------
// macros to make casting between WXFOO and FOO a bit easier: the GetFoo()
// returns Foo cast to the Windows type for oruselves, while GetFooOf() takes
#endif // wxUSE_GUI
-// ---------------------------------------------------------------------------
-// global data
-// ---------------------------------------------------------------------------
-
-extern WXDLLIMPEXP_DATA_BASE(HINSTANCE) wxhInstance;
-
// ---------------------------------------------------------------------------
// global functions
// ---------------------------------------------------------------------------