2 * windows.c: Windows front end for my puzzle collection.
16 #define IDM_NEW 0x0010
17 #define IDM_RESTART 0x0020
18 #define IDM_UNDO 0x0030
19 #define IDM_REDO 0x0040
20 #define IDM_QUIT 0x0050
21 #define IDM_CONFIG 0x0060
22 #define IDM_SEED 0x0070
23 #define IDM_PRESETS 0x0100
26 static FILE *debug_fp = NULL;
27 static HANDLE debug_hdl = INVALID_HANDLE_VALUE;
28 static int debug_got_console = 0;
34 if (!debug_got_console) {
36 debug_got_console = 1;
37 debug_hdl = GetStdHandle(STD_OUTPUT_HANDLE);
41 debug_fp = fopen("debug.log", "w");
44 if (debug_hdl != INVALID_HANDLE_VALUE) {
45 WriteFile(debug_hdl, buf, strlen(buf), &dw, NULL);
51 void debug_printf(char *fmt, ...)
57 vsprintf(buf, fmt, ap);
62 #define debug(x) (debug_printf x)
82 HWND hwnd, statusbar, cfgbox;
84 HBITMAP bitmap, prevbm;
91 DWORD timer_last_tickcount;
93 game_params **presets;
97 struct cfg_aux *cfgaux;
98 int cfg_which, cfg_done;
102 void fatal(char *fmt, ...)
108 vsprintf(buf, fmt, ap);
111 MessageBox(NULL, buf, "Fatal error", MB_ICONEXCLAMATION | MB_OK);
116 void status_bar(frontend *fe, char *text)
118 SetWindowText(fe->statusbar, text);
121 void frontend_default_colour(frontend *fe, float *output)
123 DWORD c = GetSysColor(COLOR_MENU); /* ick */
125 output[0] = (float)(GetRValue(c) / 255.0);
126 output[1] = (float)(GetGValue(c) / 255.0);
127 output[2] = (float)(GetBValue(c) / 255.0);
130 void clip(frontend *fe, int x, int y, int w, int h)
133 fe->clip = CreateRectRgn(0, 0, 1, 1);
134 GetClipRgn(fe->hdc_bm, fe->clip);
137 IntersectClipRect(fe->hdc_bm, x, y, x+w, y+h);
140 void unclip(frontend *fe)
143 SelectClipRgn(fe->hdc_bm, fe->clip);
146 void draw_text(frontend *fe, int x, int y, int fonttype, int fontsize,
147 int align, int colour, char *text)
152 * Find or create the font.
154 for (i = 0; i < fe->nfonts; i++)
155 if (fe->fonts[i].type == fonttype && fe->fonts[i].size == fontsize)
158 if (i == fe->nfonts) {
159 if (fe->fontsize <= fe->nfonts) {
160 fe->fontsize = fe->nfonts + 10;
161 fe->fonts = sresize(fe->fonts, fe->fontsize, struct font);
166 fe->fonts[i].type = fonttype;
167 fe->fonts[i].size = fontsize;
170 * FIXME: Really I should make at least _some_ effort to
171 * pick the correct font.
173 fe->fonts[i].font = CreateFont(-fontsize, 0, 0, 0, 0,
174 FALSE, FALSE, FALSE, DEFAULT_CHARSET,
175 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
177 (fonttype == FONT_FIXED ?
178 FIXED_PITCH | FF_DONTCARE :
179 VARIABLE_PITCH | FF_SWISS),
184 * Position and draw the text.
191 oldfont = SelectObject(fe->hdc_bm, fe->fonts[i].font);
192 if (GetTextMetrics(fe->hdc_bm, &tm)) {
193 if (align & ALIGN_VCENTRE)
194 y -= (tm.tmAscent+tm.tmDescent)/2;
198 if (GetTextExtentPoint32(fe->hdc_bm, text, strlen(text), &size)) {
199 if (align & ALIGN_HCENTRE)
201 else if (align & ALIGN_HRIGHT)
204 SetBkMode(fe->hdc_bm, TRANSPARENT);
205 TextOut(fe->hdc_bm, x, y, text, strlen(text));
206 SelectObject(fe->hdc_bm, oldfont);
210 void draw_rect(frontend *fe, int x, int y, int w, int h, int colour)
212 if (w == 1 && h == 1) {
214 * Rectangle() appears to get uppity if asked to draw a 1x1
215 * rectangle, presumably on the grounds that that's beneath
216 * its dignity and you ought to be using SetPixel instead.
219 SetPixel(fe->hdc_bm, x, y, fe->colours[colour]);
221 HBRUSH oldbrush = SelectObject(fe->hdc_bm, fe->brushes[colour]);
222 HPEN oldpen = SelectObject(fe->hdc_bm, fe->pens[colour]);
223 Rectangle(fe->hdc_bm, x, y, x+w, y+h);
224 SelectObject(fe->hdc_bm, oldbrush);
225 SelectObject(fe->hdc_bm, oldpen);
229 void draw_line(frontend *fe, int x1, int y1, int x2, int y2, int colour)
231 HPEN oldpen = SelectObject(fe->hdc_bm, fe->pens[colour]);
232 MoveToEx(fe->hdc_bm, x1, y1, NULL);
233 LineTo(fe->hdc_bm, x2, y2);
234 SetPixel(fe->hdc_bm, x2, y2, fe->colours[colour]);
235 SelectObject(fe->hdc_bm, oldpen);
238 void draw_polygon(frontend *fe, int *coords, int npoints,
239 int fill, int colour)
241 POINT *pts = snewn(npoints+1, POINT);
244 for (i = 0; i <= npoints; i++) {
245 int j = (i < npoints ? i : 0);
246 pts[i].x = coords[j*2];
247 pts[i].y = coords[j*2+1];
251 HBRUSH oldbrush = SelectObject(fe->hdc_bm, fe->brushes[colour]);
252 HPEN oldpen = SelectObject(fe->hdc_bm, fe->pens[colour]);
253 Polygon(fe->hdc_bm, pts, npoints);
254 SelectObject(fe->hdc_bm, oldbrush);
255 SelectObject(fe->hdc_bm, oldpen);
257 HPEN oldpen = SelectObject(fe->hdc_bm, fe->pens[colour]);
258 Polyline(fe->hdc_bm, pts, npoints+1);
259 SelectObject(fe->hdc_bm, oldpen);
265 void start_draw(frontend *fe)
268 hdc_win = GetDC(fe->hwnd);
269 fe->hdc_bm = CreateCompatibleDC(hdc_win);
270 fe->prevbm = SelectObject(fe->hdc_bm, fe->bitmap);
271 ReleaseDC(fe->hwnd, hdc_win);
273 SetMapMode(fe->hdc_bm, MM_TEXT);
276 void draw_update(frontend *fe, int x, int y, int w, int h)
285 InvalidateRect(fe->hwnd, &r, FALSE);
288 void end_draw(frontend *fe)
290 SelectObject(fe->hdc_bm, fe->prevbm);
291 DeleteDC(fe->hdc_bm);
293 DeleteObject(fe->clip);
298 void deactivate_timer(frontend *fe)
300 KillTimer(fe->hwnd, fe->timer);
304 void activate_timer(frontend *fe)
307 fe->timer = SetTimer(fe->hwnd, fe->timer, 20, NULL);
308 fe->timer_last_tickcount = GetTickCount();
312 static frontend *new_window(HINSTANCE inst)
323 fe->me = midend_new(fe, &t, sizeof(t));
326 midend_new_game(fe->me);
327 midend_size(fe->me, &x, &y);
335 colours = midend_colours(fe->me, &ncolours);
337 fe->colours = snewn(ncolours, COLORREF);
338 fe->brushes = snewn(ncolours, HBRUSH);
339 fe->pens = snewn(ncolours, HPEN);
341 for (i = 0; i < ncolours; i++) {
342 fe->colours[i] = RGB(255 * colours[i*3+0],
343 255 * colours[i*3+1],
344 255 * colours[i*3+2]);
345 fe->brushes[i] = CreateSolidBrush(fe->colours[i]);
346 fe->pens[i] = CreatePen(PS_SOLID, 1, fe->colours[i]);
353 AdjustWindowRectEx(&r, WS_OVERLAPPEDWINDOW &~
354 (WS_THICKFRAME | WS_MAXIMIZEBOX | WS_OVERLAPPED),
357 fe->hwnd = CreateWindowEx(0, game_name, game_name,
358 WS_OVERLAPPEDWINDOW &~
359 (WS_THICKFRAME | WS_MAXIMIZEBOX),
360 CW_USEDEFAULT, CW_USEDEFAULT,
361 r.right - r.left, r.bottom - r.top,
362 NULL, NULL, inst, NULL);
365 HMENU bar = CreateMenu();
366 HMENU menu = CreateMenu();
368 AppendMenu(bar, MF_ENABLED|MF_POPUP, (UINT)menu, "Game");
369 AppendMenu(menu, MF_ENABLED, IDM_NEW, "New");
370 AppendMenu(menu, MF_ENABLED, IDM_RESTART, "Restart");
371 AppendMenu(menu, MF_ENABLED, IDM_SEED, "Specific...");
373 if ((fe->npresets = midend_num_presets(fe->me)) > 0 ||
374 game_can_configure) {
375 HMENU sub = CreateMenu();
378 AppendMenu(bar, MF_ENABLED|MF_POPUP, (UINT)sub, "Type");
380 fe->presets = snewn(fe->npresets, game_params *);
382 for (i = 0; i < fe->npresets; i++) {
385 midend_fetch_preset(fe->me, i, &name, &fe->presets[i]);
388 * FIXME: we ought to go through and do something
389 * with ampersands here.
392 AppendMenu(sub, MF_ENABLED, IDM_PRESETS + 0x10 * i, name);
395 if (game_can_configure) {
396 AppendMenu(sub, MF_ENABLED, IDM_CONFIG, "Custom...");
400 AppendMenu(menu, MF_SEPARATOR, 0, 0);
401 AppendMenu(menu, MF_ENABLED, IDM_UNDO, "Undo");
402 AppendMenu(menu, MF_ENABLED, IDM_REDO, "Redo");
403 AppendMenu(menu, MF_SEPARATOR, 0, 0);
404 AppendMenu(menu, MF_ENABLED, IDM_QUIT, "Exit");
405 SetMenu(fe->hwnd, bar);
408 if (midend_wants_statusbar(fe->me)) {
409 fe->statusbar = CreateWindowEx(0, STATUSCLASSNAME, "ooh",
410 WS_CHILD | WS_VISIBLE,
411 0, 0, 0, 0, /* status bar does these */
412 fe->hwnd, NULL, inst, NULL);
413 GetWindowRect(fe->statusbar, &sr);
414 SetWindowPos(fe->hwnd, NULL, 0, 0,
415 r.right - r.left, r.bottom - r.top + sr.bottom - sr.top,
416 SWP_NOMOVE | SWP_NOZORDER);
417 SetWindowPos(fe->statusbar, NULL, 0, y, x, sr.bottom - sr.top,
420 fe->statusbar = NULL;
423 hdc = GetDC(fe->hwnd);
424 fe->bitmap = CreateCompatibleBitmap(hdc, x, y);
425 ReleaseDC(fe->hwnd, hdc);
427 SetWindowLong(fe->hwnd, GWL_USERDATA, (LONG)fe);
429 ShowWindow(fe->hwnd, SW_NORMAL);
430 SetForegroundWindow(fe->hwnd);
432 midend_redraw(fe->me);
437 static int CALLBACK ConfigDlgProc(HWND hwnd, UINT msg,
438 WPARAM wParam, LPARAM lParam)
440 frontend *fe = (frontend *)GetWindowLong(hwnd, GWL_USERDATA);
450 * OK and Cancel are special cases.
452 if ((HIWORD(wParam) == BN_CLICKED ||
453 HIWORD(wParam) == BN_DOUBLECLICKED) &&
454 (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)) {
455 if (LOWORD(wParam) == IDOK) {
456 char *err = midend_set_config(fe->me, fe->cfg_which, fe->cfg);
459 MessageBox(hwnd, err, "Validation error",
460 MB_ICONERROR | MB_OK);
471 * First find the control whose id this is.
473 for (i = fe->cfg, j = fe->cfgaux; i->type != C_END; i++, j++) {
474 if (j->ctlid == LOWORD(wParam))
477 if (i->type == C_END)
478 return 0; /* not our problem */
480 if (i->type == C_STRING && HIWORD(wParam) == EN_CHANGE) {
482 GetDlgItemText(fe->cfgbox, j->ctlid, buffer, lenof(buffer));
483 buffer[lenof(buffer)-1] = '\0';
485 i->sval = dupstr(buffer);
486 } else if (i->type == C_BOOLEAN &&
487 (HIWORD(wParam) == BN_CLICKED ||
488 HIWORD(wParam) == BN_DOUBLECLICKED)) {
489 i->ival = IsDlgButtonChecked(fe->cfgbox, j->ctlid);
490 } else if (i->type == C_CHOICES &&
491 HIWORD(wParam) == CBN_SELCHANGE) {
492 i->ival = SendDlgItemMessage(fe->cfgbox, j->ctlid,
506 HWND mkctrl(frontend *fe, int x1, int x2, int y1, int y2,
507 char *wclass, int wstyle,
508 int exstyle, char *wtext, int wid)
511 ret = CreateWindowEx(exstyle, wclass, wtext,
512 wstyle | WS_CHILD | WS_VISIBLE, x1, y1, x2-x1, y2-y1,
513 fe->cfgbox, (HMENU) wid, fe->inst, NULL);
514 SendMessage(ret, WM_SETFONT, (WPARAM)fe->cfgfont, MAKELPARAM(TRUE, 0));
518 static int get_config(frontend *fe, int which)
531 int winwidth, winheight, col1l, col1r, col2l, col2r, y;
532 int height, width, maxlabel, maxcheckbox;
534 wc.style = CS_DBLCLKS | CS_SAVEBITS | CS_BYTEALIGNWINDOW;
535 wc.lpfnWndProc = DefDlgProc;
537 wc.cbWndExtra = DLGWINDOWEXTRA + 8;
538 wc.hInstance = fe->inst;
540 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
541 wc.hbrBackground = (HBRUSH) (COLOR_BACKGROUND +1);
542 wc.lpszMenuName = NULL;
543 wc.lpszClassName = "GameConfigBox";
546 hdc = GetDC(fe->hwnd);
547 SetMapMode(hdc, MM_TEXT);
549 fe->cfg_done = FALSE;
551 fe->cfgfont = CreateFont(-MulDiv(8, GetDeviceCaps(hdc, LOGPIXELSY), 72),
553 FALSE, FALSE, FALSE, DEFAULT_CHARSET,
554 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
559 oldfont = SelectObject(hdc, fe->cfgfont);
560 if (GetTextMetrics(hdc, &tm)) {
561 height = tm.tmAscent + tm.tmDescent;
562 width = tm.tmAveCharWidth;
567 fe->cfg = midend_get_config(fe->me, which, &title);
568 fe->cfg_which = which;
571 * Figure out the layout of the config box by measuring the
572 * length of each piece of text.
574 maxlabel = maxcheckbox = 0;
575 winheight = height/2;
577 for (i = fe->cfg; i->type != C_END; i++) {
582 * Both these control types have a label filling only
583 * the left-hand column of the box.
585 if (GetTextExtentPoint32(hdc, i->name, strlen(i->name), &size) &&
588 winheight += height * 3 / 2 + (height / 2);
593 * Checkboxes take up the whole of the box width.
595 if (GetTextExtentPoint32(hdc, i->name, strlen(i->name), &size) &&
596 maxcheckbox < size.cx)
597 maxcheckbox = size.cx;
598 winheight += height + (height / 2);
603 winheight += height + height * 7 / 4; /* OK / Cancel buttons */
606 col1r = col1l + maxlabel;
607 col2l = col1r + 2*width;
608 col2r = col2l + 30*width;
609 if (col2r < col1l+2*height+maxcheckbox)
610 col2r = col1l+2*height+maxcheckbox;
611 winwidth = col2r + 2*width;
613 ReleaseDC(fe->hwnd, hdc);
616 * Create the dialog, now that we know its size.
623 r.bottom = winheight;
625 AdjustWindowRectEx(&r, (WS_OVERLAPPEDWINDOW /*|
626 DS_MODALFRAME | WS_POPUP | WS_VISIBLE |
627 WS_CAPTION | WS_SYSMENU*/) &~
628 (WS_MAXIMIZEBOX | WS_OVERLAPPED),
632 * Centre the dialog on its parent window.
636 GetWindowRect(fe->hwnd, &r2);
637 r.left = (r2.left + r2.right - r.right) / 2;
638 r.top = (r2.top + r2.bottom - r.bottom) / 2;
642 fe->cfgbox = CreateWindowEx(0, wc.lpszClassName, title,
643 DS_MODALFRAME | WS_POPUP | WS_VISIBLE |
644 WS_CAPTION | WS_SYSMENU,
646 r.right-r.left, r.bottom-r.top,
647 fe->hwnd, NULL, fe->inst, NULL);
651 SendMessage(fe->cfgbox, WM_SETFONT, (WPARAM)fe->cfgfont, FALSE);
653 SetWindowLong(fe->cfgbox, GWL_USERDATA, (LONG)fe);
654 SetWindowLong(fe->cfgbox, DWL_DLGPROC, (LONG)ConfigDlgProc);
657 * Count the controls so we can allocate cfgaux.
659 for (nctrls = 0, i = fe->cfg; i->type != C_END; i++)
661 fe->cfgaux = snewn(nctrls, struct cfg_aux);
665 for (i = fe->cfg, j = fe->cfgaux; i->type != C_END; i++, j++) {
669 * Edit box with a label beside it.
671 mkctrl(fe, col1l, col1r, y+height*1/8, y+height*9/8,
672 "Static", 0, 0, i->name, id++);
673 ctl = mkctrl(fe, col2l, col2r, y, y+height*3/2,
674 "EDIT", WS_TABSTOP | ES_AUTOHSCROLL,
675 WS_EX_CLIENTEDGE, "", (j->ctlid = id++));
676 SetWindowText(ctl, i->sval);
684 mkctrl(fe, col1l, col2r, y, y+height, "BUTTON",
685 BS_NOTIFY | BS_AUTOCHECKBOX | WS_TABSTOP,
686 0, i->name, (j->ctlid = id++));
692 * Drop-down list with a label beside it.
694 mkctrl(fe, col1l, col1r, y+height*1/8, y+height*9/8,
695 "STATIC", 0, 0, i->name, id++);
696 ctl = mkctrl(fe, col2l, col2r, y, y+height*41/2,
697 "COMBOBOX", WS_TABSTOP |
698 CBS_DROPDOWNLIST | CBS_HASSTRINGS,
699 WS_EX_CLIENTEDGE, "", (j->ctlid = id++));
701 char c, *p, *q, *str;
703 SendMessage(ctl, CB_RESETCONTENT, 0, 0);
708 while (*q && *q != c) q++;
709 str = snewn(q-p+1, char);
710 strncpy(str, p, q-p);
712 SendMessage(ctl, CB_ADDSTRING, 0, (LPARAM)str);
719 SendMessage(ctl, CB_SETCURSEL, i->ival, 0);
725 assert(y < winheight);
729 y += height/2; /* extra space before OK and Cancel */
730 mkctrl(fe, col1l, (col1l+col2r)/2-width, y, y+height*7/4, "BUTTON",
731 BS_PUSHBUTTON | BS_NOTIFY | WS_TABSTOP | BS_DEFPUSHBUTTON, 0,
733 mkctrl(fe, (col1l+col2r)/2+width, col2r, y, y+height*7/4, "BUTTON",
734 BS_PUSHBUTTON | BS_NOTIFY | WS_TABSTOP, 0, "Cancel", IDCANCEL);
736 SendMessage(fe->cfgbox, WM_INITDIALOG, 0, 0);
738 EnableWindow(fe->hwnd, FALSE);
739 ShowWindow(fe->cfgbox, SW_NORMAL);
740 while ((gm=GetMessage(&msg, NULL, 0, 0)) > 0) {
741 if (!IsDialogMessage(fe->cfgbox, &msg))
742 DispatchMessage(&msg);
746 EnableWindow(fe->hwnd, TRUE);
747 SetForegroundWindow(fe->hwnd);
748 DestroyWindow(fe->cfgbox);
749 DeleteObject(fe->cfgfont);
754 return (fe->cfg_done == 2);
757 static void new_game_type(frontend *fe)
763 midend_new_game(fe->me);
764 midend_size(fe->me, &x, &y);
769 AdjustWindowRectEx(&r, WS_OVERLAPPEDWINDOW &~
770 (WS_THICKFRAME | WS_MAXIMIZEBOX |
774 if (fe->statusbar != NULL) {
775 GetWindowRect(fe->statusbar, &sr);
777 sr.left = sr.right = sr.top = sr.bottom = 0;
779 SetWindowPos(fe->hwnd, NULL, 0, 0,
781 r.bottom - r.top + sr.bottom - sr.top,
782 SWP_NOMOVE | SWP_NOZORDER);
783 if (fe->statusbar != NULL)
784 SetWindowPos(fe->statusbar, NULL, 0, y, x,
785 sr.bottom - sr.top, SWP_NOZORDER);
787 DeleteObject(fe->bitmap);
789 hdc = GetDC(fe->hwnd);
790 fe->bitmap = CreateCompatibleBitmap(hdc, x, y);
791 ReleaseDC(fe->hwnd, hdc);
793 midend_redraw(fe->me);
796 static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
797 WPARAM wParam, LPARAM lParam)
799 frontend *fe = (frontend *)GetWindowLong(hwnd, GWL_USERDATA);
806 switch (wParam & ~0xF) { /* low 4 bits reserved to Windows */
808 if (!midend_process_key(fe->me, 0, 0, 'n'))
812 if (!midend_process_key(fe->me, 0, 0, 'r'))
816 if (!midend_process_key(fe->me, 0, 0, 'u'))
820 if (!midend_process_key(fe->me, 0, 0, '\x12'))
824 if (!midend_process_key(fe->me, 0, 0, 'q'))
828 if (get_config(fe, CFG_SETTINGS))
832 if (get_config(fe, CFG_SEED))
837 int p = ((wParam &~ 0xF) - IDM_PRESETS) / 0x10;
839 if (p >= 0 && p < fe->npresets) {
840 midend_set_params(fe->me, fe->presets[p]);
856 hdc = BeginPaint(hwnd, &p);
857 hdc2 = CreateCompatibleDC(hdc);
858 prevbm = SelectObject(hdc2, fe->bitmap);
860 p.rcPaint.left, p.rcPaint.top,
861 p.rcPaint.right - p.rcPaint.left,
862 p.rcPaint.bottom - p.rcPaint.top,
864 p.rcPaint.left, p.rcPaint.top,
866 SelectObject(hdc2, prevbm);
876 case VK_LEFT: key = CURSOR_LEFT; break;
877 case VK_RIGHT: key = CURSOR_RIGHT; break;
878 case VK_UP: key = CURSOR_UP; break;
879 case VK_DOWN: key = CURSOR_DOWN; break;
881 * Diagonal keys on the numeric keypad.
884 if (!(lParam & 0x01000000)) key = CURSOR_UP_RIGHT;
887 if (!(lParam & 0x01000000)) key = CURSOR_DOWN_RIGHT;
890 if (!(lParam & 0x01000000)) key = CURSOR_UP_LEFT;
893 if (!(lParam & 0x01000000)) key = CURSOR_DOWN_LEFT;
896 * Numeric keypad keys with Num Lock on.
898 case VK_NUMPAD4: key = CURSOR_LEFT; break;
899 case VK_NUMPAD6: key = CURSOR_RIGHT; break;
900 case VK_NUMPAD8: key = CURSOR_UP; break;
901 case VK_NUMPAD2: key = CURSOR_DOWN; break;
902 case VK_NUMPAD9: key = CURSOR_UP_RIGHT; break;
903 case VK_NUMPAD3: key = CURSOR_DOWN_RIGHT; break;
904 case VK_NUMPAD7: key = CURSOR_UP_LEFT; break;
905 case VK_NUMPAD1: key = CURSOR_DOWN_LEFT; break;
909 if (!midend_process_key(fe->me, 0, 0, key))
914 m.message = WM_KEYDOWN;
916 m.lParam = lParam & 0xdfff;
917 TranslateMessage(&m);
928 * Shift-clicks count as middle-clicks, since otherwise
929 * two-button Windows users won't have any kind of
930 * middle click to use.
932 if (message == WM_MBUTTONDOWN || (wParam & MK_SHIFT))
933 button = MIDDLE_BUTTON;
934 else if (message == WM_LBUTTONDOWN)
935 button = LEFT_BUTTON;
937 button = RIGHT_BUTTON;
939 if (!midend_process_key(fe->me, LOWORD(lParam),
940 HIWORD(lParam), button))
945 if (!midend_process_key(fe->me, 0, 0, (unsigned char)wParam))
950 DWORD now = GetTickCount();
951 float elapsed = (float) (now - fe->timer_last_tickcount) * 0.001F;
952 midend_timer(fe->me, elapsed);
953 fe->timer_last_tickcount = now;
958 return DefWindowProc(hwnd, message, wParam, lParam);
961 int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
965 InitCommonControls();
971 wndclass.lpfnWndProc = WndProc;
972 wndclass.cbClsExtra = 0;
973 wndclass.cbWndExtra = 0;
974 wndclass.hInstance = inst;
975 wndclass.hIcon = LoadIcon(inst, IDI_APPLICATION);
976 wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
977 wndclass.hbrBackground = NULL;
978 wndclass.lpszMenuName = NULL;
979 wndclass.lpszClassName = game_name;
981 RegisterClass(&wndclass);
986 while (GetMessage(&msg, NULL, 0, 0)) {
987 DispatchMessage(&msg);