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;
92 game_params **presets;
96 struct cfg_aux *cfgaux;
97 int cfg_which, cfg_done;
101 void fatal(char *fmt, ...)
107 vsprintf(buf, fmt, ap);
110 MessageBox(NULL, buf, "Fatal error", MB_ICONEXCLAMATION | MB_OK);
115 void status_bar(frontend *fe, char *text)
117 SetWindowText(fe->statusbar, text);
120 void frontend_default_colour(frontend *fe, float *output)
122 DWORD c = GetSysColor(COLOR_MENU); /* ick */
124 output[0] = (float)(GetRValue(c) / 255.0);
125 output[1] = (float)(GetGValue(c) / 255.0);
126 output[2] = (float)(GetBValue(c) / 255.0);
129 void clip(frontend *fe, int x, int y, int w, int h)
132 fe->clip = CreateRectRgn(0, 0, 1, 1);
133 GetClipRgn(fe->hdc_bm, fe->clip);
136 IntersectClipRect(fe->hdc_bm, x, y, x+w, y+h);
139 void unclip(frontend *fe)
142 SelectClipRgn(fe->hdc_bm, fe->clip);
145 void draw_text(frontend *fe, int x, int y, int fonttype, int fontsize,
146 int align, int colour, char *text)
151 * Find or create the font.
153 for (i = 0; i < fe->nfonts; i++)
154 if (fe->fonts[i].type == fonttype && fe->fonts[i].size == fontsize)
157 if (i == fe->nfonts) {
158 if (fe->fontsize <= fe->nfonts) {
159 fe->fontsize = fe->nfonts + 10;
160 fe->fonts = sresize(fe->fonts, fe->fontsize, struct font);
165 fe->fonts[i].type = fonttype;
166 fe->fonts[i].size = fontsize;
169 * FIXME: Really I should make at least _some_ effort to
170 * pick the correct font.
172 fe->fonts[i].font = CreateFont(-fontsize, 0, 0, 0, 0,
173 FALSE, FALSE, FALSE, DEFAULT_CHARSET,
174 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
176 (fonttype == FONT_FIXED ?
177 FIXED_PITCH | FF_DONTCARE :
178 VARIABLE_PITCH | FF_SWISS),
183 * Position and draw the text.
190 oldfont = SelectObject(fe->hdc_bm, fe->fonts[i].font);
191 if (GetTextMetrics(fe->hdc_bm, &tm)) {
192 if (align & ALIGN_VCENTRE)
193 y -= (tm.tmAscent+tm.tmDescent)/2;
197 if (GetTextExtentPoint32(fe->hdc_bm, text, strlen(text), &size)) {
198 if (align & ALIGN_HCENTRE)
200 else if (align & ALIGN_HRIGHT)
203 SetBkMode(fe->hdc_bm, TRANSPARENT);
204 TextOut(fe->hdc_bm, x, y, text, strlen(text));
205 SelectObject(fe->hdc_bm, oldfont);
209 void draw_rect(frontend *fe, int x, int y, int w, int h, int colour)
211 if (w == 1 && h == 1) {
213 * Rectangle() appears to get uppity if asked to draw a 1x1
214 * rectangle, presumably on the grounds that that's beneath
215 * its dignity and you ought to be using SetPixel instead.
218 SetPixel(fe->hdc_bm, x, y, fe->colours[colour]);
220 HBRUSH oldbrush = SelectObject(fe->hdc_bm, fe->brushes[colour]);
221 HPEN oldpen = SelectObject(fe->hdc_bm, fe->pens[colour]);
222 Rectangle(fe->hdc_bm, x, y, x+w, y+h);
223 SelectObject(fe->hdc_bm, oldbrush);
224 SelectObject(fe->hdc_bm, oldpen);
228 void draw_line(frontend *fe, int x1, int y1, int x2, int y2, int colour)
230 HPEN oldpen = SelectObject(fe->hdc_bm, fe->pens[colour]);
231 MoveToEx(fe->hdc_bm, x1, y1, NULL);
232 LineTo(fe->hdc_bm, x2, y2);
233 SetPixel(fe->hdc_bm, x2, y2, fe->colours[colour]);
234 SelectObject(fe->hdc_bm, oldpen);
237 void draw_polygon(frontend *fe, int *coords, int npoints,
238 int fill, int colour)
240 POINT *pts = snewn(npoints+1, POINT);
243 for (i = 0; i <= npoints; i++) {
244 int j = (i < npoints ? i : 0);
245 pts[i].x = coords[j*2];
246 pts[i].y = coords[j*2+1];
250 HBRUSH oldbrush = SelectObject(fe->hdc_bm, fe->brushes[colour]);
251 HPEN oldpen = SelectObject(fe->hdc_bm, fe->pens[colour]);
252 Polygon(fe->hdc_bm, pts, npoints);
253 SelectObject(fe->hdc_bm, oldbrush);
254 SelectObject(fe->hdc_bm, oldpen);
256 HPEN oldpen = SelectObject(fe->hdc_bm, fe->pens[colour]);
257 Polyline(fe->hdc_bm, pts, npoints+1);
258 SelectObject(fe->hdc_bm, oldpen);
264 void start_draw(frontend *fe)
267 hdc_win = GetDC(fe->hwnd);
268 fe->hdc_bm = CreateCompatibleDC(hdc_win);
269 fe->prevbm = SelectObject(fe->hdc_bm, fe->bitmap);
270 ReleaseDC(fe->hwnd, hdc_win);
272 SetMapMode(fe->hdc_bm, MM_TEXT);
275 void draw_update(frontend *fe, int x, int y, int w, int h)
284 InvalidateRect(fe->hwnd, &r, FALSE);
287 void end_draw(frontend *fe)
289 SelectObject(fe->hdc_bm, fe->prevbm);
290 DeleteDC(fe->hdc_bm);
292 DeleteObject(fe->clip);
297 void deactivate_timer(frontend *fe)
299 KillTimer(fe->hwnd, fe->timer);
303 void activate_timer(frontend *fe)
305 fe->timer = SetTimer(fe->hwnd, fe->timer, 20, NULL);
308 static frontend *new_window(HINSTANCE inst)
316 fe->me = midend_new(fe);
318 midend_new_game(fe->me);
319 midend_size(fe->me, &x, &y);
327 colours = midend_colours(fe->me, &ncolours);
329 fe->colours = snewn(ncolours, COLORREF);
330 fe->brushes = snewn(ncolours, HBRUSH);
331 fe->pens = snewn(ncolours, HPEN);
333 for (i = 0; i < ncolours; i++) {
334 fe->colours[i] = RGB(255 * colours[i*3+0],
335 255 * colours[i*3+1],
336 255 * colours[i*3+2]);
337 fe->brushes[i] = CreateSolidBrush(fe->colours[i]);
338 fe->pens[i] = CreatePen(PS_SOLID, 1, fe->colours[i]);
345 AdjustWindowRectEx(&r, WS_OVERLAPPEDWINDOW &~
346 (WS_THICKFRAME | WS_MAXIMIZEBOX | WS_OVERLAPPED),
349 fe->hwnd = CreateWindowEx(0, game_name, game_name,
350 WS_OVERLAPPEDWINDOW &~
351 (WS_THICKFRAME | WS_MAXIMIZEBOX),
352 CW_USEDEFAULT, CW_USEDEFAULT,
353 r.right - r.left, r.bottom - r.top,
354 NULL, NULL, inst, NULL);
357 HMENU bar = CreateMenu();
358 HMENU menu = CreateMenu();
360 AppendMenu(bar, MF_ENABLED|MF_POPUP, (UINT)menu, "Game");
361 AppendMenu(menu, MF_ENABLED, IDM_NEW, "New");
362 AppendMenu(menu, MF_ENABLED, IDM_RESTART, "Restart");
363 AppendMenu(menu, MF_ENABLED, IDM_SEED, "Specific...");
365 if ((fe->npresets = midend_num_presets(fe->me)) > 0 ||
366 game_can_configure) {
367 HMENU sub = CreateMenu();
370 AppendMenu(bar, MF_ENABLED|MF_POPUP, (UINT)sub, "Type");
372 fe->presets = snewn(fe->npresets, game_params *);
374 for (i = 0; i < fe->npresets; i++) {
377 midend_fetch_preset(fe->me, i, &name, &fe->presets[i]);
380 * FIXME: we ought to go through and do something
381 * with ampersands here.
384 AppendMenu(sub, MF_ENABLED, IDM_PRESETS + 0x10 * i, name);
387 if (game_can_configure) {
388 AppendMenu(sub, MF_ENABLED, IDM_CONFIG, "Custom...");
392 AppendMenu(menu, MF_SEPARATOR, 0, 0);
393 AppendMenu(menu, MF_ENABLED, IDM_UNDO, "Undo");
394 AppendMenu(menu, MF_ENABLED, IDM_REDO, "Redo");
395 AppendMenu(menu, MF_SEPARATOR, 0, 0);
396 AppendMenu(menu, MF_ENABLED, IDM_QUIT, "Exit");
397 SetMenu(fe->hwnd, bar);
400 if (midend_wants_statusbar(fe->me)) {
401 fe->statusbar = CreateWindowEx(0, STATUSCLASSNAME, "ooh",
402 WS_CHILD | WS_VISIBLE,
403 0, 0, 0, 0, /* status bar does these */
404 fe->hwnd, NULL, inst, NULL);
405 GetWindowRect(fe->statusbar, &sr);
406 SetWindowPos(fe->hwnd, NULL, 0, 0,
407 r.right - r.left, r.bottom - r.top + sr.bottom - sr.top,
408 SWP_NOMOVE | SWP_NOZORDER);
409 SetWindowPos(fe->statusbar, NULL, 0, y, x, sr.bottom - sr.top,
412 fe->statusbar = NULL;
415 hdc = GetDC(fe->hwnd);
416 fe->bitmap = CreateCompatibleBitmap(hdc, x, y);
417 ReleaseDC(fe->hwnd, hdc);
419 SetWindowLong(fe->hwnd, GWL_USERDATA, (LONG)fe);
421 ShowWindow(fe->hwnd, SW_NORMAL);
422 SetForegroundWindow(fe->hwnd);
424 midend_redraw(fe->me);
429 static int CALLBACK ConfigDlgProc(HWND hwnd, UINT msg,
430 WPARAM wParam, LPARAM lParam)
432 frontend *fe = (frontend *)GetWindowLong(hwnd, GWL_USERDATA);
442 * OK and Cancel are special cases.
444 if ((HIWORD(wParam) == BN_CLICKED ||
445 HIWORD(wParam) == BN_DOUBLECLICKED) &&
446 (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)) {
447 if (LOWORD(wParam) == IDOK) {
448 char *err = midend_set_config(fe->me, fe->cfg_which, fe->cfg);
451 MessageBox(hwnd, err, "Validation error",
452 MB_ICONERROR | MB_OK);
463 * First find the control whose id this is.
465 for (i = fe->cfg, j = fe->cfgaux; i->type != C_END; i++, j++) {
466 if (j->ctlid == LOWORD(wParam))
469 if (i->type == C_END)
470 return 0; /* not our problem */
472 if (i->type == C_STRING && HIWORD(wParam) == EN_CHANGE) {
474 GetDlgItemText(fe->cfgbox, j->ctlid, buffer, lenof(buffer));
475 buffer[lenof(buffer)-1] = '\0';
477 i->sval = dupstr(buffer);
478 } else if (i->type == C_BOOLEAN &&
479 (HIWORD(wParam) == BN_CLICKED ||
480 HIWORD(wParam) == BN_DOUBLECLICKED)) {
481 i->ival = IsDlgButtonChecked(fe->cfgbox, j->ctlid);
482 } else if (i->type == C_CHOICES &&
483 HIWORD(wParam) == CBN_SELCHANGE) {
484 i->ival = SendDlgItemMessage(fe->cfgbox, j->ctlid,
498 HWND mkctrl(frontend *fe, int x1, int x2, int y1, int y2,
499 char *wclass, int wstyle,
500 int exstyle, char *wtext, int wid)
503 ret = CreateWindowEx(exstyle, wclass, wtext,
504 wstyle | WS_CHILD | WS_VISIBLE, x1, y1, x2-x1, y2-y1,
505 fe->cfgbox, (HMENU) wid, fe->inst, NULL);
506 SendMessage(ret, WM_SETFONT, (WPARAM)fe->cfgfont, MAKELPARAM(TRUE, 0));
510 static int get_config(frontend *fe, int which)
523 int winwidth, winheight, col1l, col1r, col2l, col2r, y;
524 int height, width, maxlabel, maxcheckbox;
526 wc.style = CS_DBLCLKS | CS_SAVEBITS | CS_BYTEALIGNWINDOW;
527 wc.lpfnWndProc = DefDlgProc;
529 wc.cbWndExtra = DLGWINDOWEXTRA + 8;
530 wc.hInstance = fe->inst;
532 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
533 wc.hbrBackground = (HBRUSH) (COLOR_BACKGROUND +1);
534 wc.lpszMenuName = NULL;
535 wc.lpszClassName = "GameConfigBox";
538 hdc = GetDC(fe->hwnd);
539 SetMapMode(hdc, MM_TEXT);
541 fe->cfg_done = FALSE;
543 fe->cfgfont = CreateFont(-MulDiv(8, GetDeviceCaps(hdc, LOGPIXELSY), 72),
545 FALSE, FALSE, FALSE, DEFAULT_CHARSET,
546 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
551 oldfont = SelectObject(hdc, fe->cfgfont);
552 if (GetTextMetrics(hdc, &tm)) {
553 height = tm.tmAscent + tm.tmDescent;
554 width = tm.tmAveCharWidth;
559 fe->cfg = midend_get_config(fe->me, which, &title);
560 fe->cfg_which = which;
563 * Figure out the layout of the config box by measuring the
564 * length of each piece of text.
566 maxlabel = maxcheckbox = 0;
567 winheight = height/2;
569 for (i = fe->cfg; i->type != C_END; i++) {
574 * Both these control types have a label filling only
575 * the left-hand column of the box.
577 if (GetTextExtentPoint32(hdc, i->name, strlen(i->name), &size) &&
580 winheight += height * 3 / 2 + (height / 2);
585 * Checkboxes take up the whole of the box width.
587 if (GetTextExtentPoint32(hdc, i->name, strlen(i->name), &size) &&
588 maxcheckbox < size.cx)
589 maxcheckbox = size.cx;
590 winheight += height + (height / 2);
595 winheight += height + height * 7 / 4; /* OK / Cancel buttons */
598 col1r = col1l + maxlabel;
599 col2l = col1r + 2*width;
600 col2r = col2l + 30*width;
601 if (col2r < col1l+2*height+maxcheckbox)
602 col2r = col1l+2*height+maxcheckbox;
603 winwidth = col2r + 2*width;
605 ReleaseDC(fe->hwnd, hdc);
608 * Create the dialog, now that we know its size.
615 r.bottom = winheight;
617 AdjustWindowRectEx(&r, (WS_OVERLAPPEDWINDOW /*|
618 DS_MODALFRAME | WS_POPUP | WS_VISIBLE |
619 WS_CAPTION | WS_SYSMENU*/) &~
620 (WS_MAXIMIZEBOX | WS_OVERLAPPED),
624 * Centre the dialog on its parent window.
628 GetWindowRect(fe->hwnd, &r2);
629 r.left = (r2.left + r2.right - r.right) / 2;
630 r.top = (r2.top + r2.bottom - r.bottom) / 2;
634 fe->cfgbox = CreateWindowEx(0, wc.lpszClassName, title,
635 DS_MODALFRAME | WS_POPUP | WS_VISIBLE |
636 WS_CAPTION | WS_SYSMENU,
638 r.right-r.left, r.bottom-r.top,
639 fe->hwnd, NULL, fe->inst, NULL);
643 SendMessage(fe->cfgbox, WM_SETFONT, (WPARAM)fe->cfgfont, FALSE);
645 SetWindowLong(fe->cfgbox, GWL_USERDATA, (LONG)fe);
646 SetWindowLong(fe->cfgbox, DWL_DLGPROC, (LONG)ConfigDlgProc);
649 * Count the controls so we can allocate cfgaux.
651 for (nctrls = 0, i = fe->cfg; i->type != C_END; i++)
653 fe->cfgaux = snewn(nctrls, struct cfg_aux);
657 for (i = fe->cfg, j = fe->cfgaux; i->type != C_END; i++, j++) {
661 * Edit box with a label beside it.
663 mkctrl(fe, col1l, col1r, y+height*1/8, y+height*9/8,
664 "Static", 0, 0, i->name, id++);
665 ctl = mkctrl(fe, col2l, col2r, y, y+height*3/2,
666 "EDIT", WS_TABSTOP | ES_AUTOHSCROLL,
667 WS_EX_CLIENTEDGE, "", (j->ctlid = id++));
668 SetWindowText(ctl, i->sval);
676 mkctrl(fe, col1l, col2r, y, y+height, "BUTTON",
677 BS_NOTIFY | BS_AUTOCHECKBOX | WS_TABSTOP,
678 0, i->name, (j->ctlid = id++));
684 * Drop-down list with a label beside it.
686 mkctrl(fe, col1l, col1r, y+height*1/8, y+height*9/8,
687 "STATIC", 0, 0, i->name, id++);
688 ctl = mkctrl(fe, col2l, col2r, y, y+height*41/2,
689 "COMBOBOX", WS_TABSTOP |
690 CBS_DROPDOWNLIST | CBS_HASSTRINGS,
691 WS_EX_CLIENTEDGE, "", (j->ctlid = id++));
693 char c, *p, *q, *str;
695 SendMessage(ctl, CB_RESETCONTENT, 0, 0);
700 while (*q && *q != c) q++;
701 str = snewn(q-p+1, char);
702 strncpy(str, p, q-p);
704 SendMessage(ctl, CB_ADDSTRING, 0, (LPARAM)str);
711 SendMessage(ctl, CB_SETCURSEL, i->ival, 0);
717 assert(y < winheight);
721 y += height/2; /* extra space before OK and Cancel */
722 mkctrl(fe, col1l, (col1l+col2r)/2-width, y, y+height*7/4, "BUTTON",
723 BS_PUSHBUTTON | BS_NOTIFY | WS_TABSTOP | BS_DEFPUSHBUTTON, 0,
725 mkctrl(fe, (col1l+col2r)/2+width, col2r, y, y+height*7/4, "BUTTON",
726 BS_PUSHBUTTON | BS_NOTIFY | WS_TABSTOP, 0, "Cancel", IDCANCEL);
728 SendMessage(fe->cfgbox, WM_INITDIALOG, 0, 0);
730 EnableWindow(fe->hwnd, FALSE);
731 ShowWindow(fe->cfgbox, SW_NORMAL);
732 while ((gm=GetMessage(&msg, NULL, 0, 0)) > 0) {
733 if (!IsDialogMessage(fe->cfgbox, &msg))
734 DispatchMessage(&msg);
738 EnableWindow(fe->hwnd, TRUE);
739 SetForegroundWindow(fe->hwnd);
740 DestroyWindow(fe->cfgbox);
741 DeleteObject(fe->cfgfont);
746 return (fe->cfg_done == 2);
749 static void new_game_type(frontend *fe)
755 midend_new_game(fe->me);
756 midend_size(fe->me, &x, &y);
761 AdjustWindowRectEx(&r, WS_OVERLAPPEDWINDOW &~
762 (WS_THICKFRAME | WS_MAXIMIZEBOX |
766 if (fe->statusbar != NULL) {
767 GetWindowRect(fe->statusbar, &sr);
769 sr.left = sr.right = sr.top = sr.bottom = 0;
771 SetWindowPos(fe->hwnd, NULL, 0, 0,
773 r.bottom - r.top + sr.bottom - sr.top,
774 SWP_NOMOVE | SWP_NOZORDER);
775 if (fe->statusbar != NULL)
776 SetWindowPos(fe->statusbar, NULL, 0, y, x,
777 sr.bottom - sr.top, SWP_NOZORDER);
779 DeleteObject(fe->bitmap);
781 hdc = GetDC(fe->hwnd);
782 fe->bitmap = CreateCompatibleBitmap(hdc, x, y);
783 ReleaseDC(fe->hwnd, hdc);
785 midend_redraw(fe->me);
788 static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
789 WPARAM wParam, LPARAM lParam)
791 frontend *fe = (frontend *)GetWindowLong(hwnd, GWL_USERDATA);
798 switch (wParam & ~0xF) { /* low 4 bits reserved to Windows */
800 if (!midend_process_key(fe->me, 0, 0, 'n'))
804 if (!midend_process_key(fe->me, 0, 0, 'r'))
808 if (!midend_process_key(fe->me, 0, 0, 'u'))
812 if (!midend_process_key(fe->me, 0, 0, '\x12'))
816 if (!midend_process_key(fe->me, 0, 0, 'q'))
820 if (get_config(fe, CFG_SETTINGS))
824 if (get_config(fe, CFG_SEED))
829 int p = ((wParam &~ 0xF) - IDM_PRESETS) / 0x10;
831 if (p >= 0 && p < fe->npresets) {
832 midend_set_params(fe->me, fe->presets[p]);
848 hdc = BeginPaint(hwnd, &p);
849 hdc2 = CreateCompatibleDC(hdc);
850 prevbm = SelectObject(hdc2, fe->bitmap);
852 p.rcPaint.left, p.rcPaint.top,
853 p.rcPaint.right - p.rcPaint.left,
854 p.rcPaint.bottom - p.rcPaint.top,
856 p.rcPaint.left, p.rcPaint.top,
858 SelectObject(hdc2, prevbm);
868 case VK_LEFT: key = CURSOR_LEFT; break;
869 case VK_RIGHT: key = CURSOR_RIGHT; break;
870 case VK_UP: key = CURSOR_UP; break;
871 case VK_DOWN: key = CURSOR_DOWN; break;
873 * Diagonal keys on the numeric keypad.
876 if (!(lParam & 0x01000000)) key = CURSOR_UP_RIGHT;
879 if (!(lParam & 0x01000000)) key = CURSOR_DOWN_RIGHT;
882 if (!(lParam & 0x01000000)) key = CURSOR_UP_LEFT;
885 if (!(lParam & 0x01000000)) key = CURSOR_DOWN_LEFT;
888 * Numeric keypad keys with Num Lock on.
890 case VK_NUMPAD4: key = CURSOR_LEFT; break;
891 case VK_NUMPAD6: key = CURSOR_RIGHT; break;
892 case VK_NUMPAD8: key = CURSOR_UP; break;
893 case VK_NUMPAD2: key = CURSOR_DOWN; break;
894 case VK_NUMPAD9: key = CURSOR_UP_RIGHT; break;
895 case VK_NUMPAD3: key = CURSOR_DOWN_RIGHT; break;
896 case VK_NUMPAD7: key = CURSOR_UP_LEFT; break;
897 case VK_NUMPAD1: key = CURSOR_DOWN_LEFT; break;
901 if (!midend_process_key(fe->me, 0, 0, key))
906 m.message = WM_KEYDOWN;
908 m.lParam = lParam & 0xdfff;
909 TranslateMessage(&m);
920 * Shift-clicks count as middle-clicks, since otherwise
921 * two-button Windows users won't have any kind of
922 * middle click to use.
924 if (message == WM_MBUTTONDOWN || (wParam & MK_SHIFT))
925 button = MIDDLE_BUTTON;
926 else if (message == WM_LBUTTONDOWN)
927 button = LEFT_BUTTON;
929 button = RIGHT_BUTTON;
931 if (!midend_process_key(fe->me, LOWORD(lParam),
932 HIWORD(lParam), button))
937 if (!midend_process_key(fe->me, 0, 0, (unsigned char)wParam))
942 midend_timer(fe->me, (float)0.02);
946 return DefWindowProc(hwnd, message, wParam, lParam);
949 int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
955 InitCommonControls();
961 wndclass.lpfnWndProc = WndProc;
962 wndclass.cbClsExtra = 0;
963 wndclass.cbWndExtra = 0;
964 wndclass.hInstance = inst;
965 wndclass.hIcon = LoadIcon(inst, IDI_APPLICATION);
966 wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
967 wndclass.hbrBackground = NULL;
968 wndclass.lpszMenuName = NULL;
969 wndclass.lpszClassName = game_name;
971 RegisterClass(&wndclass);
976 while (GetMessage(&msg, NULL, 0, 0)) {
977 DispatchMessage(&msg);