chiark / gitweb /
Patch from James H to enable a single monolithic binary to be built
authorSimon Tatham <anakin@pobox.com>
Tue, 6 Jan 2009 23:26:18 +0000 (23:26 +0000)
committerSimon Tatham <anakin@pobox.com>
Tue, 6 Jan 2009 23:26:18 +0000 (23:26 +0000)
alongside the individual puzzle binaries, on Windows only. (MacOS
already has it, of course; Unix would require about as much work
again.)

[originally from svn r8396]

Recipe
midend.c
puzzles.h
windows.c

diff --git a/Recipe b/Recipe
index e377acde08d3a2f59adbd38a17d4cdf293359bdf..3925447711b53e1dac8081f95a778944af4c6e17 100644 (file)
--- a/Recipe
+++ b/Recipe
@@ -17,8 +17,9 @@
 
 !srcdir icons/
 
-WINDOWS  = windows printing
+WINDOWS_COMMON = printing
          + user32.lib gdi32.lib comctl32.lib comdlg32.lib winspool.lib
+WINDOWS  = windows WINDOWS_COMMON
 COMMON   = midend drawing misc malloc random version
 GTK      = gtk printing ps
 # Objects needed for auxiliary command-line programs.
@@ -56,6 +57,8 @@ const int gamecount = lenof(gamelist);
 # Unix standalone application for special-purpose obfuscation.
 obfusc : [U] obfusc STANDALONE
 
+puzzles  : [G] windows[COMBINED] WINDOWS_COMMON COMMON ALL noicon.res
+
 # Mac OS X unified application containing all the puzzles.
 Puzzles  : [MX] osx osx.icns osx-info.plist COMMON ALL
 # For OS X, we must create the online help and include it in the
index 22d823bf28e7d39b35c17b507f337b315558ef57..df395e06ad09b1ead26484d99d3d4277caab3ccb 100644 (file)
--- a/midend.c
+++ b/midend.c
@@ -278,6 +278,8 @@ void midend_size(midend *me, int *x, int *y, int user_size)
     *y = me->winheight;
 }
 
+int midend_tilesize(midend *me) { return me->tilesize; }
+
 void midend_set_params(midend *me, game_params *params)
 {
     me->ourgame->free_params(me->params);
index f2ef978d99d0419fffd4807a4f0cbe9142875a9e..b375c3b905a9172e538ba9532d8837ad2429fb41 100644 (file)
--- a/puzzles.h
+++ b/puzzles.h
@@ -259,6 +259,7 @@ char *midend_deserialise(midend *me,
                          void *rctx);
 /* Printing functions supplied by the mid-end */
 char *midend_print_puzzle(midend *me, document *doc, int with_soln);
+int midend_tilesize(midend *me);
 
 /*
  * malloc.c
index 2a2262b88d2a370f46c228cbe66fbcacfbdbbcd4..6bcf895ed8310130a1e8f1ccb15ef5835d12644b 100644 (file)
--- a/windows.c
+++ b/windows.c
@@ -44,6 +44,7 @@
 #define IDM_LOAD      0x00F0
 #define IDM_PRINT     0x0100
 #define IDM_PRESETS   0x0110
+#define IDM_GAMES     0x0300
 
 #define IDM_KEYEMUL   0x0400
 
@@ -60,7 +61,6 @@ static HINSTANCE hh_dll;
 #endif /* NO_HTMLHELP */
 enum { NONE, HLP, CHM } help_type;
 char *help_path;
-const char *help_topic;
 int help_has_contents;
 
 #ifndef FILENAME_MAX
@@ -71,6 +71,12 @@ int help_has_contents;
 #define HGDI_ERROR ((HANDLE)GDI_ERROR)
 #endif
 
+#ifdef COMBINED
+#define CLASSNAME "Puzzles"
+#else
+#define CLASSNAME thegame.name
+#endif
+
 #ifdef _WIN32_WCE
 
 /*
@@ -111,7 +117,7 @@ BOOL GetKeyboardState(PBYTE pb)
   return FALSE;
 }
 
-static TCHAR wGameName[256];
+static TCHAR wClassName[256], wGameName[256];
 
 #endif
 
@@ -122,7 +128,7 @@ static int debug_got_console = 0;
 
 void dputs(char *buf)
 {
-    DWORD dw;
+    /*DWORD dw;
 
     if (!debug_got_console) {
        if (AllocConsole()) {
@@ -137,8 +143,10 @@ void dputs(char *buf)
     if (debug_hdl != INVALID_HANDLE_VALUE) {
        WriteFile(debug_hdl, buf, strlen(buf), &dw, NULL);
     }
-    fputs(buf, debug_fp);
-    fflush(debug_fp);
+    if (debug_fp) {
+      fputs(buf, debug_fp);
+      fflush(debug_fp);
+    }*/
     OutputDebugString(buf);
 }
 
