+ int mode;
+ int refresh = MGL_DEFAULT_REFRESH;
+
+#if wxUSE_SYSTEM_OPTIONS
+ if ( wxSystemOptions::HasOption(wxT("mgl.screen-refresh")) )
+ refresh = wxSystemOptions::GetOptionInt(wxT("mgl.screen-refresh"));
+#endif
+
+ mode = MGL_findMode(displayMode.GetWidth(),
+ displayMode.GetHeight(),
+ displayMode.GetDepth());
+ if ( mode == -1 )
+ {
+ wxLogError(_("Mode %ix%i-%i not available."),
+ displayMode.GetWidth(),
+ displayMode.GetHeight(),
+ displayMode.GetDepth());
+ return false;
+ }
+ g_displayDC = new MGLDisplayDC(mode, 1, refresh);
+ if ( !g_displayDC->isValid() )
+ {
+ delete g_displayDC;
+ g_displayDC = NULL;
+ return false;
+ }
+
+ g_winMng = MGL_wmCreate(g_displayDC->getDC());
+ if (!g_winMng)
+ return false;
+
+ return true;
+}
+
+static void wxDestroyMGL_WM()
+{
+ if ( g_winMng )
+ {
+ MGL_wmDestroy(g_winMng);
+ g_winMng = NULL;
+ }
+ if ( g_displayDC )
+ {
+ delete g_displayDC;
+ g_displayDC = NULL;
+ }