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);
332 fe->nfonts = fe->fontsize = 0;
338 colours = midend_colours(fe->me, &ncolours);
340 fe->colours = snewn(ncolours, COLORREF);
341 fe->brushes = snewn(ncolours, HBRUSH);
342 fe->pens = snewn(ncolours, HPEN);
344 for (i = 0; i < ncolours; i++) {
345 fe->colours[i] = RGB(255 * colours[i*3+0],
346 255 * colours[i*3+1],
347 255 * colours[i*3+2]);
348 fe->brushes[i] = CreateSolidBrush(fe->colours[i]);
349 fe->pens[i] = CreatePen(PS_SOLID, 1, fe->colours[i]);
356 AdjustWindowRectEx(&r, WS_OVERLAPPEDWINDOW &~
357 (WS_THICKFRAME | WS_MAXIMIZEBOX | WS_OVERLAPPED),
360 fe->hwnd = CreateWindowEx(0, game_name, game_name,
361 WS_OVERLAPPEDWINDOW &~
362 (WS_THICKFRAME | WS_MAXIMIZEBOX),
363 CW_USEDEFAULT, CW_USEDEFAULT,
364 r.right - r.left, r.bottom - r.top,
365 NULL, NULL, inst, NULL);
368 HMENU bar = CreateMenu();
369 HMENU menu = CreateMenu();
371 AppendMenu(bar, MF_ENABLED|MF_POPUP, (UINT)menu, "Game");
372 AppendMenu(menu, MF_ENABLED, IDM_NEW, "New");
373 AppendMenu(menu, MF_ENABLED, IDM_RESTART, "Restart");
374 AppendMenu(menu, MF_ENABLED, IDM_SEED, "Specific...");
376 if ((fe->npresets = midend_num_presets(fe->me)) > 0 ||
377 game_can_configure) {
378 HMENU sub = CreateMenu();
381 AppendMenu(bar, MF_ENABLED|MF_POPUP, (UINT)sub, "Type");
383 fe->presets = snewn(fe->npresets, game_params *);
385 for (i = 0; i < fe->npresets; i++) {
388 midend_fetch_preset(fe->me, i, &name, &fe->presets[i]);
391 * FIXME: we ought to go through and do something
392 * with ampersands here.
395 AppendMenu(sub, MF_ENABLED, IDM_PRESETS + 0x10 * i, name);
398 if (game_can_configure) {
399 AppendMenu(sub, MF_ENABLED, IDM_CONFIG, "Custom...");
403 AppendMenu(menu, MF_SEPARATOR, 0, 0);
404 AppendMenu(menu, MF_ENABLED, IDM_UNDO, "Undo");
405 AppendMenu(menu, MF_ENABLED, IDM_REDO, "Redo");
406 AppendMenu(menu, MF_SEPARATOR, 0, 0);
407 AppendMenu(menu, MF_ENABLED, IDM_QUIT, "Exit");
408 SetMenu(fe->hwnd, bar);
411 if (midend_wants_statusbar(fe->me)) {
412 fe->statusbar = CreateWindowEx(0, STATUSCLASSNAME, "ooh",
413 WS_CHILD | WS_VISIBLE,
414 0, 0, 0, 0, /* status bar does these */
415 fe->hwnd, NULL, inst, NULL);
416 GetWindowRect(fe->statusbar, &sr);
417 SetWindowPos(fe->hwnd, NULL, 0, 0,
418 r.right - r.left, r.bottom - r.top + sr.bottom - sr.top,
419 SWP_NOMOVE | SWP_NOZORDER);
420 SetWindowPos(fe->statusbar, NULL, 0, y, x, sr.bottom - sr.top,
423 fe->statusbar = NULL;
426 hdc = GetDC(fe->hwnd);
427 fe->bitmap = CreateCompatibleBitmap(hdc, x, y);
428 ReleaseDC(fe->hwnd, hdc);
430 SetWindowLong(fe->hwnd, GWL_USERDATA, (LONG)fe);
432 ShowWindow(fe->hwnd, SW_NORMAL);
433 SetForegroundWindow(fe->hwnd);
435 midend_redraw(fe->me);
440 static int CALLBACK ConfigDlgProc(HWND hwnd, UINT msg,
441 WPARAM wParam, LPARAM lParam)
443 frontend *fe = (frontend *)GetWindowLong(hwnd, GWL_USERDATA);
453 * OK and Cancel are special cases.
455 if ((HIWORD(wParam) == BN_CLICKED ||
456 HIWORD(wParam) == BN_DOUBLECLICKED) &&
457 (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)) {
458 if (LOWORD(wParam) == IDOK) {
459 char *err = midend_set_config(fe->me, fe->cfg_which, fe->cfg);
462 MessageBox(hwnd, err, "Validation error",
463 MB_ICONERROR | MB_OK);
474 * First find the control whose id this is.
476 for (i = fe->cfg, j = fe->cfgaux; i->type != C_END; i++, j++) {
477 if (j->ctlid == LOWORD(wParam))
480 if (i->type == C_END)
481 return 0; /* not our problem */
483 if (i->type == C_STRING && HIWORD(wParam) == EN_CHANGE) {
485 GetDlgItemText(fe->cfgbox, j->ctlid, buffer, lenof(buffer));
486 buffer[lenof(buffer)-1] = '\0';
488 i->sval = dupstr(buffer);
489 } else if (i->type == C_BOOLEAN &&
490 (HIWORD(wParam) == BN_CLICKED ||
491 HIWORD(wParam) == BN_DOUBLECLICKED)) {
492 i->ival = IsDlgButtonChecked(fe->cfgbox, j->ctlid);
493 } else if (i->type == C_CHOICES &&
494 HIWORD(wParam) == CBN_SELCHANGE) {
495 i->ival = SendDlgItemMessage(fe->cfgbox, j->ctlid,
509 HWND mkctrl(frontend *fe, int x1, int x2, int y1, int y2,
510 char *wclass, int wstyle,
511 int exstyle, char *wtext, int wid)
514 ret = CreateWindowEx(exstyle, wclass, wtext,
515 wstyle | WS_CHILD | WS_VISIBLE, x1, y1, x2-x1, y2-y1,
516 fe->cfgbox, (HMENU) wid, fe->inst, NULL);
517 SendMessage(ret, WM_SETFONT, (WPARAM)fe->cfgfont, MAKELPARAM(TRUE, 0));
521 static int get_config(frontend *fe, int which)
534 int winwidth, winheight, col1l, col1r, col2l, col2r, y;
535 int height, width, maxlabel, maxcheckbox;
537 wc.style = CS_DBLCLKS | CS_SAVEBITS | CS_BYTEALIGNWINDOW;
538 wc.lpfnWndProc = DefDlgProc;
540 wc.cbWndExtra = DLGWINDOWEXTRA + 8;
541 wc.hInstance = fe->inst;
543 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
544 wc.hbrBackground = (HBRUSH) (COLOR_BACKGROUND +1);
545 wc.lpszMenuName = NULL;
546 wc.lpszClassName = "GameConfigBox";
549 hdc = GetDC(fe->hwnd);
550 SetMapMode(hdc, MM_TEXT);
552 fe->cfg_done = FALSE;
554 fe->cfgfont = CreateFont(-MulDiv(8, GetDeviceCaps(hdc, LOGPIXELSY), 72),
556 FALSE, FALSE, FALSE, DEFAULT_CHARSET,
557 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
562 oldfont = SelectObject(hdc, fe->cfgfont);
563 if (GetTextMetrics(hdc, &tm)) {
564 height = tm.tmAscent + tm.tmDescent;
565 width = tm.tmAveCharWidth;
570 fe->cfg = midend_get_config(fe->me, which, &title);
571 fe->cfg_which = which;
574 * Figure out the layout of the config box by measuring the
575 * length of each piece of text.
577 maxlabel = maxcheckbox = 0;
578 winheight = height/2;
580 for (i = fe->cfg; i->type != C_END; i++) {
585 * Both these control types have a label filling only
586 * the left-hand column of the box.
588 if (GetTextExtentPoint32(hdc, i->name, strlen(i->name), &size) &&
591 winheight += height * 3 / 2 + (height / 2);
596 * Checkboxes take up the whole of the box width.
598 if (GetTextExtentPoint32(hdc, i->name, strlen(i->name), &size) &&
599 maxcheckbox < size.cx)
600 maxcheckbox = size.cx;
601 winheight += height + (height / 2);
606 winheight += height + height * 7 / 4; /* OK / Cancel buttons */
609 col1r = col1l + maxlabel;
610 col2l = col1r + 2*width;
611 col2r = col2l + 30*width;
612 if (col2r < col1l+2*height+maxcheckbox)
613 col2r = col1l+2*height+maxcheckbox;
614 winwidth = col2r + 2*width;
616 ReleaseDC(fe->hwnd, hdc);
619 * Create the dialog, now that we know its size.
626 r.bottom = winheight;
628 AdjustWindowRectEx(&r, (WS_OVERLAPPEDWINDOW /*|
629 DS_MODALFRAME | WS_POPUP | WS_VISIBLE |
630 WS_CAPTION | WS_SYSMENU*/) &~
631 (WS_MAXIMIZEBOX | WS_OVERLAPPED),
635 * Centre the dialog on its parent window.
639 GetWindowRect(fe->hwnd, &r2);
640 r.left = (r2.left + r2.right - r.right) / 2;
641 r.top = (r2.top + r2.bottom - r.bottom) / 2;
645 fe->cfgbox = CreateWindowEx(0, wc.lpszClassName, title,
646 DS_MODALFRAME | WS_POPUP | WS_VISIBLE |
647 WS_CAPTION | WS_SYSMENU,
649 r.right-r.left, r.bottom-r.top,
650 fe->hwnd, NULL, fe->inst, NULL);
654 SendMessage(fe->cfgbox, WM_SETFONT, (WPARAM)fe->cfgfont, FALSE);
656 SetWindowLong(fe->cfgbox, GWL_USERDATA, (LONG)fe);
657 SetWindowLong(fe->cfgbox, DWL_DLGPROC, (LONG)ConfigDlgProc);
660 * Count the controls so we can allocate cfgaux.
662 for (nctrls = 0, i = fe->cfg; i->type != C_END; i++)
664 fe->cfgaux = snewn(nctrls, struct cfg_aux);
668 for (i = fe->cfg, j = fe->cfgaux; i->type != C_END; i++, j++) {
672 * Edit box with a label beside it.
674 mkctrl(fe, col1l, col1r, y+height*1/8, y+height*9/8,
675 "Static", 0, 0, i->name, id++);
676 ctl = mkctrl(fe, col2l, col2r, y, y+height*3/2,
677 "EDIT", WS_TABSTOP | ES_AUTOHSCROLL,
678 WS_EX_CLIENTEDGE, "", (j->ctlid = id++));
679 SetWindowText(ctl, i->sval);
687 mkctrl(fe, col1l, col2r, y, y+height, "BUTTON",
688 BS_NOTIFY | BS_AUTOCHECKBOX | WS_TABSTOP,
689 0, i->name, (j->ctlid = id++));
690 CheckDlgButton(fe->cfgbox, j->ctlid, (i->ival != 0));
696 * Drop-down list with a label beside it.
698 mkctrl(fe, col1l, col1r, y+height*1/8, y+height*9/8,
699 "STATIC", 0, 0, i->name, id++);
700 ctl = mkctrl(fe, col2l, col2r, y, y+height*41/2,
701 "COMBOBOX", WS_TABSTOP |
702 CBS_DROPDOWNLIST | CBS_HASSTRINGS,
703 WS_EX_CLIENTEDGE, "", (j->ctlid = id++));
705 char c, *p, *q, *str;
707 SendMessage(ctl, CB_RESETCONTENT, 0, 0);
712 while (*q && *q != c) q++;
713 str = snewn(q-p+1, char);
714 strncpy(str, p, q-p);
716 SendMessage(ctl, CB_ADDSTRING, 0, (LPARAM)str);
723 SendMessage(ctl, CB_SETCURSEL, i->ival, 0);
729 assert(y < winheight);
733 y += height/2; /* extra space before OK and Cancel */
734 mkctrl(fe, col1l, (col1l+col2r)/2-width, y, y+height*7/4, "BUTTON",
735 BS_PUSHBUTTON | BS_NOTIFY | WS_TABSTOP | BS_DEFPUSHBUTTON, 0,
737 mkctrl(fe, (col1l+col2r)/2+width, col2r, y, y+height*7/4, "BUTTON",
738 BS_PUSHBUTTON | BS_NOTIFY | WS_TABSTOP, 0, "Cancel", IDCANCEL);
740 SendMessage(fe->cfgbox, WM_INITDIALOG, 0, 0);
742 EnableWindow(fe->hwnd, FALSE);
743 ShowWindow(fe->cfgbox, SW_NORMAL);
744 while ((gm=GetMessage(&msg, NULL, 0, 0)) > 0) {
745 if (!IsDialogMessage(fe->cfgbox, &msg))
746 DispatchMessage(&msg);
750 EnableWindow(fe->hwnd, TRUE);
751 SetForegroundWindow(fe->hwnd);
752 DestroyWindow(fe->cfgbox);
753 DeleteObject(fe->cfgfont);
758 return (fe->cfg_done == 2);
761 static void new_game_type(frontend *fe)
767 midend_new_game(fe->me);
768 midend_size(fe->me, &x, &y);
773 AdjustWindowRectEx(&r, WS_OVERLAPPEDWINDOW &~
774 (WS_THICKFRAME | WS_MAXIMIZEBOX |
778 if (fe->statusbar != NULL) {
779 GetWindowRect(fe->statusbar, &sr);
781 sr.left = sr.right = sr.top = sr.bottom = 0;
783 SetWindowPos(fe->hwnd, NULL, 0, 0,
785 r.bottom - r.top + sr.bottom - sr.top,
786 SWP_NOMOVE | SWP_NOZORDER);
787 if (fe->statusbar != NULL)
788 SetWindowPos(fe->statusbar, NULL, 0, y, x,
789 sr.bottom - sr.top, SWP_NOZORDER);
791 DeleteObject(fe->bitmap);
793 hdc = GetDC(fe->hwnd);
794 fe->bitmap = CreateCompatibleBitmap(hdc, x, y);
795 ReleaseDC(fe->hwnd, hdc);
797 midend_redraw(fe->me);
800 static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
801 WPARAM wParam, LPARAM lParam)
803 frontend *fe = (frontend *)GetWindowLong(hwnd, GWL_USERDATA);
810 switch (wParam & ~0xF) { /* low 4 bits reserved to Windows */
812 if (!midend_process_key(fe->me, 0, 0, 'n'))
816 if (!midend_process_key(fe->me, 0, 0, 'r'))
820 if (!midend_process_key(fe->me, 0, 0, 'u'))
824 if (!midend_process_key(fe->me, 0, 0, '\x12'))
828 if (!midend_process_key(fe->me, 0, 0, 'q'))
832 if (get_config(fe, CFG_SETTINGS))
836 if (get_config(fe, CFG_SEED))
841 int p = ((wParam &~ 0xF) - IDM_PRESETS) / 0x10;
843 if (p >= 0 && p < fe->npresets) {
844 midend_set_params(fe->me, fe->presets[p]);
860 hdc = BeginPaint(hwnd, &p);
861 hdc2 = CreateCompatibleDC(hdc);
862 prevbm = SelectObject(hdc2, fe->bitmap);
864 p.rcPaint.left, p.rcPaint.top,
865 p.rcPaint.right - p.rcPaint.left,
866 p.rcPaint.bottom - p.rcPaint.top,
868 p.rcPaint.left, p.rcPaint.top,
870 SelectObject(hdc2, prevbm);
880 case VK_LEFT: key = CURSOR_LEFT; break;
881 case VK_RIGHT: key = CURSOR_RIGHT; break;
882 case VK_UP: key = CURSOR_UP; break;
883 case VK_DOWN: key = CURSOR_DOWN; break;
885 * Diagonal keys on the numeric keypad.
888 if (!(lParam & 0x01000000)) key = CURSOR_UP_RIGHT;
891 if (!(lParam & 0x01000000)) key = CURSOR_DOWN_RIGHT;
894 if (!(lParam & 0x01000000)) key = CURSOR_UP_LEFT;
897 if (!(lParam & 0x01000000)) key = CURSOR_DOWN_LEFT;
900 * Numeric keypad keys with Num Lock on.
902 case VK_NUMPAD4: key = CURSOR_LEFT; break;
903 case VK_NUMPAD6: key = CURSOR_RIGHT; break;
904 case VK_NUMPAD8: key = CURSOR_UP; break;
905 case VK_NUMPAD2: key = CURSOR_DOWN; break;
906 case VK_NUMPAD9: key = CURSOR_UP_RIGHT; break;
907 case VK_NUMPAD3: key = CURSOR_DOWN_RIGHT; break;
908 case VK_NUMPAD7: key = CURSOR_UP_LEFT; break;
909 case VK_NUMPAD1: key = CURSOR_DOWN_LEFT; break;
913 if (!midend_process_key(fe->me, 0, 0, key))
918 m.message = WM_KEYDOWN;
920 m.lParam = lParam & 0xdfff;
921 TranslateMessage(&m);
932 * Shift-clicks count as middle-clicks, since otherwise
933 * two-button Windows users won't have any kind of
934 * middle click to use.
936 if (message == WM_MBUTTONDOWN || (wParam & MK_SHIFT))
937 button = MIDDLE_BUTTON;
938 else if (message == WM_LBUTTONDOWN)
939 button = LEFT_BUTTON;
941 button = RIGHT_BUTTON;
943 if (!midend_process_key(fe->me, LOWORD(lParam),
944 HIWORD(lParam), button))
957 * Shift-clicks count as middle-clicks, since otherwise
958 * two-button Windows users won't have any kind of
959 * middle click to use.
961 if (message == WM_MBUTTONUP || (wParam & MK_SHIFT))
962 button = MIDDLE_RELEASE;
963 else if (message == WM_LBUTTONUP)
964 button = LEFT_RELEASE;
966 button = RIGHT_RELEASE;
968 if (!midend_process_key(fe->me, LOWORD(lParam),
969 HIWORD(lParam), button))
979 if (wParam & (MK_MBUTTON | MK_SHIFT))
980 button = MIDDLE_DRAG;
981 else if (wParam & MK_LBUTTON)
986 if (!midend_process_key(fe->me, LOWORD(lParam),
987 HIWORD(lParam), button))
992 if (!midend_process_key(fe->me, 0, 0, (unsigned char)wParam))
997 DWORD now = GetTickCount();
998 float elapsed = (float) (now - fe->timer_last_tickcount) * 0.001F;
999 midend_timer(fe->me, elapsed);
1000 fe->timer_last_tickcount = now;
1005 return DefWindowProc(hwnd, message, wParam, lParam);
1008 int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
1012 InitCommonControls();
1018 wndclass.lpfnWndProc = WndProc;
1019 wndclass.cbClsExtra = 0;
1020 wndclass.cbWndExtra = 0;
1021 wndclass.hInstance = inst;
1022 wndclass.hIcon = LoadIcon(inst, IDI_APPLICATION);
1023 wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
1024 wndclass.hbrBackground = NULL;
1025 wndclass.lpszMenuName = NULL;
1026 wndclass.lpszClassName = game_name;
1028 RegisterClass(&wndclass);
1033 while (GetMessage(&msg, NULL, 0, 0)) {
1034 DispatchMessage(&msg);