2 * windows.c: Windows front end for my puzzle collection.
18 #define IDM_NEW 0x0010
19 #define IDM_RESTART 0x0020
20 #define IDM_UNDO 0x0030
21 #define IDM_REDO 0x0040
22 #define IDM_COPY 0x0050
23 #define IDM_SOLVE 0x0060
24 #define IDM_QUIT 0x0070
25 #define IDM_CONFIG 0x0080
26 #define IDM_DESC 0x0090
27 #define IDM_SEED 0x00A0
28 #define IDM_HELPC 0x00B0
29 #define IDM_GAMEHELP 0x00C0
30 #define IDM_ABOUT 0x00D0
31 #define IDM_SAVE 0x00E0
32 #define IDM_LOAD 0x00F0
33 #define IDM_PRESETS 0x0100
35 #define HELP_FILE_NAME "puzzles.hlp"
36 #define HELP_CNT_NAME "puzzles.cnt"
39 static FILE *debug_fp
= NULL
;
40 static HANDLE debug_hdl
= INVALID_HANDLE_VALUE
;
41 static int debug_got_console
= 0;
47 if (!debug_got_console
) {
49 debug_got_console
= 1;
50 debug_hdl
= GetStdHandle(STD_OUTPUT_HANDLE
);
54 debug_fp
= fopen("debug.log", "w");
57 if (debug_hdl
!= INVALID_HANDLE_VALUE
) {
58 WriteFile(debug_hdl
, buf
, strlen(buf
), &dw
, NULL
);
64 void debug_printf(char *fmt
, ...)
70 vsprintf(buf
, fmt
, ap
);
94 HWND hwnd
, statusbar
, cfgbox
;
96 HBITMAP bitmap
, prevbm
;
103 DWORD timer_last_tickcount
;
105 game_params
**presets
;
107 int nfonts
, fontsize
;
109 struct cfg_aux
*cfgaux
;
110 int cfg_which
, dlg_done
;
113 int help_has_contents
;
117 void fatal(char *fmt
, ...)
123 vsprintf(buf
, fmt
, ap
);
126 MessageBox(NULL
, buf
, "Fatal error", MB_ICONEXCLAMATION
| MB_OK
);
131 void get_random_seed(void **randseed
, int *randseedsize
)
133 time_t *tp
= snew(time_t);
135 *randseed
= (void *)tp
;
136 *randseedsize
= sizeof(time_t);
139 void status_bar(frontend
*fe
, char *text
)
141 char *rewritten
= midend_rewrite_statusbar(fe
->me
, text
);
142 if (!fe
->laststatus
|| strcmp(rewritten
, fe
->laststatus
)) {
143 SetWindowText(fe
->statusbar
, rewritten
);
144 sfree(fe
->laststatus
);
145 fe
->laststatus
= rewritten
;
151 blitter
*blitter_new(int w
, int h
)
153 blitter
*bl
= snew(blitter
);
155 memset(bl
, 0, sizeof(blitter
));
163 void blitter_free(blitter
*bl
)
165 if (bl
->bitmap
) DeleteObject(bl
->bitmap
);
169 static void blitter_mkbitmap(frontend
*fe
, blitter
*bl
)
171 HDC hdc
= GetDC(fe
->hwnd
);
172 bl
->bitmap
= CreateCompatibleBitmap(hdc
, bl
->w
, bl
->h
);
173 ReleaseDC(fe
->hwnd
, hdc
);
176 /* BitBlt(dstDC, dstX, dstY, dstW, dstH, srcDC, srcX, srcY, dType) */
178 void blitter_save(frontend
*fe
, blitter
*bl
, int x
, int y
)
180 HDC hdc_win
, hdc_blit
;
183 if (!bl
->bitmap
) blitter_mkbitmap(fe
, bl
);
185 bl
->x
= x
; bl
->y
= y
;
187 hdc_win
= GetDC(fe
->hwnd
);
188 hdc_blit
= CreateCompatibleDC(hdc_win
);
189 if (!hdc_blit
) fatal("hdc_blit failed: 0x%x", GetLastError());
191 prev_blit
= SelectObject(hdc_blit
, bl
->bitmap
);
192 if (prev_blit
== NULL
|| prev_blit
== HGDI_ERROR
)
193 fatal("SelectObject for hdc_main failed: 0x%x", GetLastError());
195 if (!BitBlt(hdc_blit
, 0, 0, bl
->w
, bl
->h
,
196 fe
->hdc_bm
, x
, y
, SRCCOPY
))
197 fatal("BitBlt failed: 0x%x", GetLastError());
199 SelectObject(hdc_blit
, prev_blit
);
201 ReleaseDC(fe
->hwnd
, hdc_win
);
204 void blitter_load(frontend
*fe
, blitter
*bl
, int x
, int y
)
206 HDC hdc_win
, hdc_blit
;
209 assert(bl
->bitmap
); /* we should always have saved before loading */
211 if (x
== BLITTER_FROMSAVED
) x
= bl
->x
;
212 if (y
== BLITTER_FROMSAVED
) y
= bl
->y
;
214 hdc_win
= GetDC(fe
->hwnd
);
215 hdc_blit
= CreateCompatibleDC(hdc_win
);
217 prev_blit
= SelectObject(hdc_blit
, bl
->bitmap
);
219 BitBlt(fe
->hdc_bm
, x
, y
, bl
->w
, bl
->h
,
220 hdc_blit
, 0, 0, SRCCOPY
);
222 SelectObject(hdc_blit
, prev_blit
);
224 ReleaseDC(fe
->hwnd
, hdc_win
);
227 void frontend_default_colour(frontend
*fe
, float *output
)
229 DWORD c
= GetSysColor(COLOR_MENU
); /* ick */
231 output
[0] = (float)(GetRValue(c
) / 255.0);
232 output
[1] = (float)(GetGValue(c
) / 255.0);
233 output
[2] = (float)(GetBValue(c
) / 255.0);
236 void clip(frontend
*fe
, int x
, int y
, int w
, int h
)
238 IntersectClipRect(fe
->hdc_bm
, x
, y
, x
+w
, y
+h
);
241 void unclip(frontend
*fe
)
243 SelectClipRgn(fe
->hdc_bm
, NULL
);
246 void draw_text(frontend
*fe
, int x
, int y
, int fonttype
, int fontsize
,
247 int align
, int colour
, char *text
)
252 * Find or create the font.
254 for (i
= 0; i
< fe
->nfonts
; i
++)
255 if (fe
->fonts
[i
].type
== fonttype
&& fe
->fonts
[i
].size
== fontsize
)
258 if (i
== fe
->nfonts
) {
259 if (fe
->fontsize
<= fe
->nfonts
) {
260 fe
->fontsize
= fe
->nfonts
+ 10;
261 fe
->fonts
= sresize(fe
->fonts
, fe
->fontsize
, struct font
);
266 fe
->fonts
[i
].type
= fonttype
;
267 fe
->fonts
[i
].size
= fontsize
;
269 fe
->fonts
[i
].font
= CreateFont(-fontsize
, 0, 0, 0, FW_BOLD
,
270 FALSE
, FALSE
, FALSE
, DEFAULT_CHARSET
,
271 OUT_DEFAULT_PRECIS
, CLIP_DEFAULT_PRECIS
,
273 (fonttype
== FONT_FIXED ?
274 FIXED_PITCH
| FF_DONTCARE
:
275 VARIABLE_PITCH
| FF_SWISS
),
280 * Position and draw the text.
287 oldfont
= SelectObject(fe
->hdc_bm
, fe
->fonts
[i
].font
);
288 if (GetTextMetrics(fe
->hdc_bm
, &tm
)) {
289 if (align
& ALIGN_VCENTRE
)
290 y
-= (tm
.tmAscent
+tm
.tmDescent
)/2;
294 if (GetTextExtentPoint32(fe
->hdc_bm
, text
, strlen(text
), &size
)) {
295 if (align
& ALIGN_HCENTRE
)
297 else if (align
& ALIGN_HRIGHT
)
300 SetBkMode(fe
->hdc_bm
, TRANSPARENT
);
301 SetTextColor(fe
->hdc_bm
, fe
->colours
[colour
]);
302 TextOut(fe
->hdc_bm
, x
, y
, text
, strlen(text
));
303 SelectObject(fe
->hdc_bm
, oldfont
);
307 void draw_rect(frontend
*fe
, int x
, int y
, int w
, int h
, int colour
)
309 if (w
== 1 && h
== 1) {
311 * Rectangle() appears to get uppity if asked to draw a 1x1
312 * rectangle, presumably on the grounds that that's beneath
313 * its dignity and you ought to be using SetPixel instead.
316 SetPixel(fe
->hdc_bm
, x
, y
, fe
->colours
[colour
]);
318 HBRUSH oldbrush
= SelectObject(fe
->hdc_bm
, fe
->brushes
[colour
]);
319 HPEN oldpen
= SelectObject(fe
->hdc_bm
, fe
->pens
[colour
]);
320 Rectangle(fe
->hdc_bm
, x
, y
, x
+w
, y
+h
);
321 SelectObject(fe
->hdc_bm
, oldbrush
);
322 SelectObject(fe
->hdc_bm
, oldpen
);
326 void draw_line(frontend
*fe
, int x1
, int y1
, int x2
, int y2
, int colour
)
328 HPEN oldpen
= SelectObject(fe
->hdc_bm
, fe
->pens
[colour
]);
329 MoveToEx(fe
->hdc_bm
, x1
, y1
, NULL
);
330 LineTo(fe
->hdc_bm
, x2
, y2
);
331 SetPixel(fe
->hdc_bm
, x2
, y2
, fe
->colours
[colour
]);
332 SelectObject(fe
->hdc_bm
, oldpen
);
335 void draw_circle(frontend
*fe
, int cx
, int cy
, int radius
,
336 int fill
, int colour
)
339 HBRUSH oldbrush
= SelectObject(fe
->hdc_bm
, fe
->brushes
[colour
]);
340 HPEN oldpen
= SelectObject(fe
->hdc_bm
, fe
->pens
[colour
]);
341 Ellipse(fe
->hdc_bm
, cx
- radius
, cy
- radius
,
342 cx
+ radius
+ 1, cy
+ radius
+ 1);
343 SelectObject(fe
->hdc_bm
, oldbrush
);
344 SelectObject(fe
->hdc_bm
, oldpen
);
346 HPEN oldpen
= SelectObject(fe
->hdc_bm
, fe
->pens
[colour
]);
347 Arc(fe
->hdc_bm
, cx
- radius
, cy
- radius
,
348 cx
+ radius
+ 1, cy
+ radius
+ 1,
349 cx
- radius
, cy
, cx
- radius
, cy
);
350 SelectObject(fe
->hdc_bm
, oldpen
);
354 void draw_polygon(frontend
*fe
, int *coords
, int npoints
,
355 int fill
, int colour
)
357 POINT
*pts
= snewn(npoints
+1, POINT
);
360 for (i
= 0; i
<= npoints
; i
++) {
361 int j
= (i
< npoints ? i
: 0);
362 pts
[i
].x
= coords
[j
*2];
363 pts
[i
].y
= coords
[j
*2+1];
367 HBRUSH oldbrush
= SelectObject(fe
->hdc_bm
, fe
->brushes
[colour
]);
368 HPEN oldpen
= SelectObject(fe
->hdc_bm
, fe
->pens
[colour
]);
369 Polygon(fe
->hdc_bm
, pts
, npoints
);
370 SelectObject(fe
->hdc_bm
, oldbrush
);
371 SelectObject(fe
->hdc_bm
, oldpen
);
373 HPEN oldpen
= SelectObject(fe
->hdc_bm
, fe
->pens
[colour
]);
374 Polyline(fe
->hdc_bm
, pts
, npoints
+1);
375 SelectObject(fe
->hdc_bm
, oldpen
);
381 void start_draw(frontend
*fe
)
384 hdc_win
= GetDC(fe
->hwnd
);
385 fe
->hdc_bm
= CreateCompatibleDC(hdc_win
);
386 fe
->prevbm
= SelectObject(fe
->hdc_bm
, fe
->bitmap
);
387 ReleaseDC(fe
->hwnd
, hdc_win
);
389 SetMapMode(fe
->hdc_bm
, MM_TEXT
);
392 void draw_update(frontend
*fe
, int x
, int y
, int w
, int h
)
401 InvalidateRect(fe
->hwnd
, &r
, FALSE
);
404 void end_draw(frontend
*fe
)
406 SelectObject(fe
->hdc_bm
, fe
->prevbm
);
407 DeleteDC(fe
->hdc_bm
);
409 DeleteObject(fe
->clip
);
414 void deactivate_timer(frontend
*fe
)
416 KillTimer(fe
->hwnd
, fe
->timer
);
420 void activate_timer(frontend
*fe
)
423 fe
->timer
= SetTimer(fe
->hwnd
, fe
->timer
, 20, NULL
);
424 fe
->timer_last_tickcount
= GetTickCount();
428 void write_clip(HWND hwnd
, char *data
)
436 * Windows expects CRLF in the clipboard, so we must convert
437 * any \n that has come out of the puzzle backend.
440 for (i
= 0; data
[i
]; i
++) {
445 data2
= snewn(len
+1, char);
447 for (i
= 0; data
[i
]; i
++) {
450 data2
[j
++] = data
[i
];
455 clipdata
= GlobalAlloc(GMEM_DDESHARE
| GMEM_MOVEABLE
, len
+ 1);
458 lock
= GlobalLock(clipdata
);
461 memcpy(lock
, data2
, len
);
462 ((unsigned char *) lock
)[len
] = 0;
463 GlobalUnlock(clipdata
);
465 if (OpenClipboard(hwnd
)) {
467 SetClipboardData(CF_TEXT
, clipdata
);
470 GlobalFree(clipdata
);
476 * See if we can find a help file.
478 static void find_help_file(frontend
*fe
)
480 char b
[2048], *p
, *q
, *r
;
482 if (!fe
->help_path
) {
483 GetModuleFileName(NULL
, b
, sizeof(b
) - 1);
485 p
= strrchr(b
, '\\');
486 if (p
&& p
>= r
) r
= p
+1;
488 if (q
&& q
>= r
) r
= q
+1;
489 strcpy(r
, HELP_FILE_NAME
);
490 if ( (fp
= fopen(b
, "r")) != NULL
) {
491 fe
->help_path
= dupstr(b
);
494 fe
->help_path
= NULL
;
495 strcpy(r
, HELP_CNT_NAME
);
496 if ( (fp
= fopen(b
, "r")) != NULL
) {
497 fe
->help_has_contents
= TRUE
;
500 fe
->help_has_contents
= FALSE
;
504 static void check_window_size(frontend
*fe
, int *px
, int *py
)
511 GetWindowRect(fe
->statusbar
, &sr
);
512 sy
= sr
.bottom
- sr
.top
;
518 * See if we actually got the window size we wanted, and adjust
519 * the puzzle size if not.
521 GetClientRect(fe
->hwnd
, &r
);
522 x
= r
.right
- r
.left
;
523 y
= r
.bottom
- r
.top
- sy
;
524 midend_size(fe
->me
, &x
, &y
, FALSE
);
525 if (x
!= r
.right
- r
.left
|| y
!= r
.bottom
- r
.top
) {
527 * Resize the window, now we know what size we _really_
533 AdjustWindowRectEx(&r
, WS_OVERLAPPEDWINDOW
&~
534 (WS_THICKFRAME
| WS_MAXIMIZEBOX
| WS_OVERLAPPED
),
536 SetWindowPos(fe
->hwnd
, NULL
, 0, 0, r
.right
- r
.left
, r
.bottom
- r
.top
,
537 SWP_NOMOVE
| SWP_NOZORDER
);
541 GetClientRect(fe
->hwnd
, &r
);
542 SetWindowPos(fe
->statusbar
, NULL
, 0, r
.bottom
-r
.top
-sy
, r
.right
-r
.left
,
550 static frontend
*new_window(HINSTANCE inst
, char *game_id
, char **error
)
559 fe
->me
= midend_new(fe
, &thegame
);
562 *error
= midend_game_id(fe
->me
, game_id
);
570 fe
->help_path
= NULL
;
574 midend_new_game(fe
->me
);
579 fe
->nfonts
= fe
->fontsize
= 0;
581 fe
->laststatus
= NULL
;
587 colours
= midend_colours(fe
->me
, &ncolours
);
589 fe
->colours
= snewn(ncolours
, COLORREF
);
590 fe
->brushes
= snewn(ncolours
, HBRUSH
);
591 fe
->pens
= snewn(ncolours
, HPEN
);
593 for (i
= 0; i
< ncolours
; i
++) {
594 fe
->colours
[i
] = RGB(255 * colours
[i
*3+0],
595 255 * colours
[i
*3+1],
596 255 * colours
[i
*3+2]);
597 fe
->brushes
[i
] = CreateSolidBrush(fe
->colours
[i
]);
598 fe
->pens
[i
] = CreatePen(PS_SOLID
, 1, fe
->colours
[i
]);
602 x
= y
= INT_MAX
; /* find puzzle's preferred size */
603 midend_size(fe
->me
, &x
, &y
, FALSE
);
608 AdjustWindowRectEx(&r
, WS_OVERLAPPEDWINDOW
&~
609 (WS_THICKFRAME
| WS_MAXIMIZEBOX
| WS_OVERLAPPED
),
612 fe
->hwnd
= CreateWindowEx(0, thegame
.name
, thegame
.name
,
613 WS_OVERLAPPEDWINDOW
&~
614 (WS_THICKFRAME
| WS_MAXIMIZEBOX
),
615 CW_USEDEFAULT
, CW_USEDEFAULT
,
616 r
.right
- r
.left
, r
.bottom
- r
.top
,
617 NULL
, NULL
, inst
, NULL
);
619 if (midend_wants_statusbar(fe
->me
)) {
621 fe
->statusbar
= CreateWindowEx(0, STATUSCLASSNAME
, "ooh",
622 WS_CHILD
| WS_VISIBLE
,
623 0, 0, 0, 0, /* status bar does these */
624 fe
->hwnd
, NULL
, inst
, NULL
);
626 * Now resize the window to take account of the status bar.
628 GetWindowRect(fe
->statusbar
, &sr
);
629 GetWindowRect(fe
->hwnd
, &r
);
630 SetWindowPos(fe
->hwnd
, NULL
, 0, 0, r
.right
- r
.left
,
631 r
.bottom
- r
.top
+ sr
.bottom
- sr
.top
,
632 SWP_NOMOVE
| SWP_NOZORDER
);
634 fe
->statusbar
= NULL
;
638 HMENU bar
= CreateMenu();
639 HMENU menu
= CreateMenu();
641 AppendMenu(bar
, MF_ENABLED
|MF_POPUP
, (UINT
)menu
, "Game");
642 AppendMenu(menu
, MF_ENABLED
, IDM_NEW
, "New");
643 AppendMenu(menu
, MF_ENABLED
, IDM_RESTART
, "Restart");
644 AppendMenu(menu
, MF_ENABLED
, IDM_DESC
, "Specific...");
645 AppendMenu(menu
, MF_ENABLED
, IDM_SEED
, "Random Seed...");
647 if ((fe
->npresets
= midend_num_presets(fe
->me
)) > 0 ||
648 thegame
.can_configure
) {
649 HMENU sub
= CreateMenu();
652 AppendMenu(bar
, MF_ENABLED
|MF_POPUP
, (UINT
)sub
, "Type");
654 fe
->presets
= snewn(fe
->npresets
, game_params
*);
656 for (i
= 0; i
< fe
->npresets
; i
++) {
659 midend_fetch_preset(fe
->me
, i
, &name
, &fe
->presets
[i
]);
662 * FIXME: we ought to go through and do something
663 * with ampersands here.
666 AppendMenu(sub
, MF_ENABLED
, IDM_PRESETS
+ 0x10 * i
, name
);
669 if (thegame
.can_configure
) {
670 AppendMenu(sub
, MF_ENABLED
, IDM_CONFIG
, "Custom...");
674 AppendMenu(menu
, MF_SEPARATOR
, 0, 0);
675 AppendMenu(menu
, MF_ENABLED
, IDM_LOAD
, "Load");
676 AppendMenu(menu
, MF_ENABLED
, IDM_SAVE
, "Save");
677 AppendMenu(menu
, MF_SEPARATOR
, 0, 0);
678 AppendMenu(menu
, MF_ENABLED
, IDM_UNDO
, "Undo");
679 AppendMenu(menu
, MF_ENABLED
, IDM_REDO
, "Redo");
680 if (thegame
.can_format_as_text
) {
681 AppendMenu(menu
, MF_SEPARATOR
, 0, 0);
682 AppendMenu(menu
, MF_ENABLED
, IDM_COPY
, "Copy");
684 if (thegame
.can_solve
) {
685 AppendMenu(menu
, MF_SEPARATOR
, 0, 0);
686 AppendMenu(menu
, MF_ENABLED
, IDM_SOLVE
, "Solve");
688 AppendMenu(menu
, MF_SEPARATOR
, 0, 0);
689 AppendMenu(menu
, MF_ENABLED
, IDM_QUIT
, "Exit");
691 AppendMenu(bar
, MF_ENABLED
|MF_POPUP
, (UINT
)menu
, "Help");
692 AppendMenu(menu
, MF_ENABLED
, IDM_ABOUT
, "About");
694 AppendMenu(menu
, MF_SEPARATOR
, 0, 0);
695 AppendMenu(menu
, MF_ENABLED
, IDM_HELPC
, "Contents");
696 if (thegame
.winhelp_topic
) {
698 assert(thegame
.name
);
699 item
= snewn(9+strlen(thegame
.name
), char); /*ick*/
700 sprintf(item
, "Help on %s", thegame
.name
);
701 AppendMenu(menu
, MF_ENABLED
, IDM_GAMEHELP
, item
);
705 SetMenu(fe
->hwnd
, bar
);
708 check_window_size(fe
, &x
, &y
);
710 hdc
= GetDC(fe
->hwnd
);
711 fe
->bitmap
= CreateCompatibleBitmap(hdc
, x
, y
);
712 ReleaseDC(fe
->hwnd
, hdc
);
714 SetWindowLong(fe
->hwnd
, GWL_USERDATA
, (LONG
)fe
);
716 ShowWindow(fe
->hwnd
, SW_NORMAL
);
717 SetForegroundWindow(fe
->hwnd
);
719 midend_redraw(fe
->me
);
724 static int CALLBACK
AboutDlgProc(HWND hwnd
, UINT msg
,
725 WPARAM wParam
, LPARAM lParam
)
727 frontend
*fe
= (frontend
*)GetWindowLong(hwnd
, GWL_USERDATA
);
734 if ((HIWORD(wParam
) == BN_CLICKED
||
735 HIWORD(wParam
) == BN_DOUBLECLICKED
) &&
736 LOWORD(wParam
) == IDOK
)
748 static int CALLBACK
ConfigDlgProc(HWND hwnd
, UINT msg
,
749 WPARAM wParam
, LPARAM lParam
)
751 frontend
*fe
= (frontend
*)GetWindowLong(hwnd
, GWL_USERDATA
);
761 * OK and Cancel are special cases.
763 if ((HIWORD(wParam
) == BN_CLICKED
||
764 HIWORD(wParam
) == BN_DOUBLECLICKED
) &&
765 (LOWORD(wParam
) == IDOK
|| LOWORD(wParam
) == IDCANCEL
)) {
766 if (LOWORD(wParam
) == IDOK
) {
767 char *err
= midend_set_config(fe
->me
, fe
->cfg_which
, fe
->cfg
);
770 MessageBox(hwnd
, err
, "Validation error",
771 MB_ICONERROR
| MB_OK
);
782 * First find the control whose id this is.
784 for (i
= fe
->cfg
, j
= fe
->cfgaux
; i
->type
!= C_END
; i
++, j
++) {
785 if (j
->ctlid
== LOWORD(wParam
))
788 if (i
->type
== C_END
)
789 return 0; /* not our problem */
791 if (i
->type
== C_STRING
&& HIWORD(wParam
) == EN_CHANGE
) {
793 GetDlgItemText(fe
->cfgbox
, j
->ctlid
, buffer
, lenof(buffer
));
794 buffer
[lenof(buffer
)-1] = '\0';
796 i
->sval
= dupstr(buffer
);
797 } else if (i
->type
== C_BOOLEAN
&&
798 (HIWORD(wParam
) == BN_CLICKED
||
799 HIWORD(wParam
) == BN_DOUBLECLICKED
)) {
800 i
->ival
= IsDlgButtonChecked(fe
->cfgbox
, j
->ctlid
);
801 } else if (i
->type
== C_CHOICES
&&
802 HIWORD(wParam
) == CBN_SELCHANGE
) {
803 i
->ival
= SendDlgItemMessage(fe
->cfgbox
, j
->ctlid
,
817 HWND
mkctrl(frontend
*fe
, int x1
, int x2
, int y1
, int y2
,
818 char *wclass
, int wstyle
,
819 int exstyle
, const char *wtext
, int wid
)
822 ret
= CreateWindowEx(exstyle
, wclass
, wtext
,
823 wstyle
| WS_CHILD
| WS_VISIBLE
, x1
, y1
, x2
-x1
, y2
-y1
,
824 fe
->cfgbox
, (HMENU
) wid
, fe
->inst
, NULL
);
825 SendMessage(ret
, WM_SETFONT
, (WPARAM
)fe
->cfgfont
, MAKELPARAM(TRUE
, 0));
829 static void about(frontend
*fe
)
839 int winwidth
, winheight
, y
;
840 int height
, width
, maxwid
;
841 const char *strings
[16];
846 sprintf(titlebuf
, "About %.250s", thegame
.name
);
848 strings
[nstrings
++] = thegame
.name
;
849 strings
[nstrings
++] = "from Simon Tatham's Portable Puzzle Collection";
850 strings
[nstrings
++] = ver
;
852 wc
.style
= CS_DBLCLKS
| CS_SAVEBITS
| CS_BYTEALIGNWINDOW
;
853 wc
.lpfnWndProc
= DefDlgProc
;
855 wc
.cbWndExtra
= DLGWINDOWEXTRA
+ 8;
856 wc
.hInstance
= fe
->inst
;
858 wc
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
859 wc
.hbrBackground
= (HBRUSH
) (COLOR_BACKGROUND
+1);
860 wc
.lpszMenuName
= NULL
;
861 wc
.lpszClassName
= "GameAboutBox";
864 hdc
= GetDC(fe
->hwnd
);
865 SetMapMode(hdc
, MM_TEXT
);
867 fe
->dlg_done
= FALSE
;
869 fe
->cfgfont
= CreateFont(-MulDiv(8, GetDeviceCaps(hdc
, LOGPIXELSY
), 72),
871 FALSE
, FALSE
, FALSE
, DEFAULT_CHARSET
,
872 OUT_DEFAULT_PRECIS
, CLIP_DEFAULT_PRECIS
,
877 oldfont
= SelectObject(hdc
, fe
->cfgfont
);
878 if (GetTextMetrics(hdc
, &tm
)) {
879 height
= tm
.tmAscent
+ tm
.tmDescent
;
880 width
= tm
.tmAveCharWidth
;
886 * Figure out the layout of the About box by measuring the
887 * length of each piece of text.
890 winheight
= height
/2;
892 for (i
= 0; i
< nstrings
; i
++) {
893 if (GetTextExtentPoint32(hdc
, strings
[i
], strlen(strings
[i
]), &size
))
894 lengths
[i
] = size
.cx
;
896 lengths
[i
] = 0; /* *shrug* */
897 if (maxwid
< lengths
[i
])
899 winheight
+= height
* 3 / 2 + (height
/ 2);
902 winheight
+= height
+ height
* 7 / 4; /* OK button */
903 winwidth
= maxwid
+ 4*width
;
905 SelectObject(hdc
, oldfont
);
906 ReleaseDC(fe
->hwnd
, hdc
);
909 * Create the dialog, now that we know its size.
916 r
.bottom
= winheight
;
918 AdjustWindowRectEx(&r
, (WS_OVERLAPPEDWINDOW
/*|
919 DS_MODALFRAME | WS_POPUP | WS_VISIBLE |
920 WS_CAPTION | WS_SYSMENU*/) &~
921 (WS_MAXIMIZEBOX
| WS_OVERLAPPED
),
925 * Centre the dialog on its parent window.
929 GetWindowRect(fe
->hwnd
, &r2
);
930 r
.left
= (r2
.left
+ r2
.right
- r
.right
) / 2;
931 r
.top
= (r2
.top
+ r2
.bottom
- r
.bottom
) / 2;
935 fe
->cfgbox
= CreateWindowEx(0, wc
.lpszClassName
, titlebuf
,
936 DS_MODALFRAME
| WS_POPUP
| WS_VISIBLE
|
937 WS_CAPTION
| WS_SYSMENU
,
939 r
.right
-r
.left
, r
.bottom
-r
.top
,
940 fe
->hwnd
, NULL
, fe
->inst
, NULL
);
943 SendMessage(fe
->cfgbox
, WM_SETFONT
, (WPARAM
)fe
->cfgfont
, FALSE
);
945 SetWindowLong(fe
->cfgbox
, GWL_USERDATA
, (LONG
)fe
);
946 SetWindowLong(fe
->cfgbox
, DWL_DLGPROC
, (LONG
)AboutDlgProc
);
950 for (i
= 0; i
< nstrings
; i
++) {
951 int border
= width
*2 + (maxwid
- lengths
[i
]) / 2;
952 mkctrl(fe
, border
, border
+lengths
[i
], y
+height
*1/8, y
+height
*9/8,
953 "Static", 0, 0, strings
[i
], id
++);
956 assert(y
< winheight
);
960 y
+= height
/2; /* extra space before OK */
961 mkctrl(fe
, width
*2, maxwid
+width
*2, y
, y
+height
*7/4, "BUTTON",
962 BS_PUSHBUTTON
| BS_NOTIFY
| WS_TABSTOP
| BS_DEFPUSHBUTTON
, 0,
965 SendMessage(fe
->cfgbox
, WM_INITDIALOG
, 0, 0);
967 EnableWindow(fe
->hwnd
, FALSE
);
968 ShowWindow(fe
->cfgbox
, SW_NORMAL
);
969 while ((gm
=GetMessage(&msg
, NULL
, 0, 0)) > 0) {
970 if (!IsDialogMessage(fe
->cfgbox
, &msg
))
971 DispatchMessage(&msg
);
975 EnableWindow(fe
->hwnd
, TRUE
);
976 SetForegroundWindow(fe
->hwnd
);
977 DestroyWindow(fe
->cfgbox
);
978 DeleteObject(fe
->cfgfont
);
981 static int get_config(frontend
*fe
, int which
)
994 int winwidth
, winheight
, col1l
, col1r
, col2l
, col2r
, y
;
995 int height
, width
, maxlabel
, maxcheckbox
;
997 wc
.style
= CS_DBLCLKS
| CS_SAVEBITS
| CS_BYTEALIGNWINDOW
;
998 wc
.lpfnWndProc
= DefDlgProc
;
1000 wc
.cbWndExtra
= DLGWINDOWEXTRA
+ 8;
1001 wc
.hInstance
= fe
->inst
;
1003 wc
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
1004 wc
.hbrBackground
= (HBRUSH
) (COLOR_BACKGROUND
+1);
1005 wc
.lpszMenuName
= NULL
;
1006 wc
.lpszClassName
= "GameConfigBox";
1009 hdc
= GetDC(fe
->hwnd
);
1010 SetMapMode(hdc
, MM_TEXT
);
1012 fe
->dlg_done
= FALSE
;
1014 fe
->cfgfont
= CreateFont(-MulDiv(8, GetDeviceCaps(hdc
, LOGPIXELSY
), 72),
1016 FALSE
, FALSE
, FALSE
, DEFAULT_CHARSET
,
1017 OUT_DEFAULT_PRECIS
, CLIP_DEFAULT_PRECIS
,
1022 oldfont
= SelectObject(hdc
, fe
->cfgfont
);
1023 if (GetTextMetrics(hdc
, &tm
)) {
1024 height
= tm
.tmAscent
+ tm
.tmDescent
;
1025 width
= tm
.tmAveCharWidth
;
1027 height
= width
= 30;
1030 fe
->cfg
= midend_get_config(fe
->me
, which
, &title
);
1031 fe
->cfg_which
= which
;
1034 * Figure out the layout of the config box by measuring the
1035 * length of each piece of text.
1037 maxlabel
= maxcheckbox
= 0;
1038 winheight
= height
/2;
1040 for (i
= fe
->cfg
; i
->type
!= C_END
; i
++) {
1045 * Both these control types have a label filling only
1046 * the left-hand column of the box.
1048 if (GetTextExtentPoint32(hdc
, i
->name
, strlen(i
->name
), &size
) &&
1051 winheight
+= height
* 3 / 2 + (height
/ 2);
1056 * Checkboxes take up the whole of the box width.
1058 if (GetTextExtentPoint32(hdc
, i
->name
, strlen(i
->name
), &size
) &&
1059 maxcheckbox
< size
.cx
)
1060 maxcheckbox
= size
.cx
;
1061 winheight
+= height
+ (height
/ 2);
1066 winheight
+= height
+ height
* 7 / 4; /* OK / Cancel buttons */
1069 col1r
= col1l
+ maxlabel
;
1070 col2l
= col1r
+ 2*width
;
1071 col2r
= col2l
+ 30*width
;
1072 if (col2r
< col1l
+2*height
+maxcheckbox
)
1073 col2r
= col1l
+2*height
+maxcheckbox
;
1074 winwidth
= col2r
+ 2*width
;
1076 SelectObject(hdc
, oldfont
);
1077 ReleaseDC(fe
->hwnd
, hdc
);
1080 * Create the dialog, now that we know its size.
1087 r
.bottom
= winheight
;
1089 AdjustWindowRectEx(&r
, (WS_OVERLAPPEDWINDOW
/*|
1090 DS_MODALFRAME | WS_POPUP | WS_VISIBLE |
1091 WS_CAPTION | WS_SYSMENU*/) &~
1092 (WS_MAXIMIZEBOX
| WS_OVERLAPPED
),
1096 * Centre the dialog on its parent window.
1100 GetWindowRect(fe
->hwnd
, &r2
);
1101 r
.left
= (r2
.left
+ r2
.right
- r
.right
) / 2;
1102 r
.top
= (r2
.top
+ r2
.bottom
- r
.bottom
) / 2;
1106 fe
->cfgbox
= CreateWindowEx(0, wc
.lpszClassName
, title
,
1107 DS_MODALFRAME
| WS_POPUP
| WS_VISIBLE
|
1108 WS_CAPTION
| WS_SYSMENU
,
1110 r
.right
-r
.left
, r
.bottom
-r
.top
,
1111 fe
->hwnd
, NULL
, fe
->inst
, NULL
);
1115 SendMessage(fe
->cfgbox
, WM_SETFONT
, (WPARAM
)fe
->cfgfont
, FALSE
);
1117 SetWindowLong(fe
->cfgbox
, GWL_USERDATA
, (LONG
)fe
);
1118 SetWindowLong(fe
->cfgbox
, DWL_DLGPROC
, (LONG
)ConfigDlgProc
);
1121 * Count the controls so we can allocate cfgaux.
1123 for (nctrls
= 0, i
= fe
->cfg
; i
->type
!= C_END
; i
++)
1125 fe
->cfgaux
= snewn(nctrls
, struct cfg_aux
);
1129 for (i
= fe
->cfg
, j
= fe
->cfgaux
; i
->type
!= C_END
; i
++, j
++) {
1133 * Edit box with a label beside it.
1135 mkctrl(fe
, col1l
, col1r
, y
+height
*1/8, y
+height
*9/8,
1136 "Static", 0, 0, i
->name
, id
++);
1137 ctl
= mkctrl(fe
, col2l
, col2r
, y
, y
+height
*3/2,
1138 "EDIT", WS_TABSTOP
| ES_AUTOHSCROLL
,
1139 WS_EX_CLIENTEDGE
, "", (j
->ctlid
= id
++));
1140 SetWindowText(ctl
, i
->sval
);
1148 mkctrl(fe
, col1l
, col2r
, y
, y
+height
, "BUTTON",
1149 BS_NOTIFY
| BS_AUTOCHECKBOX
| WS_TABSTOP
,
1150 0, i
->name
, (j
->ctlid
= id
++));
1151 CheckDlgButton(fe
->cfgbox
, j
->ctlid
, (i
->ival
!= 0));
1157 * Drop-down list with a label beside it.
1159 mkctrl(fe
, col1l
, col1r
, y
+height
*1/8, y
+height
*9/8,
1160 "STATIC", 0, 0, i
->name
, id
++);
1161 ctl
= mkctrl(fe
, col2l
, col2r
, y
, y
+height
*41/2,
1162 "COMBOBOX", WS_TABSTOP
|
1163 CBS_DROPDOWNLIST
| CBS_HASSTRINGS
,
1164 WS_EX_CLIENTEDGE
, "", (j
->ctlid
= id
++));
1166 char c
, *p
, *q
, *str
;
1168 SendMessage(ctl
, CB_RESETCONTENT
, 0, 0);
1173 while (*q
&& *q
!= c
) q
++;
1174 str
= snewn(q
-p
+1, char);
1175 strncpy(str
, p
, q
-p
);
1177 SendMessage(ctl
, CB_ADDSTRING
, 0, (LPARAM
)str
);
1184 SendMessage(ctl
, CB_SETCURSEL
, i
->ival
, 0);
1190 assert(y
< winheight
);
1194 y
+= height
/2; /* extra space before OK and Cancel */
1195 mkctrl(fe
, col1l
, (col1l
+col2r
)/2-width
, y
, y
+height
*7/4, "BUTTON",
1196 BS_PUSHBUTTON
| BS_NOTIFY
| WS_TABSTOP
| BS_DEFPUSHBUTTON
, 0,
1198 mkctrl(fe
, (col1l
+col2r
)/2+width
, col2r
, y
, y
+height
*7/4, "BUTTON",
1199 BS_PUSHBUTTON
| BS_NOTIFY
| WS_TABSTOP
, 0, "Cancel", IDCANCEL
);
1201 SendMessage(fe
->cfgbox
, WM_INITDIALOG
, 0, 0);
1203 EnableWindow(fe
->hwnd
, FALSE
);
1204 ShowWindow(fe
->cfgbox
, SW_NORMAL
);
1205 while ((gm
=GetMessage(&msg
, NULL
, 0, 0)) > 0) {
1206 if (!IsDialogMessage(fe
->cfgbox
, &msg
))
1207 DispatchMessage(&msg
);
1211 EnableWindow(fe
->hwnd
, TRUE
);
1212 SetForegroundWindow(fe
->hwnd
);
1213 DestroyWindow(fe
->cfgbox
);
1214 DeleteObject(fe
->cfgfont
);
1219 return (fe
->dlg_done
== 2);
1222 static void new_game_size(frontend
*fe
)
1229 midend_size(fe
->me
, &x
, &y
, FALSE
);
1234 AdjustWindowRectEx(&r
, WS_OVERLAPPEDWINDOW
&~
1235 (WS_THICKFRAME
| WS_MAXIMIZEBOX
|
1239 if (fe
->statusbar
!= NULL
) {
1240 GetWindowRect(fe
->statusbar
, &sr
);
1242 sr
.left
= sr
.right
= sr
.top
= sr
.bottom
= 0;
1244 SetWindowPos(fe
->hwnd
, NULL
, 0, 0,
1246 r
.bottom
- r
.top
+ sr
.bottom
- sr
.top
,
1247 SWP_NOMOVE
| SWP_NOZORDER
);
1249 check_window_size(fe
, &x
, &y
);
1251 if (fe
->statusbar
!= NULL
)
1252 SetWindowPos(fe
->statusbar
, NULL
, 0, y
, x
,
1253 sr
.bottom
- sr
.top
, SWP_NOZORDER
);
1255 DeleteObject(fe
->bitmap
);
1257 hdc
= GetDC(fe
->hwnd
);
1258 fe
->bitmap
= CreateCompatibleBitmap(hdc
, x
, y
);
1259 ReleaseDC(fe
->hwnd
, hdc
);
1261 midend_redraw(fe
->me
);
1264 static void new_game_type(frontend
*fe
)
1266 midend_new_game(fe
->me
);
1270 static int is_alt_pressed(void)
1273 int r
= GetKeyboardState(keystate
);
1276 if (keystate
[VK_MENU
] & 0x80)
1278 if (keystate
[VK_RMENU
] & 0x80)
1283 static void savefile_write(void *wctx
, void *buf
, int len
)
1285 FILE *fp
= (FILE *)wctx
;
1286 fwrite(buf
, 1, len
, fp
);
1289 static int savefile_read(void *wctx
, void *buf
, int len
)
1291 FILE *fp
= (FILE *)wctx
;
1294 ret
= fread(buf
, 1, len
, fp
);
1295 return (ret
== len
);
1298 static LRESULT CALLBACK
WndProc(HWND hwnd
, UINT message
,
1299 WPARAM wParam
, LPARAM lParam
)
1301 frontend
*fe
= (frontend
*)GetWindowLong(hwnd
, GWL_USERDATA
);
1306 DestroyWindow(hwnd
);
1309 cmd
= wParam
& ~0xF; /* low 4 bits reserved to Windows */
1312 if (!midend_process_key(fe
->me
, 0, 0, 'n'))
1316 midend_restart_game(fe
->me
);
1319 if (!midend_process_key(fe
->me
, 0, 0, 'u'))
1323 if (!midend_process_key(fe
->me
, 0, 0, '\x12'))
1328 char *text
= midend_text_format(fe
->me
);
1330 write_clip(hwnd
, text
);
1332 MessageBeep(MB_ICONWARNING
);
1338 char *msg
= midend_solve(fe
->me
);
1340 MessageBox(hwnd
, msg
, "Unable to solve",
1341 MB_ICONERROR
| MB_OK
);
1345 if (!midend_process_key(fe
->me
, 0, 0, 'q'))
1349 if (get_config(fe
, CFG_SETTINGS
))
1353 if (get_config(fe
, CFG_SEED
))
1357 if (get_config(fe
, CFG_DESC
))
1367 char filename
[FILENAME_MAX
];
1370 memset(&of
, 0, sizeof(of
));
1371 of
.hwndOwner
= hwnd
;
1372 of
.lpstrFilter
= "All Files (*.*)\0*\0\0\0";
1373 of
.lpstrCustomFilter
= NULL
;
1374 of
.nFilterIndex
= 1;
1375 of
.lpstrFile
= filename
;
1377 of
.nMaxFile
= lenof(filename
);
1378 of
.lpstrFileTitle
= NULL
;
1379 of
.lpstrTitle
= (cmd
== IDM_SAVE ?
1380 "Enter name of game file to save" :
1381 "Enter name of saved game file to load");
1383 #ifdef OPENFILENAME_SIZE_VERSION_400
1384 of
.lStructSize
= OPENFILENAME_SIZE_VERSION_400
;
1386 of
.lStructSize
= sizeof(of
);
1388 of
.lpstrInitialDir
= NULL
;
1390 if (cmd
== IDM_SAVE
)
1391 ret
= GetSaveFileName(&of
);
1393 ret
= GetOpenFileName(&of
);
1396 if (cmd
== IDM_SAVE
) {
1399 if ((fp
= fopen(filename
, "r")) != NULL
) {
1400 char buf
[256 + FILENAME_MAX
];
1404 sprintf(buf
, "Are you sure you want to overwrite"
1405 " the file \"%.*s\"?",
1406 FILENAME_MAX
, filename
);
1407 if (MessageBox(hwnd
, buf
, "Question",
1408 MB_YESNO
| MB_ICONQUESTION
)
1413 fp
= fopen(filename
, "w");
1416 MessageBox(hwnd
, "Unable to open save file",
1417 "Error", MB_ICONERROR
| MB_OK
);
1421 midend_serialise(fe
->me
, savefile_write
, fp
);
1425 FILE *fp
= fopen(filename
, "r");
1429 MessageBox(hwnd
, "Unable to open saved game file",
1430 "Error", MB_ICONERROR
| MB_OK
);
1434 err
= midend_deserialise(fe
->me
, savefile_read
, fp
);
1439 MessageBox(hwnd
, err
, "Error", MB_ICONERROR
|MB_OK
);
1450 assert(fe
->help_path
);
1451 WinHelp(hwnd
, fe
->help_path
,
1452 fe
->help_has_contents ? HELP_FINDER
: HELP_CONTENTS
, 0);
1455 assert(fe
->help_path
);
1456 assert(thegame
.winhelp_topic
);
1458 char *cmd
= snewn(10+strlen(thegame
.winhelp_topic
), char);
1459 sprintf(cmd
, "JI(`',`%s')", thegame
.winhelp_topic
);
1460 WinHelp(hwnd
, fe
->help_path
, HELP_COMMAND
, (DWORD
)cmd
);
1466 int p
= ((wParam
&~ 0xF) - IDM_PRESETS
) / 0x10;
1468 if (p
>= 0 && p
< fe
->npresets
) {
1469 midend_set_params(fe
->me
, fe
->presets
[p
]);
1485 hdc
= BeginPaint(hwnd
, &p
);
1486 hdc2
= CreateCompatibleDC(hdc
);
1487 prevbm
= SelectObject(hdc2
, fe
->bitmap
);
1489 p
.rcPaint
.left
, p
.rcPaint
.top
,
1490 p
.rcPaint
.right
- p
.rcPaint
.left
,
1491 p
.rcPaint
.bottom
- p
.rcPaint
.top
,
1493 p
.rcPaint
.left
, p
.rcPaint
.top
,
1495 SelectObject(hdc2
, prevbm
);
1504 int r
= GetKeyboardState(keystate
);
1505 int shift
= (r
&& (keystate
[VK_SHIFT
] & 0x80)) ? MOD_SHFT
: 0;
1506 int ctrl
= (r
&& (keystate
[VK_CONTROL
] & 0x80)) ? MOD_CTRL
: 0;
1510 if (!(lParam
& 0x01000000))
1511 key
= MOD_NUM_KEYPAD
| '4';
1513 key
= shift
| ctrl
| CURSOR_LEFT
;
1516 if (!(lParam
& 0x01000000))
1517 key
= MOD_NUM_KEYPAD
| '6';
1519 key
= shift
| ctrl
| CURSOR_RIGHT
;
1522 if (!(lParam
& 0x01000000))
1523 key
= MOD_NUM_KEYPAD
| '8';
1525 key
= shift
| ctrl
| CURSOR_UP
;
1528 if (!(lParam
& 0x01000000))
1529 key
= MOD_NUM_KEYPAD
| '2';
1531 key
= shift
| ctrl
| CURSOR_DOWN
;
1534 * Diagonal keys on the numeric keypad.
1537 if (!(lParam
& 0x01000000)) key
= MOD_NUM_KEYPAD
| '9';
1540 if (!(lParam
& 0x01000000)) key
= MOD_NUM_KEYPAD
| '3';
1543 if (!(lParam
& 0x01000000)) key
= MOD_NUM_KEYPAD
| '7';
1546 if (!(lParam
& 0x01000000)) key
= MOD_NUM_KEYPAD
| '1';
1549 if (!(lParam
& 0x01000000)) key
= MOD_NUM_KEYPAD
| '0';
1552 if (!(lParam
& 0x01000000)) key
= MOD_NUM_KEYPAD
| '5';
1555 * Numeric keypad keys with Num Lock on.
1557 case VK_NUMPAD4
: key
= MOD_NUM_KEYPAD
| '4'; break;
1558 case VK_NUMPAD6
: key
= MOD_NUM_KEYPAD
| '6'; break;
1559 case VK_NUMPAD8
: key
= MOD_NUM_KEYPAD
| '8'; break;
1560 case VK_NUMPAD2
: key
= MOD_NUM_KEYPAD
| '2'; break;
1561 case VK_NUMPAD5
: key
= MOD_NUM_KEYPAD
| '5'; break;
1562 case VK_NUMPAD9
: key
= MOD_NUM_KEYPAD
| '9'; break;
1563 case VK_NUMPAD3
: key
= MOD_NUM_KEYPAD
| '3'; break;
1564 case VK_NUMPAD7
: key
= MOD_NUM_KEYPAD
| '7'; break;
1565 case VK_NUMPAD1
: key
= MOD_NUM_KEYPAD
| '1'; break;
1566 case VK_NUMPAD0
: key
= MOD_NUM_KEYPAD
| '0'; break;
1570 if (!midend_process_key(fe
->me
, 0, 0, key
))
1575 m
.message
= WM_KEYDOWN
;
1577 m
.lParam
= lParam
& 0xdfff;
1578 TranslateMessage(&m
);
1582 case WM_LBUTTONDOWN
:
1583 case WM_RBUTTONDOWN
:
1584 case WM_MBUTTONDOWN
:
1589 * Shift-clicks count as middle-clicks, since otherwise
1590 * two-button Windows users won't have any kind of
1591 * middle click to use.
1593 if (message
== WM_MBUTTONDOWN
|| (wParam
& MK_SHIFT
))
1594 button
= MIDDLE_BUTTON
;
1595 else if (message
== WM_RBUTTONDOWN
|| is_alt_pressed())
1596 button
= RIGHT_BUTTON
;
1598 button
= LEFT_BUTTON
;
1600 if (!midend_process_key(fe
->me
, (signed short)LOWORD(lParam
),
1601 (signed short)HIWORD(lParam
), button
))
1614 * Shift-clicks count as middle-clicks, since otherwise
1615 * two-button Windows users won't have any kind of
1616 * middle click to use.
1618 if (message
== WM_MBUTTONUP
|| (wParam
& MK_SHIFT
))
1619 button
= MIDDLE_RELEASE
;
1620 else if (message
== WM_RBUTTONUP
|| is_alt_pressed())
1621 button
= RIGHT_RELEASE
;
1623 button
= LEFT_RELEASE
;
1625 if (!midend_process_key(fe
->me
, (signed short)LOWORD(lParam
),
1626 (signed short)HIWORD(lParam
), button
))
1636 if (wParam
& (MK_MBUTTON
| MK_SHIFT
))
1637 button
= MIDDLE_DRAG
;
1638 else if (wParam
& MK_RBUTTON
|| is_alt_pressed())
1639 button
= RIGHT_DRAG
;
1643 if (!midend_process_key(fe
->me
, (signed short)LOWORD(lParam
),
1644 (signed short)HIWORD(lParam
), button
))
1649 if (!midend_process_key(fe
->me
, 0, 0, (unsigned char)wParam
))
1654 DWORD now
= GetTickCount();
1655 float elapsed
= (float) (now
- fe
->timer_last_tickcount
) * 0.001F
;
1656 midend_timer(fe
->me
, elapsed
);
1657 fe
->timer_last_tickcount
= now
;
1662 return DefWindowProc(hwnd
, message
, wParam
, lParam
);
1665 int WINAPI
WinMain(HINSTANCE inst
, HINSTANCE prev
, LPSTR cmdline
, int show
)
1670 InitCommonControls();
1676 wndclass
.lpfnWndProc
= WndProc
;
1677 wndclass
.cbClsExtra
= 0;
1678 wndclass
.cbWndExtra
= 0;
1679 wndclass
.hInstance
= inst
;
1680 wndclass
.hIcon
= LoadIcon(inst
, IDI_APPLICATION
);
1681 wndclass
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
1682 wndclass
.hbrBackground
= NULL
;
1683 wndclass
.lpszMenuName
= NULL
;
1684 wndclass
.lpszClassName
= thegame
.name
;
1686 RegisterClass(&wndclass
);
1689 while (*cmdline
&& isspace(*cmdline
))
1692 if (!new_window(inst
, *cmdline ? cmdline
: NULL
, &error
)) {
1694 sprintf(buf
, "%.100s Error", thegame
.name
);
1695 MessageBox(NULL
, error
, buf
, MB_OK
|MB_ICONERROR
);
1699 while (GetMessage(&msg
, NULL
, 0, 0)) {
1700 DispatchMessage(&msg
);