@@ -161,7 +169,7 @@ void debug_printf(char *fmt, ...)
 #define WINFLAGS (WS_CAPTION | WS_SYSMENU)
 #endif
 
-static void new_game_size(frontend *fe);
+static void new_game_size(frontend *fe, float scale);
 
 struct font {
     HFONT font;
@@ -182,6 +190,7 @@ struct blitter {
 enum { CFG_PRINT = CFG_FRONTEND_SPECIFIC };
 
 struct frontend {
+    const game *game;
     midend *me;
     HWND hwnd, statusbar, cfgbox;
 #ifdef _WIN32_WCE
@@ -219,8 +228,21 @@ struct frontend {
     int linewidth;
     drawing *dr;
     int xmin, ymin;
+    float puzz_scale;
 };
 
+void frontend_free(frontend *fe)
+{
+    midend_free(fe->me);
+
+    sfree(fe->colours);
+    sfree(fe->brushes);
+    sfree(fe->pens);
+    sfree(fe->presets);
+
+    sfree(fe);
+}
+
 static void update_type_menu_tick(frontend *fe);
 static void update_copy_menu_greying(frontend *fe);
 
@@ -964,7 +986,7 @@ void print(frontend *fe)
            if (!nme) {
                game_params *params;
 
-               nme = midend_new(NULL, &thegame, NULL, NULL);
+               nme = midend_new(NULL, fe->game, NULL, NULL);
 
                /*
                 * Set the non-interactive mid-end to have the same
@@ -972,7 +994,7 @@ void print(frontend *fe)
                 */
                params = midend_get_params(fe->me);
                midend_set_params(nme, params);
-               thegame.free_params(params);
+               fe->game->free_params(params);
            }
 
            midend_new_game(nme);
@@ -1018,7 +1040,7 @@ void print(frontend *fe)
     memset(&fe->di, 0, sizeof(fe->di));
     fe->di.cbSize = sizeof(fe->di);
     sprintf(doctitle, "Printed puzzles from %s (from Simon Tatham's"
-           " Portable Puzzle Collection)", thegame.name);
+           " Portable Puzzle Collection)", fe->game->name);
     fe->di.lpszDocName = doctitle;
     fe->di.lpszOutput = NULL;
     fe->di.lpszDatatype = NULL;
@@ -1085,11 +1107,16 @@ void write_clip(HWND hwnd, char *data)
     data2[j] = '\0';
 
     clipdata = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, len + 1);
-    if (!clipdata)
+    if (!clipdata) {
+        sfree(data2);
        return;
+    }
     lock = GlobalLock(clipdata);
-    if (!lock)
+    if (!lock) {
+        GlobalFree(clipdata);
+        sfree(data2);
        return;
+    }
     memcpy(lock, data2, len);
     ((unsigned char *) lock)[len] = 0;
     GlobalUnlock(clipdata);
@@ -1144,7 +1171,6 @@ static void init_help(void)
        if (htmlhelp) {
            help_path = dupstr(b);
            help_type = CHM;
-           help_topic = thegame.htmlhelp_topic;
            return;
        }
     }
@@ -1160,8 +1186,6 @@ static void init_help(void)
        help_path = dupstr(b);
        help_type = HLP;
 
-       help_topic = thegame.winhelp_topic;
-
        /*
         * See if there's a .CNT file alongside it.
         */
