+#ifndef _WIN32_WCE
+
+/*
+ * Start Help.
+ */
+static void start_help(frontend *fe, const char *topic)
+{
+ char *str = NULL;
+ int cmd;
+
+ switch (help_type) {
+ case HLP:
+ assert(help_path);
+ if (topic) {
+ str = snewn(10+strlen(topic), char);
+ sprintf(str, "JI(`',`%s')", topic);
+ cmd = HELP_COMMAND;
+ } else if (help_has_contents) {
+ cmd = HELP_FINDER;
+ } else {
+ cmd = HELP_CONTENTS;
+ }
+ WinHelp(fe->hwnd, help_path, cmd, (DWORD)str);
+ fe->help_running = TRUE;
+ break;
+ case CHM:
+#ifndef NO_HTMLHELP
+ assert(help_path);
+ assert(htmlhelp);
+ if (topic) {
+ str = snewn(20 + strlen(topic) + strlen(help_path), char);
+ sprintf(str, "%s::/%s.html>main", help_path, topic);
+ } else {
+ str = dupstr(help_path);
+ }
+ htmlhelp(fe->hwnd, str, HH_DISPLAY_TOPIC, 0);
+ fe->help_running = TRUE;
+ break;
+#endif /* NO_HTMLHELP */
+ case NONE:
+ assert(!"This shouldn't happen");
+ break;
+ }
+
+ sfree(str);
+}
+
+/*
+ * Stop Help on window cleanup.
+ */
+static void stop_help(frontend *fe)
+{
+ if (fe->help_running) {
+ switch (help_type) {
+ case HLP:
+ WinHelp(fe->hwnd, help_path, HELP_QUIT, 0);
+ break;
+ case CHM:
+#ifndef NO_HTMLHELP
+ assert(htmlhelp);
+ htmlhelp(NULL, NULL, HH_CLOSE_ALL, 0);
+ break;
+#endif /* NO_HTMLHELP */
+ case NONE:
+ assert(!"This shouldn't happen");
+ break;
+ }
+ fe->help_running = FALSE;
+ }
+}
+
+#endif
+
+/*
+ * Terminate Help on process exit.
+ */
+static void cleanup_help(void)
+{
+ /* Nothing to do currently.
+ * (If we were running HTML Help single-threaded, this is where we'd
+ * call HH_UNINITIALIZE.) */
+}
+
+static int get_statusbar_height(frontend *fe)
+{
+ int sy;
+ if (fe->statusbar) {
+ RECT sr;
+ GetWindowRect(fe->statusbar, &sr);
+ sy = sr.bottom - sr.top;
+ } else {
+ sy = 0;
+ }
+ return sy;
+}
+
+static void adjust_statusbar(frontend *fe, RECT *r)
+{
+ int sy;
+
+ if (!fe->statusbar) return;
+
+ sy = get_statusbar_height(fe);
+#ifndef _WIN32_WCE
+ SetWindowPos(fe->statusbar, NULL, 0, r->bottom-r->top-sy, r->right-r->left,
+ sy, SWP_NOZORDER);
+#endif
+}
+
+static void get_menu_size(HWND wh, RECT *r)
+{
+ HMENU bar = GetMenu(wh);
+ RECT rect;
+ int i;
+
+ SetRect(r, 0, 0, 0, 0);
+ for (i = 0; i < GetMenuItemCount(bar); i++) {
+ GetMenuItemRect(wh, bar, i, &rect);
+ UnionRect(r, r, &rect);
+ }
+}
+
+/*
+ * Given a proposed new puzzle size (cx,cy), work out the actual
+ * puzzle size that would be (px,py) and the window size including
+ * furniture (wx,wy).
+ */
+
+static int check_window_resize(frontend *fe, int cx, int cy,
+ int *px, int *py,
+ int *wx, int *wy, int resize)
+{
+ RECT r;
+ int x, y, sy = get_statusbar_height(fe), changed = 0;
+
+ /* disallow making window thinner than menu bar */
+ x = max(cx, fe->xmin);
+ y = max(cy - sy, fe->ymin);
+
+ /*
+ * See if we actually got the window size we wanted, and adjust
+ * the puzzle size if not.
+ */
+ midend_size(fe->me, &x, &y, resize);
+ if (x != cx || y != cy) {
+ /*
+ * Resize the window, now we know what size we _really_
+ * want it to be.
+ */
+ r.left = r.top = 0;
+ r.right = x;
+ r.bottom = y + sy;
+ AdjustWindowRectEx(&r, WINFLAGS, TRUE, 0);
+ *wx = r.right - r.left;
+ *wy = r.bottom - r.top;
+ changed = 1;
+ }
+
+ *px = x;
+ *py = y;
+
+ return changed;
+}
+
+/*
+ * Given the current window size, make sure it's sane for the
+ * current puzzle and resize if necessary.
+ */
+
+static void check_window_size(frontend *fe, int *px, int *py)
+{
+ RECT r;
+ int wx, wy, cx, cy;
+
+ GetClientRect(fe->hwnd, &r);
+ cx = r.right - r.left;
+ cy = r.bottom - r.top;
+
+ if (check_window_resize(fe, cx, cy, px, py, &wx, &wy, FALSE)) {
+#ifdef _WIN32_WCE
+ SetWindowPos(fe->hwnd, NULL, 0, 0, wx, wy,
+ SWP_NOMOVE | SWP_NOZORDER);
+#endif
+ ;
+ }
+
+ GetClientRect(fe->hwnd, &r);
+ adjust_statusbar(fe, &r);
+}
+
+static void get_max_puzzle_size(frontend *fe, int *x, int *y)
+{
+ RECT r, sr;
+
+ if (SystemParametersInfo(SPI_GETWORKAREA, 0, &sr, FALSE)) {
+ *x = sr.right - sr.left;
+ *y = sr.bottom - sr.top;
+ r.left = 100;
+ r.right = 200;
+ r.top = 100;
+ r.bottom = 200;
+ AdjustWindowRectEx(&r, WINFLAGS, TRUE, 0);
+ *x -= r.right - r.left - 100;
+ *y -= r.bottom - r.top - 100;
+ } else {
+ *x = *y = INT_MAX;
+ }
+
+ if (fe->statusbar != NULL) {
+ GetWindowRect(fe->statusbar, &sr);
+ *y -= sr.bottom - sr.top;
+ }
+}
+
+#ifdef _WIN32_WCE
+/* Toolbar buttons on the numeric pad */
+static TBBUTTON tbNumpadButtons[] =
+{
+ {0, IDM_KEYEMUL + '1', TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, -1},
+ {1, IDM_KEYEMUL + '2', TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, -1},
+ {2, IDM_KEYEMUL + '3', TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, -1},
+ {3, IDM_KEYEMUL + '4', TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, -1},
+ {4, IDM_KEYEMUL + '5', TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, -1},
+ {5, IDM_KEYEMUL + '6', TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, -1},
+ {6, IDM_KEYEMUL + '7', TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, -1},
+ {7, IDM_KEYEMUL + '8', TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, -1},
+ {8, IDM_KEYEMUL + '9', TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, -1},
+ {9, IDM_KEYEMUL + ' ', TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, -1}
+};
+#endif
+