@@ -1309,7 +1333,7 @@ static void get_menu_size(HWND wh, RECT *r)
 
 static int check_window_resize(frontend *fe, int cx, int cy,
                                int *px, int *py,
-                               int *wx, int *wy, int resize)
+                               int *wx, int *wy)
 {
     RECT r;
     int x, y, sy = get_statusbar_height(fe), changed = 0;
@@ -1322,7 +1346,7 @@ static int check_window_resize(frontend *fe, int cx, int cy,
      * See if we actually got the window size we wanted, and adjust
      * the puzzle size if not.
      */
-    midend_size(fe->me, &x, &y, resize);
+    midend_size(fe->me, &x, &y, TRUE);
     if (x != cx || y != cy) {
         /*
          * Resize the window, now we know what size we _really_
@@ -1340,6 +1364,9 @@ static int check_window_resize(frontend *fe, int cx, int cy,
     *px = x;
     *py = y;
 
+    fe->puzz_scale =
+      (float)midend_tilesize(fe->me) / (float)fe->game->preferred_tilesize;
+
     return changed;
 }
 
@@ -1357,7 +1384,7 @@ static void check_window_size(frontend *fe, int *px, int *py)
     cx = r.right - r.left;
     cy = r.bottom - r.top;
 
-    if (check_window_resize(fe, cx, cy, px, py, &wx, &wy, FALSE)) {
+    if (check_window_resize(fe, cx, cy, px, py, &wx, &wy)) {
 #ifdef _WIN32_WCE
         SetWindowPos(fe->hwnd, NULL, 0, 0, wx, wy,
                     SWP_NOMOVE | SWP_NOZORDER);
@@ -1410,27 +1437,21 @@ static TBBUTTON tbNumpadButtons[] =
 };
 #endif
 
-static frontend *new_window(HINSTANCE inst, char *game_id, char **error)
+/*
+ * Allocate a new frontend structure and create its main window.
+ */
+static frontend *frontend_new(HINSTANCE inst)
 {
     frontend *fe;
-    int x, y;
-    RECT r;
+    const char *nogame = "Puzzles (no game selected)";
 
     fe = snew(frontend);
 
-    fe->me = midend_new(fe, &thegame, &win_drawing, fe);
-
-    if (game_id) {
-        *error = midend_game_id(fe->me, game_id);
-        if (*error) {
-            midend_free(fe->me);
-            sfree(fe);
-            return NULL;
-        }
-    }
-
     fe->inst = inst;
 
+    fe->game = NULL;
+    fe->me = NULL;
+
     fe->timer = 0;
     fe->hwnd = NULL;
 
@@ -1440,17 +1461,103 @@ static frontend *new_window(HINSTANCE inst, char *game_id, char **error)
     fe->dr = NULL;
     fe->fontstart = 0;
 
-    midend_new_game(fe->me);
-
     fe->fonts = NULL;
     fe->nfonts = fe->fontsize = 0;
 
+    fe->colours = NULL;
+    fe->brushes = NULL;
+    fe->pens = NULL;
+
+    fe->puzz_scale = 1.0;
+
+    #ifdef _WIN32_WCE
+    MultiByteToWideChar (CP_ACP, 0, nogame, -1, wGameName, 256);
+    fe->hwnd = CreateWindowEx(0, wClassName, wGameName,
+                             WS_VISIBLE,
+                             CW_USEDEFAULT, CW_USEDEFAULT,
+                             CW_USEDEFAULT, CW_USEDEFAULT,
+                             NULL, NULL, inst, NULL);
+
+    {
+       SHMENUBARINFO mbi;
+       RECT rc, rcBar, rcTB, rcClient;
+
+       memset (&mbi, 0, sizeof(SHMENUBARINFO));
+       mbi.cbSize     = sizeof(SHMENUBARINFO);
+       mbi.hwndParent = fe->hwnd;
+       mbi.nToolBarId = IDR_MENUBAR1;
+       mbi.hInstRes   = inst;
+
+       SHCreateMenuBar(&mbi);
+
+       GetWindowRect(fe->hwnd, &rc);
+       GetWindowRect(mbi.hwndMB, &rcBar);
+       rc.bottom -= rcBar.bottom - rcBar.top;
+       MoveWindow(fe->hwnd, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, FALSE);
+
+        fe->numpad = NULL;
+    }
+#else
+    fe->hwnd = CreateWindowEx(0, CLASSNAME, nogame,
+                             WS_OVERLAPPEDWINDOW &~
+                             (WS_MAXIMIZEBOX),
+                             CW_USEDEFAULT, CW_USEDEFAULT,
+                             CW_USEDEFAULT, CW_USEDEFAULT,
+                             NULL, NULL, inst, NULL);
+    if (!fe->hwnd) {
+        DWORD lerr = GetLastError();
+        printf("no window: 0x%x\n", lerr);
+    }
+#endif
+
+    fe->gamemenu = NULL;
+    fe->presets = NULL;
+
+    fe->statusbar = NULL;
+    fe->bitmap = NULL;
+
+    SetWindowLong(fe->hwnd, GWL_USERDATA, (LONG)fe);
+
+    return fe;
+}
+
+/*
+ * Populate a frontend structure with a (new) game and midend structure, and
+ * create any window furniture that it needs.
+ *
+ * Previously-allocated memory and window furniture will be freed by this function.
+ */
+static int new_game(frontend *fe, const game *game, char *game_id, char **error)
+{
+    int x, y;
+    RECT r;
+
+    fe->game = game;
+
+    if (fe->me) midend_free(fe->me);
+    fe->me = midend_new(fe, fe->game, &win_drawing, fe);
+
+    if (game_id) {
+        *error = midend_game_id(fe->me, game_id);
+        if (*error) {
+            midend_free(fe->me);
+            sfree(fe);
+            return -1;
+        }
+    }
+
+    midend_new_game(fe->me);
+
     {
        int i, ncolours;
         float *colours;
 
         colours = midend_colours(fe->me, &ncolours);
 
+        if (fe->colours) sfree(fe->colours);
+        if (fe->brushes) sfree(fe->brushes);
+        if (fe->pens) sfree(fe->pens);
+
        fe->colours = snewn(ncolours, COLORREF);
        fe->brushes = snewn(ncolours, HBRUSH);
        fe->pens = snewn(ncolours, HPEN);
@@ -1465,11 +1572,13 @@ static frontend *new_window(HINSTANCE inst, char *game_id, char **error)
         sfree(colours);
     }
 
+    if (fe->statusbar)
+        DestroyWindow(fe->statusbar);
     if (midend_wants_statusbar(fe->me)) {
        fe->statusbar = CreateWindowEx(0, STATUSCLASSNAME, TEXT("ooh"),
                                       WS_CHILD | WS_VISIBLE,
                                       0, 0, 0, 0, /* status bar does these */
-                                      NULL, NULL, inst, NULL);
+                                      NULL, NULL, fe->inst, NULL);
     } else
         fe->statusbar = NULL;
 
@@ -1482,65 +1591,42 @@ static frontend *new_window(HINSTANCE inst, char *game_id, char **error)
     AdjustWindowRectEx(&r, WINFLAGS, TRUE, 0);
 
 #ifdef _WIN32_WCE
-    fe->hwnd = CreateWindowEx(0, wGameName, wGameName,
-                             WS_VISIBLE,
-                             CW_USEDEFAULT, CW_USEDEFAULT,
-                             CW_USEDEFAULT, CW_USEDEFAULT,
-                             NULL, NULL, inst, NULL);
-
+    if (fe->numpad)
+        DestroyWindow(fe->numpad);
+    if (fe->game->flags & REQUIRE_NUMPAD)
     {
-       SHMENUBARINFO mbi;
-       RECT rc, rcBar, rcTB, rcClient;
-
-       memset (&mbi, 0, sizeof(SHMENUBARINFO));
-       mbi.cbSize     = sizeof(SHMENUBARINFO);
-       mbi.hwndParent = fe->hwnd;
-       mbi.nToolBarId = IDR_MENUBAR1;
-       mbi.hInstRes   = inst;
-
-       SHCreateMenuBar(&mbi);
-
-       GetWindowRect(fe->hwnd, &rc);
-       GetWindowRect(mbi.hwndMB, &rcBar);
-       rc.bottom -= rcBar.bottom - rcBar.top;
-       MoveWindow(fe->hwnd, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, FALSE);
-
-       if (thegame.flags & REQUIRE_NUMPAD)
-       {
-           fe->numpad = CreateToolbarEx (fe->hwnd,
-                                         WS_VISIBLE | WS_CHILD | CCS_NOPARENTALIGN | TBSTYLE_FLAT,
-                                         0, 10, inst, IDR_PADTOOLBAR,
-                                         tbNumpadButtons, sizeof (tbNumpadButtons) / sizeof (TBBUTTON),
-                                         0, 0, 14, 15, sizeof (TBBUTTON));
-           GetWindowRect(fe->numpad, &rcTB);
-           GetClientRect(fe->hwnd, &rcClient);
-           MoveWindow(fe->numpad, 
-                      0, 
-                      rcClient.bottom - (rcTB.bottom - rcTB.top) - 1,
-                      rcClient.right,
-                      rcTB.bottom - rcTB.top,
-                      FALSE);
-           SendMessage(fe->numpad, TB_SETINDENT, (rcClient.right - (10 * 21)) / 2, 0);
-       }
-       else
-           fe->numpad = NULL;
-    }
+        fe->numpad = CreateToolbarEx (fe->hwnd,
+                                      WS_VISIBLE | WS_CHILD | CCS_NOPARENTALIGN | TBSTYLE_FLAT,
+                                      0, 10, fe->inst, IDR_PADTOOLBAR,
+                                      tbNumpadButtons, sizeof (tbNumpadButtons) / sizeof (TBBUTTON),
+                                      0, 0, 14, 15, sizeof (TBBUTTON));
+        GetWindowRect(fe->numpad, &rcTB);
+        GetClientRect(fe->hwnd, &rcClient);
+        MoveWindow(fe->numpad, 
+                   0, 
+                   rcClient.bottom - (rcTB.bottom - rcTB.top) - 1,
+                   rcClient.right,
+                   rcTB.bottom - rcTB.top,
+                   FALSE);
+        SendMessage(fe->numpad, TB_SETINDENT, (rcClient.right - (10 * 21)) / 2, 0);
+    }
+    else {
+       fe->numpad = NULL;
+    }
+    MultiByteToWideChar (CP_ACP, 0, fe->game->name, -1, wGameName, 256);
+    SetWindowText(fe->hwnd, wGameName);
 #else
-    fe->hwnd = CreateWindowEx(0, thegame.name, thegame.name,
-                             WS_OVERLAPPEDWINDOW &~
-                             (WS_MAXIMIZEBOX),
-                             CW_USEDEFAULT, CW_USEDEFAULT,
-                             r.right - r.left, r.bottom - r.top,
-                             NULL, NULL, inst, NULL);
+    SetWindowText(fe->hwnd, fe->game->name);
 #endif
 
+    if (fe->statusbar)
+        DestroyWindow(fe->statusbar);
     if (midend_wants_statusbar(fe->me)) {
        RECT sr;
-       DestroyWindow(fe->statusbar);
        fe->statusbar = CreateWindowEx(0, STATUSCLASSNAME, TEXT("ooh"),
                                       WS_CHILD | WS_VISIBLE,
                                       0, 0, 0, 0, /* status bar does these */
-                                      fe->hwnd, NULL, inst, NULL);
+                                      fe->hwnd, NULL, fe->inst, NULL);
 #ifdef _WIN32_WCE
        /* Flat status bar looks better on the Pocket PC */
        SendMessage(fe->statusbar, SB_SIMPLE, (WPARAM) TRUE, 0);
@@ -1564,6 +1650,8 @@ static frontend *new_window(HINSTANCE inst, char *game_id, char **error)
     }
 
     {
+        HMENU oldmenu = GetMenu(fe->hwnd);
+
 #ifndef _WIN32_WCE
        HMENU bar = CreateMenu();
        HMENU menu = CreateMenu();
@@ -1583,8 +1671,10 @@ static frontend *new_window(HINSTANCE inst, char *game_id, char **error)
        AppendMenu(menu, MF_ENABLED, IDM_SEED, TEXT("Rando&m Seed..."));
 #endif
 
+        if (fe->presets)
+            sfree(fe->presets);
        if ((fe->npresets = midend_num_presets(fe->me)) > 0 ||
-           thegame.can_configure) {
+           fe->game->can_configure) {
            int i;
 #ifndef _WIN32_WCE
            HMENU sub = CreateMenu();
@@ -1616,20 +1706,42 @@ static frontend *new_window(HINSTANCE inst, char *game_id, char **error)
                AppendMenu(sub, MF_ENABLED, IDM_PRESETS + 0x10 * i, wName);
 #endif
            }
-           if (thegame.can_configure) {
+           if (fe->game->can_configure) {
                AppendMenu(sub, MF_ENABLED, IDM_CONFIG, TEXT("&Custom..."));
            }
 
            fe->typemenu = sub;
-       } else
+       } else {
            fe->typemenu = INVALID_HANDLE_VALUE;
+            fe->presets = NULL;
+        }
+
+#ifdef COMBINED
+#ifdef _WIN32_WCE
+#error Windows CE does not support COMBINED build.
+#endif
+        {
+            HMENU games = CreateMenu();
+            int i;
+
+            AppendMenu(menu, MF_SEPARATOR, 0, 0);
+            AppendMenu(menu, MF_ENABLED|MF_POPUP, (UINT)games, "&Other");
+            for (i = 0; i < gamecount; i++) {
+                if (strcmp(gamelist[i]->name, fe->game->name) != 0) {
+                    /* only include those games that aren't the same as the
+                     * game we're currently playing. */
+                    AppendMenu(games, MF_ENABLED, IDM_GAMES + i, gamelist[i]->name);
+                }
+            }
+        }
+#endif
 
        AppendMenu(menu, MF_SEPARATOR, 0, 0);
 #ifndef _WIN32_WCE
        AppendMenu(menu, MF_ENABLED, IDM_LOAD, TEXT("&Load..."));
        AppendMenu(menu, MF_ENABLED, IDM_SAVE, TEXT("&Save..."));
        AppendMenu(menu, MF_SEPARATOR, 0, 0);
-       if (thegame.can_print) {
+       if (fe->game->can_print) {
            AppendMenu(menu, MF_ENABLED, IDM_PRINT, TEXT("&Print..."));
            AppendMenu(menu, MF_SEPARATOR, 0, 0);
        }
@@ -1637,12 +1749,12 @@ static frontend *new_window(HINSTANCE inst, char *game_id, char **error)
        AppendMenu(menu, MF_ENABLED, IDM_UNDO, TEXT("Undo"));
        AppendMenu(menu, MF_ENABLED, IDM_REDO, TEXT("Redo"));
 #ifndef _WIN32_WCE
-       if (thegame.can_format_as_text_ever) {
+       if (fe->game->can_format_as_text_ever) {
            AppendMenu(menu, MF_SEPARATOR, 0, 0);
            AppendMenu(menu, MF_ENABLED, IDM_COPY, TEXT("&Copy"));
        }
 #endif
-       if (thegame.can_solve) {
+       if (fe->game->can_solve) {
            AppendMenu(menu, MF_SEPARATOR, 0, 0);
            AppendMenu(menu, MF_ENABLED, IDM_SOLVE, TEXT("Sol&ve"));
        }
@@ -1655,29 +1767,31 @@ static frontend *new_window(HINSTANCE inst, char *game_id, char **error)
        AppendMenu(menu, MF_ENABLED, IDM_ABOUT, TEXT("&About"));
 #ifndef _WIN32_WCE
         if (help_type != NONE) {
-           AppendMenu(menu, MF_SEPARATOR, 0, 0);
+            char *item;
+            AppendMenu(menu, MF_SEPARATOR, 0, 0);
             AppendMenu(menu, MF_ENABLED, IDM_HELPC, TEXT("&Contents"));
-            if (help_topic) {
-                char *item;
-                assert(thegame.name);
-                item = snewn(10+strlen(thegame.name), char); /*ick*/
-                sprintf(item, "&Help on %s", thegame.name);
-                AppendMenu(menu, MF_ENABLED, IDM_GAMEHELP, item);
-                sfree(item);
-            }
+            assert(fe->game->name);
+            item = snewn(10+strlen(fe->game->name), char); /*ick*/
+            sprintf(item, "&Help on %s", fe->game->name);
+            AppendMenu(menu, MF_ENABLED, IDM_GAMEHELP, item);
+            sfree(item);
         }
+        DestroyMenu(oldmenu);
        SetMenu(fe->hwnd, bar);
         get_menu_size(fe->hwnd, &menusize);
         fe->xmin = (menusize.right - menusize.left) + 25;
 #endif
     }
 
+    if (fe->bitmap) DeleteObject(fe->bitmap);
     fe->bitmap = NULL;
-    new_game_size(fe); /* initialises fe->bitmap */
-    check_window_size(fe, &x, &y);
+    new_game_size(fe, fe->puzz_scale); /* initialises fe->bitmap */
 
-    SetWindowLong(fe->hwnd, GWL_USERDATA, (LONG)fe);
+    return 0;
+}
 
+static void show_window(frontend *fe)
+{
     ShowWindow(fe->hwnd, SW_SHOWNORMAL);
     SetForegroundWindow(fe->hwnd);
 
@@ -1685,8 +1799,6 @@ static frontend *new_window(HINSTANCE inst, char *game_id, char **error)
     update_copy_menu_greying(fe);
 
     midend_redraw(fe->me);
-
-    return fe;
 }
 
 #ifdef _WIN32_WCE
@@ -1732,13 +1844,13 @@ static int CALLBACK AboutDlgProc(HWND hwnd, UINT msg,
 
            make_dialog_full_screen(hwnd);
 
-           sprintf(title, "About %.250s", thegame.name);
+           sprintf(title, "About %.250s", fe->game->name);
            SetDlgItemTextA(hwnd, IDC_ABOUT_CAPTION, title);
 
            SendDlgItemMessage(hwnd, IDC_ABOUT_CAPTION, WM_SETFONT,
                               (WPARAM) dialog_title_font(), 0);
 
-           SetDlgItemTextA(hwnd, IDC_ABOUT_GAME, thegame.name);
+           SetDlgItemTextA(hwnd, IDC_ABOUT_GAME, fe->game->name);
            SetDlgItemTextA(hwnd, IDC_ABOUT_VERSION, ver);
        }
 #endif
@@ -1778,8 +1890,8 @@ static config_item *frontend_get_config(frontend *fe, int which,
        config_item *ret;
        int i;
 
-       *wintitle = snewn(40 + strlen(thegame.name), char);
-       sprintf(*wintitle, "%s print setup", thegame.name);
+       *wintitle = snewn(40 + strlen(fe->game->name), char);
+       sprintf(*wintitle, "%s print setup", fe->game->name);
 
        ret = snewn(8, config_item);
 
@@ -1821,7 +1933,7 @@ static config_item *frontend_get_config(frontend *fe, int which,
        ret[i].ival = FALSE;
        i++;
 
-       if (thegame.can_print_in_colour) {
+       if (fe->game->can_print_in_colour) {
            ret[i].name = "Print in colour";
            ret[i].type = C_BOOLEAN;
            ret[i].sval = NULL;
@@ -1857,7 +1969,7 @@ static char *frontend_set_config(frontend *fe, int which, config_item *cfg)
            return "Print size should be positive";
        fe->printcurr = cfg[4].ival;
        fe->printsolns = cfg[5].ival;
-       fe->printcolour = thegame.can_print_in_colour && cfg[6].ival;
+       fe->printcolour = fe->game->can_print_in_colour && cfg[6].ival;
        return NULL;
     } else {
        assert(!"We should never get here");
@@ -2110,9 +2222,9 @@ static void about(frontend *fe)
     int nstrings = 0;
     char titlebuf[512];
 
-    sprintf(titlebuf, "About %.250s", thegame.name);
+    sprintf(titlebuf, "About %.250s", fe->game->name);
 
-    strings[nstrings++] = thegame.name;
+    strings[nstrings++] = fe->game->name;
     strings[nstrings++] = "from Simon Tatham's Portable Puzzle Collection";
     strings[nstrings++] = ver;
 
@@ -2547,13 +2659,19 @@ static void new_bitmap(frontend *fe, int x, int y)
     ReleaseDC(fe->hwnd, hdc);
 }
 
-static void new_game_size(frontend *fe)
+static void new_game_size(frontend *fe, float scale)
 {
     RECT r, sr;
     int x, y;
 
     get_max_puzzle_size(fe, &x, &y);
     midend_size(fe->me, &x, &y, FALSE);
+
+    if (scale != 1.0) {
+      x = (int)((float)x * fe->puzz_scale);
+      y = (int)((float)y * fe->puzz_scale);
+      midend_size(fe->me, &x, &y, TRUE);
+    }
     fe->ymin = (fe->xmin * y) / x;
 
     r.left = r.top = 0;
@@ -2624,7 +2742,7 @@ static void adjust_game_size(frontend *fe, RECT *proposed, int isedge,
     if (check_window_resize(fe,
                             (cr.right - cr.left) + xdiff,
                             (cr.bottom - cr.top) + ydiff,
-                            &nx, &ny, &wx, &wy, TRUE)) {
+                            &nx, &ny, &wx, &wy)) {
         new_bitmap(fe, nx, ny);
         midend_force_redraw(fe->me);
     } else {
@@ -2670,7 +2788,7 @@ static void update_copy_menu_greying(frontend *fe)
 static void new_game_type(frontend *fe)
 {
     midend_new_game(fe->me);
-    new_game_size(fe);
+    new_game_size(fe, 1.0);
     update_type_menu_tick(fe);
     update_copy_menu_greying(fe);
 }
@@ -2859,7 +2977,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
                            break;
                        }
 
-                       new_game_size(fe);
+                       new_game_size(fe, 1.0);
                    }
                }
            }
@@ -2870,10 +2988,20 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
            start_help(fe, NULL);
            break;
           case IDM_GAMEHELP:
-           start_help(fe, help_topic);
+            assert(help_type != NONE);
+           start_help(fe, help_type == CHM ?
+                       fe->game->htmlhelp_topic : fe->game->winhelp_topic);
             break;
 #endif
          default:
+#ifdef COMBINED
+            if (wParam >= IDM_GAMES && wParam < (IDM_GAMES + (WPARAM)gamecount)) {
+                int p = wParam - IDM_GAMES;
+                char *error;
+
+                new_game(fe, gamelist[p], NULL, &error);
+            } else
+#endif
            {
                int p = ((wParam &~ 0xF) - IDM_PRESETS) / 0x10;
 
@@ -2889,7 +3017,8 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
 #ifndef _WIN32_WCE
        stop_help(fe);
 #endif
-       PostQuitMessage(0);
+        frontend_free(fe);
+        PostQuitMessage(0);
        return 0;
       case WM_PAINT:
        {
@@ -3019,7 +3148,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
 #ifndef _WIN32_WCE
                button = LEFT_BUTTON;
 #else
-               if ((thegame.flags & REQUIRE_RBUTTON) == 0)
+               if ((fe->game->flags & REQUIRE_RBUTTON) == 0)
                    button = LEFT_BUTTON;
                else
                {
@@ -3162,9 +3291,11 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
 {
     MSG msg;
     char *error;
+    const game *gg;
+    frontend *fe;
 
 #ifdef _WIN32_WCE
-    MultiByteToWideChar (CP_ACP, 0, thegame.name, -1, wGameName, 256);
+    MultiByteToWideChar (CP_ACP, 0, CLASSNAME, -1, wClassName, 256);
     if (FindPreviousInstance ())
         return 0;
 #endif
@@ -3188,9 +3319,9 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
        wndclass.hbrBackground = NULL;
        wndclass.lpszMenuName = NULL;
 #ifdef _WIN32_WCE
-       wndclass.lpszClassName = wGameName;
+       wndclass.lpszClassName = wClassName;
 #else
-       wndclass.lpszClassName = thegame.name;
+       wndclass.lpszClassName = CLASSNAME;
 #endif
 
        RegisterClass(&wndclass);
@@ -3201,12 +3332,49 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
 
     init_help();
 
-    if (!new_window(inst, *cmdline ? cmdline : NULL, &error)) {
+#ifdef COMBINED
+    gg = gamelist[0];
+    {
+        int i;
+        for (i = 0; i < gamecount; i++) {
+           const char *p = gamelist[i]->name;
+           char *q = cmdline;
+           while (*q && isspace((unsigned char)*q))
+               q++;
+           while (*p && *q) {
+               if (isspace((unsigned char)*p)) {
+                   while (*q && isspace((unsigned char)*q))
+                       q++;
+               } else {
+                   if (tolower((unsigned char)*p) !=
+                       tolower((unsigned char)*q))
+                       break;
+                   q++;
+               }
+               p++;
+           }
+           if (!*p) {
+                gg = gamelist[i];
+                cmdline = q;
+                if (*cmdline) {
+                   while (*cmdline && isspace((unsigned char)*cmdline))
+                       cmdline++;
+                }
+            }
+        }
+    }
+#else
+    gg = &thegame;
+#endif
+
+    fe = frontend_new(inst);
+    if (new_game(fe, gg, *cmdline ? cmdline : NULL, &error)) {
        char buf[128];
-       sprintf(buf, "%.100s Error", thegame.name);
+       sprintf(buf, "%.100s Error", gg->name);
        MessageBox(NULL, error, buf, MB_OK|MB_ICONERROR);
        return 1;
     }
+    show_window(fe);
 
     while (GetMessage(&msg, NULL, 0, 0)) {
        DispatchMessage(&msg);
@@ -3216,3 +3384,4 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
 
     return msg.wParam;
 }
+/* vim: set shiftwidth=4 tabstop=8: */