2 * windows.c: Windows front end for my puzzle collection.
9 #endif /* NO_HTMLHELP */
30 #define IDM_NEW 0x0010
31 #define IDM_RESTART 0x0020
32 #define IDM_UNDO 0x0030
33 #define IDM_REDO 0x0040
34 #define IDM_COPY 0x0050
35 #define IDM_SOLVE 0x0060
36 #define IDM_QUIT 0x0070
37 #define IDM_CONFIG 0x0080
38 #define IDM_DESC 0x0090
39 #define IDM_SEED 0x00A0
40 #define IDM_HELPC 0x00B0
41 #define IDM_GAMEHELP 0x00C0
42 #define IDM_ABOUT 0x00D0
43 #define IDM_SAVE 0x00E0
44 #define IDM_LOAD 0x00F0
45 #define IDM_PRINT 0x0100
46 #define IDM_PRESETS 0x0110
47 #define IDM_GAMES 0x0300
49 #define IDM_KEYEMUL 0x0400
51 #define HELP_FILE_NAME "puzzles.hlp"
52 #define HELP_CNT_NAME "puzzles.cnt"
54 #define CHM_FILE_NAME "puzzles.chm"
55 #endif /* NO_HTMLHELP */
58 typedef HWND (CALLBACK
*htmlhelp_t
)(HWND
, LPCSTR
, UINT
, DWORD
);
59 static htmlhelp_t htmlhelp
;
60 static HINSTANCE hh_dll
;
61 #endif /* NO_HTMLHELP */
62 enum { NONE
, HLP
, CHM
} help_type
;
64 int help_has_contents
;
67 #define FILENAME_MAX (260)
71 #define HGDI_ERROR ((HANDLE)GDI_ERROR)
75 #define CLASSNAME "Puzzles"
77 #define CLASSNAME thegame.name
83 * Wrapper implementations of functions not supplied by the
87 #define SHGetSubMenu(hWndMB,ID_MENU) (HMENU)SendMessage((hWndMB), SHCMBM_GETSUBMENU, (WPARAM)0, (LPARAM)ID_MENU)
91 int MessageBox(HWND hWnd
, LPCSTR lpText
, LPCSTR lpCaption
, UINT uType
)
96 MultiByteToWideChar (CP_ACP
, 0, lpText
, -1, wText
, 2048);
97 MultiByteToWideChar (CP_ACP
, 0, lpCaption
, -1, wCaption
, 2048);
99 return MessageBoxW (hWnd
, wText
, wCaption
, uType
);
102 BOOL
SetDlgItemTextA(HWND hDlg
, int nIDDlgItem
, LPCSTR lpString
)
106 MultiByteToWideChar (CP_ACP
, 0, lpString
, -1, wText
, 256);
107 return SetDlgItemTextW(hDlg
, nIDDlgItem
, wText
);
110 LPCSTR
getenv(LPCSTR buf
)
115 BOOL
GetKeyboardState(PBYTE pb
)
120 static TCHAR wClassName
[256], wGameName
[256];
125 static FILE *debug_fp
= NULL
;
126 static HANDLE debug_hdl
= INVALID_HANDLE_VALUE
;
127 static int debug_got_console
= 0;
129 void dputs(char *buf
)
133 if (!debug_got_console) {
134 if (AllocConsole()) {
135 debug_got_console = 1;
136 debug_hdl = GetStdHandle(STD_OUTPUT_HANDLE);
140 debug_fp = fopen("debug.log", "w");
143 if (debug_hdl != INVALID_HANDLE_VALUE) {
144 WriteFile(debug_hdl, buf, strlen(buf), &dw, NULL);
147 fputs(buf, debug_fp);
150 OutputDebugString(buf
);
153 void debug_printf(char *fmt
, ...)
159 _vsnprintf(buf
, 4095, fmt
, ap
);
166 #define WINFLAGS (WS_OVERLAPPEDWINDOW &~ \
167 (WS_MAXIMIZEBOX | WS_OVERLAPPED))
169 #define WINFLAGS (WS_CAPTION | WS_SYSMENU)
172 static void new_game_size(frontend
*fe
, float scale
);
190 enum { CFG_PRINT
= CFG_FRONTEND_SPECIFIC
};
195 HWND hwnd
, statusbar
, cfgbox
;
197 HWND numpad
; /* window handle for the numeric pad */
200 HBITMAP bitmap
, prevbm
;
201 RECT bitmapPosition
; /* game bitmap position within game window */
207 HMENU gamemenu
, typemenu
;
209 DWORD timer_last_tickcount
;
211 game_params
**presets
;
213 int nfonts
, fontsize
;
215 struct cfg_aux
*cfgaux
;
216 int cfg_which
, dlg_done
;
221 enum { DRAWING
, PRINTING
, NOTHING
} drawstatus
;
223 int printcount
, printw
, printh
, printsolns
, printcurr
, printcolour
;
225 int printoffsetx
, printoffsety
;
226 float printpixelscale
;
234 void frontend_free(frontend
*fe
)
246 static void update_type_menu_tick(frontend
*fe
);
247 static void update_copy_menu_greying(frontend
*fe
);
249 void fatal(char *fmt
, ...)
255 vsprintf(buf
, fmt
, ap
);
258 MessageBox(NULL
, buf
, "Fatal error", MB_ICONEXCLAMATION
| MB_OK
);
263 char *geterrstr(void)
266 DWORD dw
= GetLastError();
270 FORMAT_MESSAGE_ALLOCATE_BUFFER
|
271 FORMAT_MESSAGE_FROM_SYSTEM
,
274 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
278 ret
= dupstr(lpMsgBuf
);
285 void get_random_seed(void **randseed
, int *randseedsize
)
287 SYSTEMTIME
*st
= snew(SYSTEMTIME
);
291 *randseed
= (void *)st
;
292 *randseedsize
= sizeof(SYSTEMTIME
);
295 static void win_status_bar(void *handle
, char *text
)
300 frontend
*fe
= (frontend
*)handle
;
303 MultiByteToWideChar (CP_ACP
, 0, text
, -1, wText
, 255);
304 SendMessage(fe
->statusbar
, SB_SETTEXT
,
305 (WPARAM
) 255 | SBT_NOBORDERS
,
308 SetWindowText(fe
->statusbar
, text
);
312 static blitter
*win_blitter_new(void *handle
, int w
, int h
)
314 blitter
*bl
= snew(blitter
);
316 memset(bl
, 0, sizeof(blitter
));
324 static void win_blitter_free(void *handle
, blitter
*bl
)
326 if (bl
->bitmap
) DeleteObject(bl
->bitmap
);
330 static void blitter_mkbitmap(frontend
*fe
, blitter
*bl
)
332 HDC hdc
= GetDC(fe
->hwnd
);
333 bl
->bitmap
= CreateCompatibleBitmap(hdc
, bl
->w
, bl
->h
);
334 ReleaseDC(fe
->hwnd
, hdc
);
337 /* BitBlt(dstDC, dstX, dstY, dstW, dstH, srcDC, srcX, srcY, dType) */
339 static void win_blitter_save(void *handle
, blitter
*bl
, int x
, int y
)
341 frontend
*fe
= (frontend
*)handle
;
342 HDC hdc_win
, hdc_blit
;
345 assert(fe
->drawstatus
== DRAWING
);
347 if (!bl
->bitmap
) blitter_mkbitmap(fe
, bl
);
349 bl
->x
= x
; bl
->y
= y
;
351 hdc_win
= GetDC(fe
->hwnd
);
352 hdc_blit
= CreateCompatibleDC(hdc_win
);
353 if (!hdc_blit
) fatal("hdc_blit failed: 0x%x", GetLastError());
355 prev_blit
= SelectObject(hdc_blit
, bl
->bitmap
);
356 if (prev_blit
== NULL
|| prev_blit
== HGDI_ERROR
)
357 fatal("SelectObject for hdc_main failed: 0x%x", GetLastError());
359 if (!BitBlt(hdc_blit
, 0, 0, bl
->w
, bl
->h
,
360 fe
->hdc
, x
, y
, SRCCOPY
))
361 fatal("BitBlt failed: 0x%x", GetLastError());
363 SelectObject(hdc_blit
, prev_blit
);
365 ReleaseDC(fe
->hwnd
, hdc_win
);
368 static void win_blitter_load(void *handle
, blitter
*bl
, int x
, int y
)
370 frontend
*fe
= (frontend
*)handle
;
371 HDC hdc_win
, hdc_blit
;
374 assert(fe
->drawstatus
== DRAWING
);
376 assert(bl
->bitmap
); /* we should always have saved before loading */
378 if (x
== BLITTER_FROMSAVED
) x
= bl
->x
;
379 if (y
== BLITTER_FROMSAVED
) y
= bl
->y
;
381 hdc_win
= GetDC(fe
->hwnd
);
382 hdc_blit
= CreateCompatibleDC(hdc_win
);
384 prev_blit
= SelectObject(hdc_blit
, bl
->bitmap
);
386 BitBlt(fe
->hdc
, x
, y
, bl
->w
, bl
->h
,
387 hdc_blit
, 0, 0, SRCCOPY
);
389 SelectObject(hdc_blit
, prev_blit
);
391 ReleaseDC(fe
->hwnd
, hdc_win
);
394 void frontend_default_colour(frontend
*fe
, float *output
)
396 DWORD c
= GetSysColor(COLOR_MENU
); /* ick */
398 output
[0] = (float)(GetRValue(c
) / 255.0);
399 output
[1] = (float)(GetGValue(c
) / 255.0);
400 output
[2] = (float)(GetBValue(c
) / 255.0);
403 static POINT
win_transform_point(frontend
*fe
, int x
, int y
)
407 assert(fe
->drawstatus
!= NOTHING
);
409 if (fe
->drawstatus
== PRINTING
) {
410 ret
.x
= (int)(fe
->printoffsetx
+ fe
->printpixelscale
* x
);
411 ret
.y
= (int)(fe
->printoffsety
+ fe
->printpixelscale
* y
);
420 static void win_text_colour(frontend
*fe
, int colour
)
422 assert(fe
->drawstatus
!= NOTHING
);
424 if (fe
->drawstatus
== PRINTING
) {
427 print_get_colour(fe
->dr
, colour
, fe
->printcolour
, &hatch
, &r
, &g
, &b
);
430 * Displaying text in hatched colours is not permitted.
434 SetTextColor(fe
->hdc
, RGB(r
* 255, g
* 255, b
* 255));
436 SetTextColor(fe
->hdc
, fe
->colours
[colour
]);
440 static void win_set_brush(frontend
*fe
, int colour
)
443 assert(fe
->drawstatus
!= NOTHING
);
445 if (fe
->drawstatus
== PRINTING
) {
448 print_get_colour(fe
->dr
, colour
, fe
->printcolour
, &hatch
, &r
, &g
, &b
);
451 br
= CreateSolidBrush(RGB(r
* 255, g
* 255, b
* 255));
455 * This is only ever required during printing, and the
456 * PocketPC port doesn't support printing.
458 fatal("CreateHatchBrush not supported");
460 br
= CreateHatchBrush(hatch
== HATCH_BACKSLASH
? HS_FDIAGONAL
:
461 hatch
== HATCH_SLASH
? HS_BDIAGONAL
:
462 hatch
== HATCH_HORIZ
? HS_HORIZONTAL
:
463 hatch
== HATCH_VERT
? HS_VERTICAL
:
464 hatch
== HATCH_PLUS
? HS_CROSS
:
465 /* hatch == HATCH_X ? */ HS_DIAGCROSS
,
470 br
= fe
->brushes
[colour
];
472 fe
->oldbr
= SelectObject(fe
->hdc
, br
);
475 static void win_reset_brush(frontend
*fe
)
479 assert(fe
->drawstatus
!= NOTHING
);
481 br
= SelectObject(fe
->hdc
, fe
->oldbr
);
482 if (fe
->drawstatus
== PRINTING
)
486 static void win_set_pen(frontend
*fe
, int colour
, int thin
)
489 assert(fe
->drawstatus
!= NOTHING
);
491 if (fe
->drawstatus
== PRINTING
) {
494 int width
= thin
? 0 : fe
->linewidth
;
496 print_get_colour(fe
->dr
, colour
, fe
->printcolour
, &hatch
, &r
, &g
, &b
);
498 * Stroking in hatched colours is not permitted.
501 pen
= CreatePen(PS_SOLID
, width
, RGB(r
* 255, g
* 255, b
* 255));
503 pen
= fe
->pens
[colour
];
505 fe
->oldpen
= SelectObject(fe
->hdc
, pen
);
508 static void win_reset_pen(frontend
*fe
)
512 assert(fe
->drawstatus
!= NOTHING
);
514 pen
= SelectObject(fe
->hdc
, fe
->oldpen
);
515 if (fe
->drawstatus
== PRINTING
)
519 static void win_clip(void *handle
, int x
, int y
, int w
, int h
)
521 frontend
*fe
= (frontend
*)handle
;
524 if (fe
->drawstatus
== NOTHING
)
527 p
= win_transform_point(fe
, x
, y
);
528 q
= win_transform_point(fe
, x
+w
, y
+h
);
529 IntersectClipRect(fe
->hdc
, p
.x
, p
.y
, q
.x
, q
.y
);
532 static void win_unclip(void *handle
)
534 frontend
*fe
= (frontend
*)handle
;
536 if (fe
->drawstatus
== NOTHING
)
539 SelectClipRgn(fe
->hdc
, NULL
);
542 static void win_draw_text(void *handle
, int x
, int y
, int fonttype
,
543 int fontsize
, int align
, int colour
, char *text
)
545 frontend
*fe
= (frontend
*)handle
;
550 if (fe
->drawstatus
== NOTHING
)
553 if (fe
->drawstatus
== PRINTING
)
554 fontsize
= (int)(fontsize
* fe
->printpixelscale
);
556 xy
= win_transform_point(fe
, x
, y
);
559 * Find or create the font.
561 for (i
= fe
->fontstart
; i
< fe
->nfonts
; i
++)
562 if (fe
->fonts
[i
].type
== fonttype
&& fe
->fonts
[i
].size
== fontsize
)
565 if (i
== fe
->nfonts
) {
566 if (fe
->fontsize
<= fe
->nfonts
) {
567 fe
->fontsize
= fe
->nfonts
+ 10;
568 fe
->fonts
= sresize(fe
->fonts
, fe
->fontsize
, struct font
);
573 fe
->fonts
[i
].type
= fonttype
;
574 fe
->fonts
[i
].size
= fontsize
;
576 memset (&lf
, 0, sizeof(LOGFONT
));
577 lf
.lfHeight
= -fontsize
;
578 lf
.lfWeight
= (fe
->drawstatus
== PRINTING
? 0 : FW_BOLD
);
579 lf
.lfCharSet
= DEFAULT_CHARSET
;
580 lf
.lfOutPrecision
= OUT_DEFAULT_PRECIS
;
581 lf
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
582 lf
.lfQuality
= DEFAULT_QUALITY
;
583 lf
.lfPitchAndFamily
= (fonttype
== FONT_FIXED
?
584 FIXED_PITCH
| FF_DONTCARE
:
585 VARIABLE_PITCH
| FF_SWISS
);
587 wcscpy(lf
.lfFaceName
, TEXT("Tahoma"));
590 fe
->fonts
[i
].font
= CreateFontIndirect(&lf
);
594 * Position and draw the text.
602 MultiByteToWideChar (CP_ACP
, 0, text
, -1, wText
, 256);
605 oldfont
= SelectObject(fe
->hdc
, fe
->fonts
[i
].font
);
606 if (GetTextMetrics(fe
->hdc
, &tm
)) {
607 if (align
& ALIGN_VCENTRE
)
608 xy
.y
-= (tm
.tmAscent
+tm
.tmDescent
)/2;
613 if (GetTextExtentPoint32(fe
->hdc
, text
, strlen(text
), &size
))
615 if (GetTextExtentPoint32(fe
->hdc
, wText
, wcslen(wText
), &size
))
618 if (align
& ALIGN_HCENTRE
)
620 else if (align
& ALIGN_HRIGHT
)
623 SetBkMode(fe
->hdc
, TRANSPARENT
);
624 win_text_colour(fe
, colour
);
626 TextOut(fe
->hdc
, xy
.x
, xy
.y
, text
, strlen(text
));
628 ExtTextOut(fe
->hdc
, xy
.x
, xy
.y
, 0, NULL
, wText
, wcslen(wText
), NULL
);
630 SelectObject(fe
->hdc
, oldfont
);
634 static void win_draw_rect(void *handle
, int x
, int y
, int w
, int h
, int colour
)
636 frontend
*fe
= (frontend
*)handle
;
639 if (fe
->drawstatus
== NOTHING
)
642 if (fe
->drawstatus
== DRAWING
&& w
== 1 && h
== 1) {
644 * Rectangle() appears to get uppity if asked to draw a 1x1
645 * rectangle, presumably on the grounds that that's beneath
646 * its dignity and you ought to be using SetPixel instead.
649 SetPixel(fe
->hdc
, x
, y
, fe
->colours
[colour
]);
651 win_set_brush(fe
, colour
);
652 win_set_pen(fe
, colour
, TRUE
);
653 p
= win_transform_point(fe
, x
, y
);
654 q
= win_transform_point(fe
, x
+w
, y
+h
);
655 Rectangle(fe
->hdc
, p
.x
, p
.y
, q
.x
, q
.y
);
661 static void win_draw_line(void *handle
, int x1
, int y1
, int x2
, int y2
, int colour
)
663 frontend
*fe
= (frontend
*)handle
;
666 if (fe
->drawstatus
== NOTHING
)
669 win_set_pen(fe
, colour
, FALSE
);
670 pp
[0] = win_transform_point(fe
, x1
, y1
);
671 pp
[1] = win_transform_point(fe
, x2
, y2
);
672 Polyline(fe
->hdc
, pp
, 2);
673 if (fe
->drawstatus
== DRAWING
)
674 SetPixel(fe
->hdc
, pp
[1].x
, pp
[1].y
, fe
->colours
[colour
]);
678 static void win_draw_circle(void *handle
, int cx
, int cy
, int radius
,
679 int fillcolour
, int outlinecolour
)
681 frontend
*fe
= (frontend
*)handle
;
684 assert(outlinecolour
>= 0);
686 if (fe
->drawstatus
== NOTHING
)
690 win_set_brush(fe
, fillcolour
);
692 fe
->oldbr
= SelectObject(fe
->hdc
, GetStockObject(NULL_BRUSH
));
694 win_set_pen(fe
, outlinecolour
, FALSE
);
695 p
= win_transform_point(fe
, cx
- radius
, cy
- radius
);
696 q
= win_transform_point(fe
, cx
+ radius
, cy
+ radius
);
697 Ellipse(fe
->hdc
, p
.x
, p
.y
, q
.x
+1, q
.y
+1);
702 static void win_draw_polygon(void *handle
, int *coords
, int npoints
,
703 int fillcolour
, int outlinecolour
)
705 frontend
*fe
= (frontend
*)handle
;
709 if (fe
->drawstatus
== NOTHING
)
712 pts
= snewn(npoints
+1, POINT
);
714 for (i
= 0; i
<= npoints
; i
++) {
715 int j
= (i
< npoints
? i
: 0);
716 pts
[i
] = win_transform_point(fe
, coords
[j
*2], coords
[j
*2+1]);
719 assert(outlinecolour
>= 0);
721 if (fillcolour
>= 0) {
722 win_set_brush(fe
, fillcolour
);
723 win_set_pen(fe
, outlinecolour
, FALSE
);
724 Polygon(fe
->hdc
, pts
, npoints
);
728 win_set_pen(fe
, outlinecolour
, FALSE
);
729 Polyline(fe
->hdc
, pts
, npoints
+1);
736 static void win_start_draw(void *handle
)
738 frontend
*fe
= (frontend
*)handle
;
741 assert(fe
->drawstatus
== NOTHING
);
743 hdc_win
= GetDC(fe
->hwnd
);
744 fe
->hdc
= CreateCompatibleDC(hdc_win
);
745 fe
->prevbm
= SelectObject(fe
->hdc
, fe
->bitmap
);
746 ReleaseDC(fe
->hwnd
, hdc_win
);
749 SetMapMode(fe
->hdc
, MM_TEXT
);
751 fe
->drawstatus
= DRAWING
;
754 static void win_draw_update(void *handle
, int x
, int y
, int w
, int h
)
756 frontend
*fe
= (frontend
*)handle
;
759 if (fe
->drawstatus
!= DRAWING
)
767 OffsetRect(&r
, fe
->bitmapPosition
.left
, fe
->bitmapPosition
.top
);
768 InvalidateRect(fe
->hwnd
, &r
, FALSE
);
771 static void win_end_draw(void *handle
)
773 frontend
*fe
= (frontend
*)handle
;
774 assert(fe
->drawstatus
== DRAWING
);
775 SelectObject(fe
->hdc
, fe
->prevbm
);
778 DeleteObject(fe
->clip
);
781 fe
->drawstatus
= NOTHING
;
784 static void win_line_width(void *handle
, float width
)
786 frontend
*fe
= (frontend
*)handle
;
788 assert(fe
->drawstatus
!= DRAWING
);
789 if (fe
->drawstatus
== NOTHING
)
792 fe
->linewidth
= (int)(width
* fe
->printpixelscale
);
795 static void win_begin_doc(void *handle
, int pages
)
797 frontend
*fe
= (frontend
*)handle
;
799 assert(fe
->drawstatus
!= DRAWING
);
800 if (fe
->drawstatus
== NOTHING
)
803 if (StartDoc(fe
->hdc
, &fe
->di
) <= 0) {
804 char *e
= geterrstr();
805 MessageBox(fe
->hwnd
, e
, "Error starting to print",
806 MB_ICONERROR
| MB_OK
);
808 fe
->drawstatus
= NOTHING
;
812 * Push a marker on the font stack so that we won't use the
813 * same fonts for printing and drawing. (This is because
814 * drawing seems to look generally better in bold, but printing
815 * is better not in bold.)
817 fe
->fontstart
= fe
->nfonts
;
820 static void win_begin_page(void *handle
, int number
)
822 frontend
*fe
= (frontend
*)handle
;
824 assert(fe
->drawstatus
!= DRAWING
);
825 if (fe
->drawstatus
== NOTHING
)
828 if (StartPage(fe
->hdc
) <= 0) {
829 char *e
= geterrstr();
830 MessageBox(fe
->hwnd
, e
, "Error starting a page",
831 MB_ICONERROR
| MB_OK
);
833 fe
->drawstatus
= NOTHING
;
837 static void win_begin_puzzle(void *handle
, float xm
, float xc
,
838 float ym
, float yc
, int pw
, int ph
, float wmm
)
840 frontend
*fe
= (frontend
*)handle
;
841 int ppw
, pph
, pox
, poy
;
842 float mmpw
, mmph
, mmox
, mmoy
;
845 assert(fe
->drawstatus
!= DRAWING
);
846 if (fe
->drawstatus
== NOTHING
)
849 ppw
= GetDeviceCaps(fe
->hdc
, HORZRES
);
850 pph
= GetDeviceCaps(fe
->hdc
, VERTRES
);
851 mmpw
= (float)GetDeviceCaps(fe
->hdc
, HORZSIZE
);
852 mmph
= (float)GetDeviceCaps(fe
->hdc
, VERTSIZE
);
855 * Compute the puzzle's position on the logical page.
857 mmox
= xm
* mmpw
+ xc
;
858 mmoy
= ym
* mmph
+ yc
;
861 * Work out what that comes to in pixels.
863 pox
= (int)(mmox
* (float)ppw
/ mmpw
);
864 poy
= (int)(mmoy
* (float)pph
/ mmph
);
867 * And determine the scale.
869 * I need a scale such that the maximum puzzle-coordinate
870 * extent of the rectangle (pw * scale) is equal to the pixel
871 * equivalent of the puzzle's millimetre width (wmm * ppw /
874 scale
= (wmm
* ppw
) / (mmpw
* pw
);
877 * Now store pox, poy and scale for use in the main drawing
880 fe
->printoffsetx
= pox
;
881 fe
->printoffsety
= poy
;
882 fe
->printpixelscale
= scale
;
887 static void win_end_puzzle(void *handle
)
889 /* Nothing needs to be done here. */
892 static void win_end_page(void *handle
, int number
)
894 frontend
*fe
= (frontend
*)handle
;
896 assert(fe
->drawstatus
!= DRAWING
);
898 if (fe
->drawstatus
== NOTHING
)
901 if (EndPage(fe
->hdc
) <= 0) {
902 char *e
= geterrstr();
903 MessageBox(fe
->hwnd
, e
, "Error finishing a page",
904 MB_ICONERROR
| MB_OK
);
906 fe
->drawstatus
= NOTHING
;
910 static void win_end_doc(void *handle
)
912 frontend
*fe
= (frontend
*)handle
;
914 assert(fe
->drawstatus
!= DRAWING
);
917 * Free all the fonts created since we began printing.
919 while (fe
->nfonts
> fe
->fontstart
) {
921 DeleteObject(fe
->fonts
[fe
->nfonts
].font
);
926 * The MSDN web site sample code doesn't bother to call EndDoc
927 * if an error occurs half way through printing. I expect doing
928 * so would cause the erroneous document to actually be
929 * printed, or something equally undesirable.
931 if (fe
->drawstatus
== NOTHING
)
934 if (EndDoc(fe
->hdc
) <= 0) {
935 char *e
= geterrstr();
936 MessageBox(fe
->hwnd
, e
, "Error finishing printing",
937 MB_ICONERROR
| MB_OK
);
939 fe
->drawstatus
= NOTHING
;
943 const struct drawing_api win_drawing
= {
968 void print(frontend
*fe
)
974 midend
*nme
= NULL
; /* non-interactive midend for bulk puzzle generation */
979 * Create our document structure and fill it up with puzzles.
981 doc
= document_new(fe
->printw
, fe
->printh
, fe
->printscale
/ 100.0F
);
982 for (i
= 0; i
< fe
->printcount
; i
++) {
983 if (i
== 0 && fe
->printcurr
) {
984 err
= midend_print_puzzle(fe
->me
, doc
, fe
->printsolns
);
989 nme
= midend_new(NULL
, fe
->game
, NULL
, NULL
);
992 * Set the non-interactive mid-end to have the same
993 * parameters as the standard one.
995 params
= midend_get_params(fe
->me
);
996 midend_set_params(nme
, params
);
997 fe
->game
->free_params(params
);
1000 midend_new_game(nme
);
1001 err
= midend_print_puzzle(nme
, doc
, fe
->printsolns
);
1010 MessageBox(fe
->hwnd
, err
, "Error preparing puzzles for printing",
1011 MB_ICONERROR
| MB_OK
);
1016 memset(&pd
, 0, sizeof(pd
));
1017 pd
.lStructSize
= sizeof(pd
);
1018 pd
.hwndOwner
= fe
->hwnd
;
1020 pd
.hDevNames
= NULL
;
1021 pd
.Flags
= PD_USEDEVMODECOPIESANDCOLLATE
| PD_RETURNDC
|
1022 PD_NOPAGENUMS
| PD_NOSELECTION
;
1024 pd
.nFromPage
= pd
.nToPage
= 0xFFFF;
1025 pd
.nMinPage
= pd
.nMaxPage
= 1;
1027 if (!PrintDlg(&pd
)) {
1033 * Now pd.hDC is a device context for the printer.
1037 * FIXME: IWBNI we put up an Abort box here.
1040 memset(&fe
->di
, 0, sizeof(fe
->di
));
1041 fe
->di
.cbSize
= sizeof(fe
->di
);
1042 sprintf(doctitle
, "Printed puzzles from %s (from Simon Tatham's"
1043 " Portable Puzzle Collection)", fe
->game
->name
);
1044 fe
->di
.lpszDocName
= doctitle
;
1045 fe
->di
.lpszOutput
= NULL
;
1046 fe
->di
.lpszDatatype
= NULL
;
1049 fe
->drawstatus
= PRINTING
;
1052 fe
->dr
= drawing_new(&win_drawing
, NULL
, fe
);
1053 document_print(doc
, fe
->dr
);
1054 drawing_free(fe
->dr
);
1057 fe
->drawstatus
= NOTHING
;
1064 void deactivate_timer(frontend
*fe
)
1067 return; /* for non-interactive midend */
1068 if (fe
->hwnd
) KillTimer(fe
->hwnd
, fe
->timer
);
1072 void activate_timer(frontend
*fe
)
1075 return; /* for non-interactive midend */
1077 fe
->timer
= SetTimer(fe
->hwnd
, 1, 20, NULL
);
1078 fe
->timer_last_tickcount
= GetTickCount();
1082 void write_clip(HWND hwnd
, char *data
)
1090 * Windows expects CRLF in the clipboard, so we must convert
1091 * any \n that has come out of the puzzle backend.
1094 for (i
= 0; data
[i
]; i
++) {
1095 if (data
[i
] == '\n')
1099 data2
= snewn(len
+1, char);
1101 for (i
= 0; data
[i
]; i
++) {
1102 if (data
[i
] == '\n')
1104 data2
[j
++] = data
[i
];
1109 clipdata
= GlobalAlloc(GMEM_DDESHARE
| GMEM_MOVEABLE
, len
+ 1);
1114 lock
= GlobalLock(clipdata
);
1116 GlobalFree(clipdata
);
1120 memcpy(lock
, data2
, len
);
1121 ((unsigned char *) lock
)[len
] = 0;
1122 GlobalUnlock(clipdata
);
1124 if (OpenClipboard(hwnd
)) {
1126 SetClipboardData(CF_TEXT
, clipdata
);
1129 GlobalFree(clipdata
);
1135 * Set up Help and see if we can find a help file.
1137 static void init_help(void)
1140 char b
[2048], *p
, *q
, *r
;
1144 * Find the executable file path, so we can look alongside
1145 * it for help files. Trim the filename off the end.
1147 GetModuleFileName(NULL
, b
, sizeof(b
) - 1);
1149 p
= strrchr(b
, '\\');
1150 if (p
&& p
>= r
) r
= p
+1;
1151 q
= strrchr(b
, ':');
1152 if (q
&& q
>= r
) r
= q
+1;
1156 * Try HTML Help first.
1158 strcpy(r
, CHM_FILE_NAME
);
1159 if ( (fp
= fopen(b
, "r")) != NULL
) {
1163 * We have a .CHM. See if we can use it.
1165 hh_dll
= LoadLibrary("hhctrl.ocx");
1167 htmlhelp
= (htmlhelp_t
)GetProcAddress(hh_dll
, "HtmlHelpA");
1169 FreeLibrary(hh_dll
);
1172 help_path
= dupstr(b
);
1177 #endif /* NO_HTMLHELP */
1180 * Now try old-style .HLP.
1182 strcpy(r
, HELP_FILE_NAME
);
1183 if ( (fp
= fopen(b
, "r")) != NULL
) {
1186 help_path
= dupstr(b
);
1190 * See if there's a .CNT file alongside it.
1192 strcpy(r
, HELP_CNT_NAME
);
1193 if ( (fp
= fopen(b
, "r")) != NULL
) {
1195 help_has_contents
= TRUE
;
1197 help_has_contents
= FALSE
;
1202 help_type
= NONE
; /* didn't find any */
1211 static void start_help(frontend
*fe
, const char *topic
)
1216 switch (help_type
) {
1220 str
= snewn(10+strlen(topic
), char);
1221 sprintf(str
, "JI(`',`%s')", topic
);
1223 } else if (help_has_contents
) {
1226 cmd
= HELP_CONTENTS
;
1228 WinHelp(fe
->hwnd
, help_path
, cmd
, (DWORD
)str
);
1229 fe
->help_running
= TRUE
;
1236 str
= snewn(20 + strlen(topic
) + strlen(help_path
), char);
1237 sprintf(str
, "%s::/%s.html>main", help_path
, topic
);
1239 str
= dupstr(help_path
);
1241 htmlhelp(fe
->hwnd
, str
, HH_DISPLAY_TOPIC
, 0);
1242 fe
->help_running
= TRUE
;
1244 #endif /* NO_HTMLHELP */
1246 assert(!"This shouldn't happen");
1254 * Stop Help on window cleanup.
1256 static void stop_help(frontend
*fe
)
1258 if (fe
->help_running
) {
1259 switch (help_type
) {
1261 WinHelp(fe
->hwnd
, help_path
, HELP_QUIT
, 0);
1266 htmlhelp(NULL
, NULL
, HH_CLOSE_ALL
, 0);
1268 #endif /* NO_HTMLHELP */
1270 assert(!"This shouldn't happen");
1273 fe
->help_running
= FALSE
;
1280 * Terminate Help on process exit.
1282 static void cleanup_help(void)
1284 /* Nothing to do currently.
1285 * (If we were running HTML Help single-threaded, this is where we'd
1286 * call HH_UNINITIALIZE.) */
1289 static int get_statusbar_height(frontend
*fe
)
1292 if (fe
->statusbar
) {
1294 GetWindowRect(fe
->statusbar
, &sr
);
1295 sy
= sr
.bottom
- sr
.top
;
1302 static void adjust_statusbar(frontend
*fe
, RECT
*r
)
1306 if (!fe
->statusbar
) return;
1308 sy
= get_statusbar_height(fe
);
1310 SetWindowPos(fe
->statusbar
, NULL
, 0, r
->bottom
-r
->top
-sy
, r
->right
-r
->left
,
1315 static void get_menu_size(HWND wh
, RECT
*r
)
1317 HMENU bar
= GetMenu(wh
);
1321 SetRect(r
, 0, 0, 0, 0);
1322 for (i
= 0; i
< GetMenuItemCount(bar
); i
++) {
1323 GetMenuItemRect(wh
, bar
, i
, &rect
);
1324 UnionRect(r
, r
, &rect
);
1329 * Given a proposed new puzzle size (cx,cy), work out the actual
1330 * puzzle size that would be (px,py) and the window size including
1331 * furniture (wx,wy).
1334 static int check_window_resize(frontend
*fe
, int cx
, int cy
,
1339 int x
, y
, sy
= get_statusbar_height(fe
), changed
= 0;
1341 /* disallow making window thinner than menu bar */
1342 x
= max(cx
, fe
->xmin
);
1343 y
= max(cy
- sy
, fe
->ymin
);
1346 * See if we actually got the window size we wanted, and adjust
1347 * the puzzle size if not.
1349 midend_size(fe
->me
, &x
, &y
, TRUE
);
1350 if (x
!= cx
|| y
!= cy
) {
1352 * Resize the window, now we know what size we _really_
1358 AdjustWindowRectEx(&r
, WINFLAGS
, TRUE
, 0);
1359 *wx
= r
.right
- r
.left
;
1360 *wy
= r
.bottom
- r
.top
;
1368 (float)midend_tilesize(fe
->me
) / (float)fe
->game
->preferred_tilesize
;
1374 * Given the current window size, make sure it's sane for the
1375 * current puzzle and resize if necessary.
1378 static void check_window_size(frontend
*fe
, int *px
, int *py
)
1383 GetClientRect(fe
->hwnd
, &r
);
1384 cx
= r
.right
- r
.left
;
1385 cy
= r
.bottom
- r
.top
;
1387 if (check_window_resize(fe
, cx
, cy
, px
, py
, &wx
, &wy
)) {
1389 SetWindowPos(fe
->hwnd
, NULL
, 0, 0, wx
, wy
,
1390 SWP_NOMOVE
| SWP_NOZORDER
);
1395 GetClientRect(fe
->hwnd
, &r
);
1396 adjust_statusbar(fe
, &r
);
1399 static void get_max_puzzle_size(frontend
*fe
, int *x
, int *y
)
1403 if (SystemParametersInfo(SPI_GETWORKAREA
, 0, &sr
, FALSE
)) {
1404 *x
= sr
.right
- sr
.left
;
1405 *y
= sr
.bottom
- sr
.top
;
1410 AdjustWindowRectEx(&r
, WINFLAGS
, TRUE
, 0);
1411 *x
-= r
.right
- r
.left
- 100;
1412 *y
-= r
.bottom
- r
.top
- 100;
1417 if (fe
->statusbar
!= NULL
) {
1418 GetWindowRect(fe
->statusbar
, &sr
);
1419 *y
-= sr
.bottom
- sr
.top
;
1424 /* Toolbar buttons on the numeric pad */
1425 static TBBUTTON tbNumpadButtons
[] =
1427 {0, IDM_KEYEMUL
+ '1', TBSTATE_ENABLED
, TBSTYLE_BUTTON
, 0, -1},
1428 {1, IDM_KEYEMUL
+ '2', TBSTATE_ENABLED
, TBSTYLE_BUTTON
, 0, -1},
1429 {2, IDM_KEYEMUL
+ '3', TBSTATE_ENABLED
, TBSTYLE_BUTTON
, 0, -1},
1430 {3, IDM_KEYEMUL
+ '4', TBSTATE_ENABLED
, TBSTYLE_BUTTON
, 0, -1},
1431 {4, IDM_KEYEMUL
+ '5', TBSTATE_ENABLED
, TBSTYLE_BUTTON
, 0, -1},
1432 {5, IDM_KEYEMUL
+ '6', TBSTATE_ENABLED
, TBSTYLE_BUTTON
, 0, -1},
1433 {6, IDM_KEYEMUL
+ '7', TBSTATE_ENABLED
, TBSTYLE_BUTTON
, 0, -1},
1434 {7, IDM_KEYEMUL
+ '8', TBSTATE_ENABLED
, TBSTYLE_BUTTON
, 0, -1},
1435 {8, IDM_KEYEMUL
+ '9', TBSTATE_ENABLED
, TBSTYLE_BUTTON
, 0, -1},
1436 {9, IDM_KEYEMUL
+ ' ', TBSTATE_ENABLED
, TBSTYLE_BUTTON
, 0, -1}
1441 * Allocate a new frontend structure and create its main window.
1443 static frontend
*frontend_new(HINSTANCE inst
)
1446 const char *nogame
= "Puzzles (no game selected)";
1448 fe
= snew(frontend
);
1458 fe
->help_running
= FALSE
;
1460 fe
->drawstatus
= NOTHING
;
1465 fe
->nfonts
= fe
->fontsize
= 0;
1471 fe
->puzz_scale
= 1.0;
1474 MultiByteToWideChar (CP_ACP
, 0, nogame
, -1, wGameName
, 256);
1475 fe
->hwnd
= CreateWindowEx(0, wClassName
, wGameName
,
1477 CW_USEDEFAULT
, CW_USEDEFAULT
,
1478 CW_USEDEFAULT
, CW_USEDEFAULT
,
1479 NULL
, NULL
, inst
, NULL
);
1483 RECT rc
, rcBar
, rcTB
, rcClient
;
1485 memset (&mbi
, 0, sizeof(SHMENUBARINFO
));
1486 mbi
.cbSize
= sizeof(SHMENUBARINFO
);
1487 mbi
.hwndParent
= fe
->hwnd
;
1488 mbi
.nToolBarId
= IDR_MENUBAR1
;
1489 mbi
.hInstRes
= inst
;
1491 SHCreateMenuBar(&mbi
);
1493 GetWindowRect(fe
->hwnd
, &rc
);
1494 GetWindowRect(mbi
.hwndMB
, &rcBar
);
1495 rc
.bottom
-= rcBar
.bottom
- rcBar
.top
;
1496 MoveWindow(fe
->hwnd
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, FALSE
);
1501 fe
->hwnd
= CreateWindowEx(0, CLASSNAME
, nogame
,
1502 WS_OVERLAPPEDWINDOW
&~
1504 CW_USEDEFAULT
, CW_USEDEFAULT
,
1505 CW_USEDEFAULT
, CW_USEDEFAULT
,
1506 NULL
, NULL
, inst
, NULL
);
1508 DWORD lerr
= GetLastError();
1509 printf("no window: 0x%x\n", lerr
);
1513 fe
->gamemenu
= NULL
;
1516 fe
->statusbar
= NULL
;
1519 SetWindowLong(fe
->hwnd
, GWL_USERDATA
, (LONG
)fe
);
1525 * Populate a frontend structure with a (new) game and midend structure, and
1526 * create any window furniture that it needs.
1528 * Previously-allocated memory and window furniture will be freed by this function.
1530 static int new_game(frontend
*fe
, const game
*game
, char *game_id
, char **error
)
1537 if (fe
->me
) midend_free(fe
->me
);
1538 fe
->me
= midend_new(fe
, fe
->game
, &win_drawing
, fe
);
1541 *error
= midend_game_id(fe
->me
, game_id
);
1543 midend_free(fe
->me
);
1549 midend_new_game(fe
->me
);
1555 colours
= midend_colours(fe
->me
, &ncolours
);
1557 if (fe
->colours
) sfree(fe
->colours
);
1558 if (fe
->brushes
) sfree(fe
->brushes
);
1559 if (fe
->pens
) sfree(fe
->pens
);
1561 fe
->colours
= snewn(ncolours
, COLORREF
);
1562 fe
->brushes
= snewn(ncolours
, HBRUSH
);
1563 fe
->pens
= snewn(ncolours
, HPEN
);
1565 for (i
= 0; i
< ncolours
; i
++) {
1566 fe
->colours
[i
] = RGB(255 * colours
[i
*3+0],
1567 255 * colours
[i
*3+1],
1568 255 * colours
[i
*3+2]);
1569 fe
->brushes
[i
] = CreateSolidBrush(fe
->colours
[i
]);
1570 fe
->pens
[i
] = CreatePen(PS_SOLID
, 1, fe
->colours
[i
]);
1576 DestroyWindow(fe
->statusbar
);
1577 if (midend_wants_statusbar(fe
->me
)) {
1578 fe
->statusbar
= CreateWindowEx(0, STATUSCLASSNAME
, TEXT("ooh"),
1579 WS_CHILD
| WS_VISIBLE
,
1580 0, 0, 0, 0, /* status bar does these */
1581 NULL
, NULL
, fe
->inst
, NULL
);
1583 fe
->statusbar
= NULL
;
1585 get_max_puzzle_size(fe
, &x
, &y
);
1586 midend_size(fe
->me
, &x
, &y
, FALSE
);
1591 AdjustWindowRectEx(&r
, WINFLAGS
, TRUE
, 0);
1595 DestroyWindow(fe
->numpad
);
1596 if (fe
->game
->flags
& REQUIRE_NUMPAD
)
1598 fe
->numpad
= CreateToolbarEx (fe
->hwnd
,
1599 WS_VISIBLE
| WS_CHILD
| CCS_NOPARENTALIGN
| TBSTYLE_FLAT
,
1600 0, 10, fe
->inst
, IDR_PADTOOLBAR
,
1601 tbNumpadButtons
, sizeof (tbNumpadButtons
) / sizeof (TBBUTTON
),
1602 0, 0, 14, 15, sizeof (TBBUTTON
));
1603 GetWindowRect(fe
->numpad
, &rcTB
);
1604 GetClientRect(fe
->hwnd
, &rcClient
);
1605 MoveWindow(fe
->numpad
,
1607 rcClient
.bottom
- (rcTB
.bottom
- rcTB
.top
) - 1,
1609 rcTB
.bottom
- rcTB
.top
,
1611 SendMessage(fe
->numpad
, TB_SETINDENT
, (rcClient
.right
- (10 * 21)) / 2, 0);
1616 MultiByteToWideChar (CP_ACP
, 0, fe
->game
->name
, -1, wGameName
, 256);
1617 SetWindowText(fe
->hwnd
, wGameName
);
1619 SetWindowText(fe
->hwnd
, fe
->game
->name
);
1623 DestroyWindow(fe
->statusbar
);
1624 if (midend_wants_statusbar(fe
->me
)) {
1626 fe
->statusbar
= CreateWindowEx(0, STATUSCLASSNAME
, TEXT("ooh"),
1627 WS_CHILD
| WS_VISIBLE
,
1628 0, 0, 0, 0, /* status bar does these */
1629 fe
->hwnd
, NULL
, fe
->inst
, NULL
);
1631 /* Flat status bar looks better on the Pocket PC */
1632 SendMessage(fe
->statusbar
, SB_SIMPLE
, (WPARAM
) TRUE
, 0);
1633 SendMessage(fe
->statusbar
, SB_SETTEXT
,
1634 (WPARAM
) 255 | SBT_NOBORDERS
,
1639 * Now resize the window to take account of the status bar.
1641 GetWindowRect(fe
->statusbar
, &sr
);
1642 GetWindowRect(fe
->hwnd
, &r
);
1644 SetWindowPos(fe
->hwnd
, NULL
, 0, 0, r
.right
- r
.left
,
1645 r
.bottom
- r
.top
+ sr
.bottom
- sr
.top
,
1646 SWP_NOMOVE
| SWP_NOZORDER
);
1649 fe
->statusbar
= NULL
;
1653 HMENU oldmenu
= GetMenu(fe
->hwnd
);
1656 HMENU bar
= CreateMenu();
1657 HMENU menu
= CreateMenu();
1660 AppendMenu(bar
, MF_ENABLED
|MF_POPUP
, (UINT
)menu
, "&Game");
1662 HMENU menu
= SHGetSubMenu(SHFindMenuBar(fe
->hwnd
), ID_GAME
);
1663 DeleteMenu(menu
, 0, MF_BYPOSITION
);
1665 fe
->gamemenu
= menu
;
1666 AppendMenu(menu
, MF_ENABLED
, IDM_NEW
, TEXT("&New"));
1667 AppendMenu(menu
, MF_ENABLED
, IDM_RESTART
, TEXT("&Restart"));
1669 /* ...here I run out of sensible accelerator characters. */
1670 AppendMenu(menu
, MF_ENABLED
, IDM_DESC
, TEXT("Speci&fic..."));
1671 AppendMenu(menu
, MF_ENABLED
, IDM_SEED
, TEXT("Rando&m Seed..."));
1676 if ((fe
->npresets
= midend_num_presets(fe
->me
)) > 0 ||
1677 fe
->game
->can_configure
) {
1680 HMENU sub
= CreateMenu();
1682 AppendMenu(bar
, MF_ENABLED
|MF_POPUP
, (UINT
)sub
, "&Type");
1684 HMENU sub
= SHGetSubMenu(SHFindMenuBar(fe
->hwnd
), ID_TYPE
);
1685 DeleteMenu(sub
, 0, MF_BYPOSITION
);
1687 fe
->presets
= snewn(fe
->npresets
, game_params
*);
1689 for (i
= 0; i
< fe
->npresets
; i
++) {
1695 midend_fetch_preset(fe
->me
, i
, &name
, &fe
->presets
[i
]);
1698 * FIXME: we ought to go through and do something
1699 * with ampersands here.
1703 AppendMenu(sub
, MF_ENABLED
, IDM_PRESETS
+ 0x10 * i
, name
);
1705 MultiByteToWideChar (CP_ACP
, 0, name
, -1, wName
, 255);
1706 AppendMenu(sub
, MF_ENABLED
, IDM_PRESETS
+ 0x10 * i
, wName
);
1709 if (fe
->game
->can_configure
) {
1710 AppendMenu(sub
, MF_ENABLED
, IDM_CONFIG
, TEXT("&Custom..."));
1715 fe
->typemenu
= INVALID_HANDLE_VALUE
;
1721 #error Windows CE does not support COMBINED build.
1724 HMENU games
= CreateMenu();
1727 AppendMenu(menu
, MF_SEPARATOR
, 0, 0);
1728 AppendMenu(menu
, MF_ENABLED
|MF_POPUP
, (UINT
)games
, "&Other");
1729 for (i
= 0; i
< gamecount
; i
++) {
1730 if (strcmp(gamelist
[i
]->name
, fe
->game
->name
) != 0) {
1731 /* only include those games that aren't the same as the
1732 * game we're currently playing. */
1733 AppendMenu(games
, MF_ENABLED
, IDM_GAMES
+ i
, gamelist
[i
]->name
);
1739 AppendMenu(menu
, MF_SEPARATOR
, 0, 0);
1741 AppendMenu(menu
, MF_ENABLED
, IDM_LOAD
, TEXT("&Load..."));
1742 AppendMenu(menu
, MF_ENABLED
, IDM_SAVE
, TEXT("&Save..."));
1743 AppendMenu(menu
, MF_SEPARATOR
, 0, 0);
1744 if (fe
->game
->can_print
) {
1745 AppendMenu(menu
, MF_ENABLED
, IDM_PRINT
, TEXT("&Print..."));
1746 AppendMenu(menu
, MF_SEPARATOR
, 0, 0);
1749 AppendMenu(menu
, MF_ENABLED
, IDM_UNDO
, TEXT("Undo"));
1750 AppendMenu(menu
, MF_ENABLED
, IDM_REDO
, TEXT("Redo"));
1752 if (fe
->game
->can_format_as_text_ever
) {
1753 AppendMenu(menu
, MF_SEPARATOR
, 0, 0);
1754 AppendMenu(menu
, MF_ENABLED
, IDM_COPY
, TEXT("&Copy"));
1757 if (fe
->game
->can_solve
) {
1758 AppendMenu(menu
, MF_SEPARATOR
, 0, 0);
1759 AppendMenu(menu
, MF_ENABLED
, IDM_SOLVE
, TEXT("Sol&ve"));
1761 AppendMenu(menu
, MF_SEPARATOR
, 0, 0);
1763 AppendMenu(menu
, MF_ENABLED
, IDM_QUIT
, TEXT("E&xit"));
1764 menu
= CreateMenu();
1765 AppendMenu(bar
, MF_ENABLED
|MF_POPUP
, (UINT
)menu
, TEXT("&Help"));
1767 AppendMenu(menu
, MF_ENABLED
, IDM_ABOUT
, TEXT("&About"));
1769 if (help_type
!= NONE
) {
1771 AppendMenu(menu
, MF_SEPARATOR
, 0, 0);
1772 AppendMenu(menu
, MF_ENABLED
, IDM_HELPC
, TEXT("&Contents"));
1773 assert(fe
->game
->name
);
1774 item
= snewn(10+strlen(fe
->game
->name
), char); /*ick*/
1775 sprintf(item
, "&Help on %s", fe
->game
->name
);
1776 AppendMenu(menu
, MF_ENABLED
, IDM_GAMEHELP
, item
);
1779 DestroyMenu(oldmenu
);
1780 SetMenu(fe
->hwnd
, bar
);
1781 get_menu_size(fe
->hwnd
, &menusize
);
1782 fe
->xmin
= (menusize
.right
- menusize
.left
) + 25;
1786 if (fe
->bitmap
) DeleteObject(fe
->bitmap
);
1788 new_game_size(fe
, fe
->puzz_scale
); /* initialises fe->bitmap */
1793 static void show_window(frontend
*fe
)
1795 ShowWindow(fe
->hwnd
, SW_SHOWNORMAL
);
1796 SetForegroundWindow(fe
->hwnd
);
1798 update_type_menu_tick(fe
);
1799 update_copy_menu_greying(fe
);
1801 midend_redraw(fe
->me
);
1805 static HFONT
dialog_title_font()
1807 static HFONT hf
= NULL
;
1813 memset (&lf
, 0, sizeof(LOGFONT
));
1814 lf
.lfHeight
= -11; /* - ((8 * GetDeviceCaps(hdc, LOGPIXELSY)) / 72) */
1815 lf
.lfWeight
= FW_BOLD
;
1816 wcscpy(lf
.lfFaceName
, TEXT("Tahoma"));
1818 return hf
= CreateFontIndirect(&lf
);
1821 static void make_dialog_full_screen(HWND hwnd
)
1823 SHINITDLGINFO shidi
;
1825 /* Make dialog full screen */
1826 shidi
.dwMask
= SHIDIM_FLAGS
;
1827 shidi
.dwFlags
= SHIDIF_DONEBUTTON
| SHIDIF_SIZEDLGFULLSCREEN
|
1830 SHInitDialog(&shidi
);
1834 static int CALLBACK
AboutDlgProc(HWND hwnd
, UINT msg
,
1835 WPARAM wParam
, LPARAM lParam
)
1837 frontend
*fe
= (frontend
*)GetWindowLong(hwnd
, GWL_USERDATA
);
1845 make_dialog_full_screen(hwnd
);
1847 sprintf(title
, "About %.250s", fe
->game
->name
);
1848 SetDlgItemTextA(hwnd
, IDC_ABOUT_CAPTION
, title
);
1850 SendDlgItemMessage(hwnd
, IDC_ABOUT_CAPTION
, WM_SETFONT
,
1851 (WPARAM
) dialog_title_font(), 0);
1853 SetDlgItemTextA(hwnd
, IDC_ABOUT_GAME
, fe
->game
->name
);
1854 SetDlgItemTextA(hwnd
, IDC_ABOUT_VERSION
, ver
);
1860 if (LOWORD(wParam
) == IDOK
)
1881 * Wrappers on midend_{get,set}_config, which extend the CFG_*
1882 * enumeration to add CFG_PRINT.
1884 static config_item
*frontend_get_config(frontend
*fe
, int which
,
1887 if (which
< CFG_FRONTEND_SPECIFIC
) {
1888 return midend_get_config(fe
->me
, which
, wintitle
);
1889 } else if (which
== CFG_PRINT
) {
1893 *wintitle
= snewn(40 + strlen(fe
->game
->name
), char);
1894 sprintf(*wintitle
, "%s print setup", fe
->game
->name
);
1896 ret
= snewn(8, config_item
);
1900 ret
[i
].name
= "Number of puzzles to print";
1901 ret
[i
].type
= C_STRING
;
1902 ret
[i
].sval
= dupstr("1");
1906 ret
[i
].name
= "Number of puzzles across the page";
1907 ret
[i
].type
= C_STRING
;
1908 ret
[i
].sval
= dupstr("1");
1912 ret
[i
].name
= "Number of puzzles down the page";
1913 ret
[i
].type
= C_STRING
;
1914 ret
[i
].sval
= dupstr("1");
1918 ret
[i
].name
= "Percentage of standard size";
1919 ret
[i
].type
= C_STRING
;
1920 ret
[i
].sval
= dupstr("100.0");
1924 ret
[i
].name
= "Include currently shown puzzle";
1925 ret
[i
].type
= C_BOOLEAN
;
1930 ret
[i
].name
= "Print solutions";
1931 ret
[i
].type
= C_BOOLEAN
;
1933 ret
[i
].ival
= FALSE
;
1936 if (fe
->game
->can_print_in_colour
) {
1937 ret
[i
].name
= "Print in colour";
1938 ret
[i
].type
= C_BOOLEAN
;
1940 ret
[i
].ival
= FALSE
;
1945 ret
[i
].type
= C_END
;
1952 assert(!"We should never get here");
1957 static char *frontend_set_config(frontend
*fe
, int which
, config_item
*cfg
)
1959 if (which
< CFG_FRONTEND_SPECIFIC
) {
1960 return midend_set_config(fe
->me
, which
, cfg
);
1961 } else if (which
== CFG_PRINT
) {
1962 if ((fe
->printcount
= atoi(cfg
[0].sval
)) <= 0)
1963 return "Number of puzzles to print should be at least one";
1964 if ((fe
->printw
= atoi(cfg
[1].sval
)) <= 0)
1965 return "Number of puzzles across the page should be at least one";
1966 if ((fe
->printh
= atoi(cfg
[2].sval
)) <= 0)
1967 return "Number of puzzles down the page should be at least one";
1968 if ((fe
->printscale
= (float)atof(cfg
[3].sval
)) <= 0)
1969 return "Print size should be positive";
1970 fe
->printcurr
= cfg
[4].ival
;
1971 fe
->printsolns
= cfg
[5].ival
;
1972 fe
->printcolour
= fe
->game
->can_print_in_colour
&& cfg
[6].ival
;
1975 assert(!"We should never get here");
1976 return "Internal error";
1981 /* Separate version of mkctrl function for the Pocket PC. */
1982 /* Control coordinates should be specified in dialog units. */
1983 HWND
mkctrl(frontend
*fe
, int x1
, int x2
, int y1
, int y2
,
1984 LPCTSTR wclass
, int wstyle
,
1985 int exstyle
, const char *wtext
, int wid
)
1990 /* Convert dialog units into pixels */
1991 rc
.left
= x1
; rc
.right
= x2
;
1992 rc
.top
= y1
; rc
.bottom
= y2
;
1993 MapDialogRect(fe
->cfgbox
, &rc
);
1995 MultiByteToWideChar (CP_ACP
, 0, wtext
, -1, wwtext
, 256);
1997 return CreateWindowEx(exstyle
, wclass
, wwtext
,
1998 wstyle
| WS_CHILD
| WS_VISIBLE
,
2000 rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
2001 fe
->cfgbox
, (HMENU
) wid
, fe
->inst
, NULL
);
2004 static void create_config_controls(frontend
* fe
)
2007 int col1l
, col1r
, col2l
, col2r
, y
;
2012 /* Control placement done in dialog units */
2013 col1l
= 4; col1r
= 96; /* Label column */
2014 col2l
= 100; col2r
= 154; /* Input column (edit boxes and combo boxes) */
2017 * Count the controls so we can allocate cfgaux.
2019 for (nctrls
= 0, i
= fe
->cfg
; i
->type
!= C_END
; i
++)
2021 fe
->cfgaux
= snewn(nctrls
, struct cfg_aux
);
2024 y
= 22; /* Leave some room for the dialog title */
2025 for (i
= fe
->cfg
, j
= fe
->cfgaux
; i
->type
!= C_END
; i
++, j
++) {
2029 * Edit box with a label beside it.
2031 mkctrl(fe
, col1l
, col1r
, y
+ 1, y
+ 11,
2032 TEXT("Static"), SS_LEFTNOWORDWRAP
, 0, i
->name
, id
++);
2033 mkctrl(fe
, col2l
, col2r
, y
, y
+ 12,
2034 TEXT("EDIT"), WS_BORDER
| WS_TABSTOP
| ES_AUTOHSCROLL
,
2035 0, "", (j
->ctlid
= id
++));
2036 SetDlgItemTextA(fe
->cfgbox
, j
->ctlid
, i
->sval
);
2043 mkctrl(fe
, col1l
, col2r
, y
+ 1, y
+ 11, TEXT("BUTTON"),
2044 BS_NOTIFY
| BS_AUTOCHECKBOX
| WS_TABSTOP
,
2045 0, i
->name
, (j
->ctlid
= id
++));
2046 CheckDlgButton(fe
->cfgbox
, j
->ctlid
, (i
->ival
!= 0));
2051 * Drop-down list with a label beside it.
2053 mkctrl(fe
, col1l
, col1r
, y
+ 1, y
+ 11,
2054 TEXT("STATIC"), SS_LEFTNOWORDWRAP
, 0, i
->name
, id
++);
2055 ctl
= mkctrl(fe
, col2l
, col2r
, y
, y
+ 48,
2056 TEXT("COMBOBOX"), WS_BORDER
| WS_TABSTOP
|
2057 CBS_DROPDOWNLIST
| CBS_HASSTRINGS
,
2058 0, "", (j
->ctlid
= id
++));
2060 char c
, *p
, *q
, *str
;
2066 while (*q
&& *q
!= c
) q
++;
2067 str
= snewn(q
-p
+1, char);
2068 strncpy(str
, p
, q
-p
);
2072 MultiByteToWideChar (CP_ACP
, 0, str
, -1, ws
, 50);
2073 SendMessage(ctl
, CB_ADDSTRING
, 0, (LPARAM
)ws
);
2081 SendMessage(ctl
, CB_SETCURSEL
, i
->ival
, 0);
2091 static int CALLBACK
ConfigDlgProc(HWND hwnd
, UINT msg
,
2092 WPARAM wParam
, LPARAM lParam
)
2094 frontend
*fe
= (frontend
*)GetWindowLong(hwnd
, GWL_USERDATA
);
2104 fe
= (frontend
*) lParam
;
2105 SetWindowLong(hwnd
, GWL_USERDATA
, lParam
);
2108 fe
->cfg
= frontend_get_config(fe
, fe
->cfg_which
, &title
);
2110 make_dialog_full_screen(hwnd
);
2112 SetDlgItemTextA(hwnd
, IDC_CONFIG_CAPTION
, title
);
2113 SendDlgItemMessage(hwnd
, IDC_CONFIG_CAPTION
, WM_SETFONT
,
2114 (WPARAM
) dialog_title_font(), 0);
2116 create_config_controls(fe
);
2123 * OK and Cancel are special cases.
2125 if ((LOWORD(wParam
) == IDOK
|| LOWORD(wParam
) == IDCANCEL
)) {
2126 if (LOWORD(wParam
) == IDOK
) {
2127 char *err
= frontend_set_config(fe
, fe
->cfg_which
, fe
->cfg
);
2130 MessageBox(hwnd
, err
, "Validation error",
2131 MB_ICONERROR
| MB_OK
);
2150 * First find the control whose id this is.
2152 for (i
= fe
->cfg
, j
= fe
->cfgaux
; i
->type
!= C_END
; i
++, j
++) {
2153 if (j
->ctlid
== LOWORD(wParam
))
2156 if (i
->type
== C_END
)
2157 return 0; /* not our problem */
2159 if (i
->type
== C_STRING
&& HIWORD(wParam
) == EN_CHANGE
) {
2162 TCHAR wBuffer
[4096];
2163 GetDlgItemText(fe
->cfgbox
, j
->ctlid
, wBuffer
, 4096);
2164 WideCharToMultiByte(CP_ACP
, 0, wBuffer
, -1, buffer
, 4096, NULL
, NULL
);
2166 GetDlgItemText(fe
->cfgbox
, j
->ctlid
, buffer
, lenof(buffer
));
2168 buffer
[lenof(buffer
)-1] = '\0';
2170 i
->sval
= dupstr(buffer
);
2171 } else if (i
->type
== C_BOOLEAN
&&
2172 (HIWORD(wParam
) == BN_CLICKED
||
2173 HIWORD(wParam
) == BN_DBLCLK
)) {
2174 i
->ival
= IsDlgButtonChecked(fe
->cfgbox
, j
->ctlid
);
2175 } else if (i
->type
== C_CHOICES
&&
2176 HIWORD(wParam
) == CBN_SELCHANGE
) {
2177 i
->ival
= SendDlgItemMessage(fe
->cfgbox
, j
->ctlid
,
2178 CB_GETCURSEL
, 0, 0);
2192 HWND
mkctrl(frontend
*fe
, int x1
, int x2
, int y1
, int y2
,
2193 char *wclass
, int wstyle
,
2194 int exstyle
, const char *wtext
, int wid
)
2197 ret
= CreateWindowEx(exstyle
, wclass
, wtext
,
2198 wstyle
| WS_CHILD
| WS_VISIBLE
, x1
, y1
, x2
-x1
, y2
-y1
,
2199 fe
->cfgbox
, (HMENU
) wid
, fe
->inst
, NULL
);
2200 SendMessage(ret
, WM_SETFONT
, (WPARAM
)fe
->cfgfont
, MAKELPARAM(TRUE
, 0));
2205 static void about(frontend
*fe
)
2208 DialogBox(fe
->inst
, MAKEINTRESOURCE(IDD_ABOUT
), fe
->hwnd
, AboutDlgProc
);
2218 int winwidth
, winheight
, y
;
2219 int height
, width
, maxwid
;
2220 const char *strings
[16];
2225 sprintf(titlebuf
, "About %.250s", fe
->game
->name
);
2227 strings
[nstrings
++] = fe
->game
->name
;
2228 strings
[nstrings
++] = "from Simon Tatham's Portable Puzzle Collection";
2229 strings
[nstrings
++] = ver
;
2231 wc
.style
= CS_DBLCLKS
| CS_SAVEBITS
;
2232 wc
.lpfnWndProc
= DefDlgProc
;
2234 wc
.cbWndExtra
= DLGWINDOWEXTRA
+ 8;
2235 wc
.hInstance
= fe
->inst
;
2237 wc
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
2238 wc
.hbrBackground
= (HBRUSH
) (COLOR_BACKGROUND
+1);
2239 wc
.lpszMenuName
= NULL
;
2240 wc
.lpszClassName
= "GameAboutBox";
2243 hdc
= GetDC(fe
->hwnd
);
2244 SetMapMode(hdc
, MM_TEXT
);
2246 fe
->dlg_done
= FALSE
;
2248 fe
->cfgfont
= CreateFont(-MulDiv(8, GetDeviceCaps(hdc
, LOGPIXELSY
), 72),
2250 FALSE
, FALSE
, FALSE
, DEFAULT_CHARSET
,
2251 OUT_DEFAULT_PRECIS
, CLIP_DEFAULT_PRECIS
,
2256 oldfont
= SelectObject(hdc
, fe
->cfgfont
);
2257 if (GetTextMetrics(hdc
, &tm
)) {
2258 height
= tm
.tmAscent
+ tm
.tmDescent
;
2259 width
= tm
.tmAveCharWidth
;
2261 height
= width
= 30;
2265 * Figure out the layout of the About box by measuring the
2266 * length of each piece of text.
2269 winheight
= height
/2;
2271 for (i
= 0; i
< nstrings
; i
++) {
2272 if (GetTextExtentPoint32(hdc
, strings
[i
], strlen(strings
[i
]), &size
))
2273 lengths
[i
] = size
.cx
;
2275 lengths
[i
] = 0; /* *shrug* */
2276 if (maxwid
< lengths
[i
])
2277 maxwid
= lengths
[i
];
2278 winheight
+= height
* 3 / 2 + (height
/ 2);
2281 winheight
+= height
+ height
* 7 / 4; /* OK button */
2282 winwidth
= maxwid
+ 4*width
;
2284 SelectObject(hdc
, oldfont
);
2285 ReleaseDC(fe
->hwnd
, hdc
);
2288 * Create the dialog, now that we know its size.
2295 r
.bottom
= winheight
;
2297 AdjustWindowRectEx(&r
, (WS_OVERLAPPEDWINDOW
/*|
2298 DS_MODALFRAME | WS_POPUP | WS_VISIBLE |
2299 WS_CAPTION | WS_SYSMENU*/) &~
2300 (WS_MAXIMIZEBOX
| WS_OVERLAPPED
),
2304 * Centre the dialog on its parent window.
2308 GetWindowRect(fe
->hwnd
, &r2
);
2309 r
.left
= (r2
.left
+ r2
.right
- r
.right
) / 2;
2310 r
.top
= (r2
.top
+ r2
.bottom
- r
.bottom
) / 2;
2314 fe
->cfgbox
= CreateWindowEx(0, wc
.lpszClassName
, titlebuf
,
2315 DS_MODALFRAME
| WS_POPUP
| WS_VISIBLE
|
2316 WS_CAPTION
| WS_SYSMENU
,
2318 r
.right
-r
.left
, r
.bottom
-r
.top
,
2319 fe
->hwnd
, NULL
, fe
->inst
, NULL
);
2322 SendMessage(fe
->cfgbox
, WM_SETFONT
, (WPARAM
)fe
->cfgfont
, FALSE
);
2324 SetWindowLong(fe
->cfgbox
, GWL_USERDATA
, (LONG
)fe
);
2325 SetWindowLong(fe
->cfgbox
, DWL_DLGPROC
, (LONG
)AboutDlgProc
);
2329 for (i
= 0; i
< nstrings
; i
++) {
2330 int border
= width
*2 + (maxwid
- lengths
[i
]) / 2;
2331 mkctrl(fe
, border
, border
+lengths
[i
], y
+height
*1/8, y
+height
*9/8,
2332 "Static", 0, 0, strings
[i
], id
++);
2335 assert(y
< winheight
);
2339 y
+= height
/2; /* extra space before OK */
2340 mkctrl(fe
, width
*2, maxwid
+width
*2, y
, y
+height
*7/4, "BUTTON",
2341 BS_PUSHBUTTON
| WS_TABSTOP
| BS_DEFPUSHBUTTON
, 0,
2344 SendMessage(fe
->cfgbox
, WM_INITDIALOG
, 0, 0);
2346 EnableWindow(fe
->hwnd
, FALSE
);
2347 ShowWindow(fe
->cfgbox
, SW_SHOWNORMAL
);
2348 while ((gm
=GetMessage(&msg
, NULL
, 0, 0)) > 0) {
2349 if (!IsDialogMessage(fe
->cfgbox
, &msg
))
2350 DispatchMessage(&msg
);
2354 EnableWindow(fe
->hwnd
, TRUE
);
2355 SetForegroundWindow(fe
->hwnd
);
2356 DestroyWindow(fe
->cfgbox
);
2357 DeleteObject(fe
->cfgfont
);
2361 static int get_config(frontend
*fe
, int which
)
2364 fe
->cfg_which
= which
;
2366 return DialogBoxParam(fe
->inst
,
2367 MAKEINTRESOURCE(IDD_CONFIG
),
2368 fe
->hwnd
, ConfigDlgProc
,
2382 int winwidth
, winheight
, col1l
, col1r
, col2l
, col2r
, y
;
2383 int height
, width
, maxlabel
, maxcheckbox
;
2385 wc
.style
= CS_DBLCLKS
| CS_SAVEBITS
;
2386 wc
.lpfnWndProc
= DefDlgProc
;
2388 wc
.cbWndExtra
= DLGWINDOWEXTRA
+ 8;
2389 wc
.hInstance
= fe
->inst
;
2391 wc
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
2392 wc
.hbrBackground
= (HBRUSH
) (COLOR_BACKGROUND
+1);
2393 wc
.lpszMenuName
= NULL
;
2394 wc
.lpszClassName
= "GameConfigBox";
2397 hdc
= GetDC(fe
->hwnd
);
2398 SetMapMode(hdc
, MM_TEXT
);
2400 fe
->dlg_done
= FALSE
;
2402 fe
->cfgfont
= CreateFont(-MulDiv(8, GetDeviceCaps(hdc
, LOGPIXELSY
), 72),
2404 FALSE
, FALSE
, FALSE
, DEFAULT_CHARSET
,
2405 OUT_DEFAULT_PRECIS
, CLIP_DEFAULT_PRECIS
,
2410 oldfont
= SelectObject(hdc
, fe
->cfgfont
);
2411 if (GetTextMetrics(hdc
, &tm
)) {
2412 height
= tm
.tmAscent
+ tm
.tmDescent
;
2413 width
= tm
.tmAveCharWidth
;
2415 height
= width
= 30;
2418 fe
->cfg
= frontend_get_config(fe
, which
, &title
);
2419 fe
->cfg_which
= which
;
2422 * Figure out the layout of the config box by measuring the
2423 * length of each piece of text.
2425 maxlabel
= maxcheckbox
= 0;
2426 winheight
= height
/2;
2428 for (i
= fe
->cfg
; i
->type
!= C_END
; i
++) {
2433 * Both these control types have a label filling only
2434 * the left-hand column of the box.
2436 if (GetTextExtentPoint32(hdc
, i
->name
, strlen(i
->name
), &size
) &&
2439 winheight
+= height
* 3 / 2 + (height
/ 2);
2444 * Checkboxes take up the whole of the box width.
2446 if (GetTextExtentPoint32(hdc
, i
->name
, strlen(i
->name
), &size
) &&
2447 maxcheckbox
< size
.cx
)
2448 maxcheckbox
= size
.cx
;
2449 winheight
+= height
+ (height
/ 2);
2454 winheight
+= height
+ height
* 7 / 4; /* OK / Cancel buttons */
2457 col1r
= col1l
+ maxlabel
;
2458 col2l
= col1r
+ 2*width
;
2459 col2r
= col2l
+ 30*width
;
2460 if (col2r
< col1l
+2*height
+maxcheckbox
)
2461 col2r
= col1l
+2*height
+maxcheckbox
;
2462 winwidth
= col2r
+ 2*width
;
2464 SelectObject(hdc
, oldfont
);
2465 ReleaseDC(fe
->hwnd
, hdc
);
2468 * Create the dialog, now that we know its size.
2475 r
.bottom
= winheight
;
2477 AdjustWindowRectEx(&r
, (WS_OVERLAPPEDWINDOW
/*|
2478 DS_MODALFRAME | WS_POPUP | WS_VISIBLE |
2479 WS_CAPTION | WS_SYSMENU*/) &~
2480 (WS_MAXIMIZEBOX
| WS_OVERLAPPED
),
2484 * Centre the dialog on its parent window.
2488 GetWindowRect(fe
->hwnd
, &r2
);
2489 r
.left
= (r2
.left
+ r2
.right
- r
.right
) / 2;
2490 r
.top
= (r2
.top
+ r2
.bottom
- r
.bottom
) / 2;
2494 fe
->cfgbox
= CreateWindowEx(0, wc
.lpszClassName
, title
,
2495 DS_MODALFRAME
| WS_POPUP
| WS_VISIBLE
|
2496 WS_CAPTION
| WS_SYSMENU
,
2498 r
.right
-r
.left
, r
.bottom
-r
.top
,
2499 fe
->hwnd
, NULL
, fe
->inst
, NULL
);
2503 SendMessage(fe
->cfgbox
, WM_SETFONT
, (WPARAM
)fe
->cfgfont
, FALSE
);
2505 SetWindowLong(fe
->cfgbox
, GWL_USERDATA
, (LONG
)fe
);
2506 SetWindowLong(fe
->cfgbox
, DWL_DLGPROC
, (LONG
)ConfigDlgProc
);
2509 * Count the controls so we can allocate cfgaux.
2511 for (nctrls
= 0, i
= fe
->cfg
; i
->type
!= C_END
; i
++)
2513 fe
->cfgaux
= snewn(nctrls
, struct cfg_aux
);
2517 for (i
= fe
->cfg
, j
= fe
->cfgaux
; i
->type
!= C_END
; i
++, j
++) {
2521 * Edit box with a label beside it.
2523 mkctrl(fe
, col1l
, col1r
, y
+height
*1/8, y
+height
*9/8,
2524 "Static", 0, 0, i
->name
, id
++);
2525 ctl
= mkctrl(fe
, col2l
, col2r
, y
, y
+height
*3/2,
2526 "EDIT", WS_TABSTOP
| ES_AUTOHSCROLL
,
2527 WS_EX_CLIENTEDGE
, "", (j
->ctlid
= id
++));
2528 SetWindowText(ctl
, i
->sval
);
2536 mkctrl(fe
, col1l
, col2r
, y
, y
+height
, "BUTTON",
2537 BS_NOTIFY
| BS_AUTOCHECKBOX
| WS_TABSTOP
,
2538 0, i
->name
, (j
->ctlid
= id
++));
2539 CheckDlgButton(fe
->cfgbox
, j
->ctlid
, (i
->ival
!= 0));
2545 * Drop-down list with a label beside it.
2547 mkctrl(fe
, col1l
, col1r
, y
+height
*1/8, y
+height
*9/8,
2548 "STATIC", 0, 0, i
->name
, id
++);
2549 ctl
= mkctrl(fe
, col2l
, col2r
, y
, y
+height
*41/2,
2550 "COMBOBOX", WS_TABSTOP
|
2551 CBS_DROPDOWNLIST
| CBS_HASSTRINGS
,
2552 WS_EX_CLIENTEDGE
, "", (j
->ctlid
= id
++));
2554 char c
, *p
, *q
, *str
;
2556 SendMessage(ctl
, CB_RESETCONTENT
, 0, 0);
2561 while (*q
&& *q
!= c
) q
++;
2562 str
= snewn(q
-p
+1, char);
2563 strncpy(str
, p
, q
-p
);
2565 SendMessage(ctl
, CB_ADDSTRING
, 0, (LPARAM
)str
);
2572 SendMessage(ctl
, CB_SETCURSEL
, i
->ival
, 0);
2578 assert(y
< winheight
);
2582 y
+= height
/2; /* extra space before OK and Cancel */
2583 mkctrl(fe
, col1l
, (col1l
+col2r
)/2-width
, y
, y
+height
*7/4, "BUTTON",
2584 BS_PUSHBUTTON
| WS_TABSTOP
| BS_DEFPUSHBUTTON
, 0,
2586 mkctrl(fe
, (col1l
+col2r
)/2+width
, col2r
, y
, y
+height
*7/4, "BUTTON",
2587 BS_PUSHBUTTON
| WS_TABSTOP
, 0, "Cancel", IDCANCEL
);
2589 SendMessage(fe
->cfgbox
, WM_INITDIALOG
, 0, 0);
2591 EnableWindow(fe
->hwnd
, FALSE
);
2592 ShowWindow(fe
->cfgbox
, SW_SHOWNORMAL
);
2593 while ((gm
=GetMessage(&msg
, NULL
, 0, 0)) > 0) {
2594 if (!IsDialogMessage(fe
->cfgbox
, &msg
))
2595 DispatchMessage(&msg
);
2599 EnableWindow(fe
->hwnd
, TRUE
);
2600 SetForegroundWindow(fe
->hwnd
);
2601 DestroyWindow(fe
->cfgbox
);
2602 DeleteObject(fe
->cfgfont
);
2607 return (fe
->dlg_done
== 2);
2612 static void calculate_bitmap_position(frontend
*fe
, int x
, int y
)
2614 /* Pocket PC - center the game in the full screen window */
2618 GetClientRect(fe
->hwnd
, &rcClient
);
2619 fe
->bitmapPosition
.left
= (rcClient
.right
- x
) / 2;
2620 yMargin
= rcClient
.bottom
- y
;
2622 if (fe
->numpad
!= NULL
) {
2624 GetWindowRect(fe
->numpad
, &rcPad
);
2625 yMargin
-= rcPad
.bottom
- rcPad
.top
;
2628 if (fe
->statusbar
!= NULL
) {
2630 GetWindowRect(fe
->statusbar
, &rcStatus
);
2631 yMargin
-= rcStatus
.bottom
- rcStatus
.top
;
2634 fe
->bitmapPosition
.top
= yMargin
/ 2;
2636 fe
->bitmapPosition
.right
= fe
->bitmapPosition
.left
+ x
;
2637 fe
->bitmapPosition
.bottom
= fe
->bitmapPosition
.top
+ y
;
2640 static void calculate_bitmap_position(frontend
*fe
, int x
, int y
)
2642 /* Plain Windows - position the game in the upper-left corner */
2643 fe
->bitmapPosition
.left
= 0;
2644 fe
->bitmapPosition
.top
= 0;
2645 fe
->bitmapPosition
.right
= fe
->bitmapPosition
.left
+ x
;
2646 fe
->bitmapPosition
.bottom
= fe
->bitmapPosition
.top
+ y
;
2650 static void new_bitmap(frontend
*fe
, int x
, int y
)
2654 if (fe
->bitmap
) DeleteObject(fe
->bitmap
);
2656 hdc
= GetDC(fe
->hwnd
);
2657 fe
->bitmap
= CreateCompatibleBitmap(hdc
, x
, y
);
2658 calculate_bitmap_position(fe
, x
, y
);
2659 ReleaseDC(fe
->hwnd
, hdc
);
2662 static void new_game_size(frontend
*fe
, float scale
)
2667 get_max_puzzle_size(fe
, &x
, &y
);
2668 midend_size(fe
->me
, &x
, &y
, FALSE
);
2671 x
= (int)((float)x
* fe
->puzz_scale
);
2672 y
= (int)((float)y
* fe
->puzz_scale
);
2673 midend_size(fe
->me
, &x
, &y
, TRUE
);
2675 fe
->ymin
= (fe
->xmin
* y
) / x
;
2680 AdjustWindowRectEx(&r
, WINFLAGS
, TRUE
, 0);
2682 if (fe
->statusbar
!= NULL
) {
2683 GetWindowRect(fe
->statusbar
, &sr
);
2685 sr
.left
= sr
.right
= sr
.top
= sr
.bottom
= 0;
2688 SetWindowPos(fe
->hwnd
, NULL
, 0, 0,
2690 r
.bottom
- r
.top
+ sr
.bottom
- sr
.top
,
2691 SWP_NOMOVE
| SWP_NOZORDER
);
2694 check_window_size(fe
, &x
, &y
);
2697 if (fe
->statusbar
!= NULL
)
2698 SetWindowPos(fe
->statusbar
, NULL
, 0, y
, x
,
2699 sr
.bottom
- sr
.top
, SWP_NOZORDER
);
2702 new_bitmap(fe
, x
, y
);
2705 InvalidateRect(fe
->hwnd
, NULL
, TRUE
);
2707 midend_redraw(fe
->me
);
2711 * Given a proposed new window rect, work out the resulting
2712 * difference in client size (from current), and use to try
2713 * and resize the puzzle, returning (wx,wy) as the actual
2717 static void adjust_game_size(frontend
*fe
, RECT
*proposed
, int isedge
,
2718 int *wx_r
, int *wy_r
)
2721 int nx
, ny
, xdiff
, ydiff
, wx
, wy
;
2723 /* Work out the current window sizing, and thus the
2724 * difference in size we're asking for. */
2725 GetClientRect(fe
->hwnd
, &cr
);
2727 AdjustWindowRectEx(&wr
, WINFLAGS
, TRUE
, 0);
2729 xdiff
= (proposed
->right
- proposed
->left
) - (wr
.right
- wr
.left
);
2730 ydiff
= (proposed
->bottom
- proposed
->top
) - (wr
.bottom
- wr
.top
);
2733 /* These next four lines work around the fact that midend_size
2734 * is happy to shrink _but not grow_ if you change one dimension
2735 * but not the other. */
2736 if (xdiff
> 0 && ydiff
== 0)
2737 ydiff
= (xdiff
* (wr
.right
- wr
.left
)) / (wr
.bottom
- wr
.top
);
2738 if (xdiff
== 0 && ydiff
> 0)
2739 xdiff
= (ydiff
* (wr
.bottom
- wr
.top
)) / (wr
.right
- wr
.left
);
2742 if (check_window_resize(fe
,
2743 (cr
.right
- cr
.left
) + xdiff
,
2744 (cr
.bottom
- cr
.top
) + ydiff
,
2745 &nx
, &ny
, &wx
, &wy
)) {
2746 new_bitmap(fe
, nx
, ny
);
2747 midend_force_redraw(fe
->me
);
2749 /* reset size to current window size */
2750 wx
= wr
.right
- wr
.left
;
2751 wy
= wr
.bottom
- wr
.top
;
2753 /* Re-fetch rectangle; size limits mean we might not have
2754 * taken it quite to the mouse drag positions. */
2755 GetClientRect(fe
->hwnd
, &cr
);
2756 adjust_statusbar(fe
, &cr
);
2758 *wx_r
= wx
; *wy_r
= wy
;
2761 static void update_type_menu_tick(frontend
*fe
)
2765 if (fe
->typemenu
== INVALID_HANDLE_VALUE
)
2768 total
= GetMenuItemCount(fe
->typemenu
);
2769 n
= midend_which_preset(fe
->me
);
2771 n
= total
- 1; /* "Custom" item */
2773 for (i
= 0; i
< total
; i
++) {
2774 int flag
= (i
== n
? MF_CHECKED
: MF_UNCHECKED
);
2775 CheckMenuItem(fe
->typemenu
, i
, MF_BYPOSITION
| flag
);
2778 DrawMenuBar(fe
->hwnd
);
2781 static void update_copy_menu_greying(frontend
*fe
)
2783 UINT enable
= (midend_can_format_as_text_now(fe
->me
) ?
2784 MF_ENABLED
: MF_GRAYED
);
2785 EnableMenuItem(fe
->gamemenu
, IDM_COPY
, MF_BYCOMMAND
| enable
);
2788 static void new_game_type(frontend
*fe
)
2790 midend_new_game(fe
->me
);
2791 new_game_size(fe
, 1.0);
2792 update_type_menu_tick(fe
);
2793 update_copy_menu_greying(fe
);
2796 static int is_alt_pressed(void)
2799 int r
= GetKeyboardState(keystate
);
2802 if (keystate
[VK_MENU
] & 0x80)
2804 if (keystate
[VK_RMENU
] & 0x80)
2809 static void savefile_write(void *wctx
, void *buf
, int len
)
2811 FILE *fp
= (FILE *)wctx
;
2812 fwrite(buf
, 1, len
, fp
);
2815 static int savefile_read(void *wctx
, void *buf
, int len
)
2817 FILE *fp
= (FILE *)wctx
;
2820 ret
= fread(buf
, 1, len
, fp
);
2821 return (ret
== len
);
2824 static LRESULT CALLBACK
WndProc(HWND hwnd
, UINT message
,
2825 WPARAM wParam
, LPARAM lParam
)
2827 frontend
*fe
= (frontend
*)GetWindowLong(hwnd
, GWL_USERDATA
);
2832 DestroyWindow(hwnd
);
2836 /* Numeric pad sends WM_COMMAND messages */
2837 if ((wParam
>= IDM_KEYEMUL
) && (wParam
< IDM_KEYEMUL
+ 256))
2839 midend_process_key(fe
->me
, 0, 0, wParam
- IDM_KEYEMUL
);
2842 cmd
= wParam
& ~0xF; /* low 4 bits reserved to Windows */
2845 if (!midend_process_key(fe
->me
, 0, 0, 'n'))
2849 midend_restart_game(fe
->me
);
2852 if (!midend_process_key(fe
->me
, 0, 0, 'u'))
2856 if (!midend_process_key(fe
->me
, 0, 0, '\x12'))
2861 char *text
= midend_text_format(fe
->me
);
2863 write_clip(hwnd
, text
);
2865 MessageBeep(MB_ICONWARNING
);
2871 char *msg
= midend_solve(fe
->me
);
2873 MessageBox(hwnd
, msg
, "Unable to solve",
2874 MB_ICONERROR
| MB_OK
);
2878 if (!midend_process_key(fe
->me
, 0, 0, 'q'))
2882 if (get_config(fe
, CFG_SETTINGS
))
2886 if (get_config(fe
, CFG_SEED
))
2890 if (get_config(fe
, CFG_DESC
))
2894 if (get_config(fe
, CFG_PRINT
))
2904 char filename
[FILENAME_MAX
];
2907 memset(&of
, 0, sizeof(of
));
2908 of
.hwndOwner
= hwnd
;
2909 of
.lpstrFilter
= "All Files (*.*)\0*\0\0\0";
2910 of
.lpstrCustomFilter
= NULL
;
2911 of
.nFilterIndex
= 1;
2912 of
.lpstrFile
= filename
;
2914 of
.nMaxFile
= lenof(filename
);
2915 of
.lpstrFileTitle
= NULL
;
2916 of
.lpstrTitle
= (cmd
== IDM_SAVE
?
2917 "Enter name of game file to save" :
2918 "Enter name of saved game file to load");
2920 #ifdef OPENFILENAME_SIZE_VERSION_400
2921 of
.lStructSize
= OPENFILENAME_SIZE_VERSION_400
;
2923 of
.lStructSize
= sizeof(of
);
2925 of
.lpstrInitialDir
= NULL
;
2927 if (cmd
== IDM_SAVE
)
2928 ret
= GetSaveFileName(&of
);
2930 ret
= GetOpenFileName(&of
);
2933 if (cmd
== IDM_SAVE
) {
2936 if ((fp
= fopen(filename
, "r")) != NULL
) {
2937 char buf
[256 + FILENAME_MAX
];
2941 sprintf(buf
, "Are you sure you want to overwrite"
2942 " the file \"%.*s\"?",
2943 FILENAME_MAX
, filename
);
2944 if (MessageBox(hwnd
, buf
, "Question",
2945 MB_YESNO
| MB_ICONQUESTION
)
2950 fp
= fopen(filename
, "w");
2953 MessageBox(hwnd
, "Unable to open save file",
2954 "Error", MB_ICONERROR
| MB_OK
);
2958 midend_serialise(fe
->me
, savefile_write
, fp
);
2962 FILE *fp
= fopen(filename
, "r");
2966 MessageBox(hwnd
, "Unable to open saved game file",
2967 "Error", MB_ICONERROR
| MB_OK
);
2971 err
= midend_deserialise(fe
->me
, savefile_read
, fp
);
2976 MessageBox(hwnd
, err
, "Error", MB_ICONERROR
|MB_OK
);
2980 new_game_size(fe
, 1.0);
2988 start_help(fe
, NULL
);
2991 assert(help_type
!= NONE
);
2992 start_help(fe
, help_type
== CHM
?
2993 fe
->game
->htmlhelp_topic
: fe
->game
->winhelp_topic
);
2998 if (wParam
>= IDM_GAMES
&& wParam
< (IDM_GAMES
+ (WPARAM
)gamecount
)) {
2999 int p
= wParam
- IDM_GAMES
;
3002 new_game(fe
, gamelist
[p
], NULL
, &error
);
3006 int p
= ((wParam
&~ 0xF) - IDM_PRESETS
) / 0x10;
3008 if (p
>= 0 && p
< fe
->npresets
) {
3009 midend_set_params(fe
->me
, fe
->presets
[p
]);
3030 hdc
= BeginPaint(hwnd
, &p
);
3031 hdc2
= CreateCompatibleDC(hdc
);
3032 prevbm
= SelectObject(hdc2
, fe
->bitmap
);
3034 FillRect(hdc
, &(p
.rcPaint
), (HBRUSH
) GetStockObject(WHITE_BRUSH
));
3036 IntersectRect(&rcDest
, &(fe
->bitmapPosition
), &(p
.rcPaint
));
3038 rcDest
.left
, rcDest
.top
,
3039 rcDest
.right
- rcDest
.left
,
3040 rcDest
.bottom
- rcDest
.top
,
3042 rcDest
.left
- fe
->bitmapPosition
.left
,
3043 rcDest
.top
- fe
->bitmapPosition
.top
,
3045 SelectObject(hdc2
, prevbm
);
3054 int r
= GetKeyboardState(keystate
);
3055 int shift
= (r
&& (keystate
[VK_SHIFT
] & 0x80)) ? MOD_SHFT
: 0;
3056 int ctrl
= (r
&& (keystate
[VK_CONTROL
] & 0x80)) ? MOD_CTRL
: 0;
3060 if (!(lParam
& 0x01000000))
3061 key
= MOD_NUM_KEYPAD
| '4';
3063 key
= shift
| ctrl
| CURSOR_LEFT
;
3066 if (!(lParam
& 0x01000000))
3067 key
= MOD_NUM_KEYPAD
| '6';
3069 key
= shift
| ctrl
| CURSOR_RIGHT
;
3072 if (!(lParam
& 0x01000000))
3073 key
= MOD_NUM_KEYPAD
| '8';
3075 key
= shift
| ctrl
| CURSOR_UP
;
3078 if (!(lParam
& 0x01000000))
3079 key
= MOD_NUM_KEYPAD
| '2';
3081 key
= shift
| ctrl
| CURSOR_DOWN
;
3084 * Diagonal keys on the numeric keypad.
3087 if (!(lParam
& 0x01000000)) key
= MOD_NUM_KEYPAD
| '9';
3090 if (!(lParam
& 0x01000000)) key
= MOD_NUM_KEYPAD
| '3';
3093 if (!(lParam
& 0x01000000)) key
= MOD_NUM_KEYPAD
| '7';
3096 if (!(lParam
& 0x01000000)) key
= MOD_NUM_KEYPAD
| '1';
3099 if (!(lParam
& 0x01000000)) key
= MOD_NUM_KEYPAD
| '0';
3102 if (!(lParam
& 0x01000000)) key
= MOD_NUM_KEYPAD
| '5';
3105 * Numeric keypad keys with Num Lock on.
3107 case VK_NUMPAD4
: key
= MOD_NUM_KEYPAD
| '4'; break;
3108 case VK_NUMPAD6
: key
= MOD_NUM_KEYPAD
| '6'; break;
3109 case VK_NUMPAD8
: key
= MOD_NUM_KEYPAD
| '8'; break;
3110 case VK_NUMPAD2
: key
= MOD_NUM_KEYPAD
| '2'; break;
3111 case VK_NUMPAD5
: key
= MOD_NUM_KEYPAD
| '5'; break;
3112 case VK_NUMPAD9
: key
= MOD_NUM_KEYPAD
| '9'; break;
3113 case VK_NUMPAD3
: key
= MOD_NUM_KEYPAD
| '3'; break;
3114 case VK_NUMPAD7
: key
= MOD_NUM_KEYPAD
| '7'; break;
3115 case VK_NUMPAD1
: key
= MOD_NUM_KEYPAD
| '1'; break;
3116 case VK_NUMPAD0
: key
= MOD_NUM_KEYPAD
| '0'; break;
3120 if (!midend_process_key(fe
->me
, 0, 0, key
))
3125 m
.message
= WM_KEYDOWN
;
3127 m
.lParam
= lParam
& 0xdfff;
3128 TranslateMessage(&m
);
3132 case WM_LBUTTONDOWN
:
3133 case WM_RBUTTONDOWN
:
3134 case WM_MBUTTONDOWN
:
3139 * Shift-clicks count as middle-clicks, since otherwise
3140 * two-button Windows users won't have any kind of
3141 * middle click to use.
3143 if (message
== WM_MBUTTONDOWN
|| (wParam
& MK_SHIFT
))
3144 button
= MIDDLE_BUTTON
;
3145 else if (message
== WM_RBUTTONDOWN
|| is_alt_pressed())
3146 button
= RIGHT_BUTTON
;
3149 button
= LEFT_BUTTON
;
3151 if ((fe
->game
->flags
& REQUIRE_RBUTTON
) == 0)
3152 button
= LEFT_BUTTON
;
3157 shrgi
.cbSize
= sizeof(SHRGINFO
);
3158 shrgi
.hwndClient
= hwnd
;
3159 shrgi
.ptDown
.x
= (signed short)LOWORD(lParam
);
3160 shrgi
.ptDown
.y
= (signed short)HIWORD(lParam
);
3161 shrgi
.dwFlags
= SHRG_RETURNCMD
;
3163 if (GN_CONTEXTMENU
== SHRecognizeGesture(&shrgi
))
3164 button
= RIGHT_BUTTON
;
3166 button
= LEFT_BUTTON
;
3170 if (!midend_process_key(fe
->me
,
3171 (signed short)LOWORD(lParam
) - fe
->bitmapPosition
.left
,
3172 (signed short)HIWORD(lParam
) - fe
->bitmapPosition
.top
,
3186 * Shift-clicks count as middle-clicks, since otherwise
3187 * two-button Windows users won't have any kind of
3188 * middle click to use.
3190 if (message
== WM_MBUTTONUP
|| (wParam
& MK_SHIFT
))
3191 button
= MIDDLE_RELEASE
;
3192 else if (message
== WM_RBUTTONUP
|| is_alt_pressed())
3193 button
= RIGHT_RELEASE
;
3195 button
= LEFT_RELEASE
;
3197 if (!midend_process_key(fe
->me
,
3198 (signed short)LOWORD(lParam
) - fe
->bitmapPosition
.left
,
3199 (signed short)HIWORD(lParam
) - fe
->bitmapPosition
.top
,
3210 if (wParam
& (MK_MBUTTON
| MK_SHIFT
))
3211 button
= MIDDLE_DRAG
;
3212 else if (wParam
& MK_RBUTTON
|| is_alt_pressed())
3213 button
= RIGHT_DRAG
;
3217 if (!midend_process_key(fe
->me
,
3218 (signed short)LOWORD(lParam
) - fe
->bitmapPosition
.left
,
3219 (signed short)HIWORD(lParam
) - fe
->bitmapPosition
.top
,
3225 if (!midend_process_key(fe
->me
, 0, 0, (unsigned char)wParam
))
3230 DWORD now
= GetTickCount();
3231 float elapsed
= (float) (now
- fe
->timer_last_tickcount
) * 0.001F
;
3232 midend_timer(fe
->me
, elapsed
);
3233 fe
->timer_last_tickcount
= now
;
3239 RECT
*sr
= (RECT
*)lParam
;
3240 int wx
, wy
, isedge
= 0;
3242 if (wParam
== WMSZ_TOP
||
3243 wParam
== WMSZ_RIGHT
||
3244 wParam
== WMSZ_BOTTOM
||
3245 wParam
== WMSZ_LEFT
) isedge
= 1;
3246 adjust_game_size(fe
, sr
, isedge
, &wx
, &wy
);
3248 /* Given the window size the puzzles constrain
3249 * us to, work out which edge we should be moving. */
3250 if (wParam
== WMSZ_TOP
||
3251 wParam
== WMSZ_TOPLEFT
||
3252 wParam
== WMSZ_TOPRIGHT
) {
3253 sr
->top
= sr
->bottom
- wy
;
3255 sr
->bottom
= sr
->top
+ wy
;
3257 if (wParam
== WMSZ_LEFT
||
3258 wParam
== WMSZ_TOPLEFT
||
3259 wParam
== WMSZ_BOTTOMLEFT
) {
3260 sr
->left
= sr
->right
- wx
;
3262 sr
->right
= sr
->left
+ wx
;
3270 return DefWindowProc(hwnd
, message
, wParam
, lParam
);
3274 static int FindPreviousInstance()
3276 /* Check if application is running. If it's running then focus on the window */
3277 HWND hOtherWnd
= NULL
;
3279 hOtherWnd
= FindWindow (wGameName
, wGameName
);
3282 SetForegroundWindow (hOtherWnd
);
3290 int WINAPI
WinMain(HINSTANCE inst
, HINSTANCE prev
, LPSTR cmdline
, int show
)
3298 MultiByteToWideChar (CP_ACP
, 0, CLASSNAME
, -1, wClassName
, 256);
3299 if (FindPreviousInstance ())
3303 InitCommonControls();
3309 wndclass
.lpfnWndProc
= WndProc
;
3310 wndclass
.cbClsExtra
= 0;
3311 wndclass
.cbWndExtra
= 0;
3312 wndclass
.hInstance
= inst
;
3313 wndclass
.hIcon
= LoadIcon(inst
, MAKEINTRESOURCE(200));
3315 if (!wndclass
.hIcon
) /* in case resource file is absent */
3316 wndclass
.hIcon
= LoadIcon(inst
, IDI_APPLICATION
);
3318 wndclass
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
3319 wndclass
.hbrBackground
= NULL
;
3320 wndclass
.lpszMenuName
= NULL
;
3322 wndclass
.lpszClassName
= wClassName
;
3324 wndclass
.lpszClassName
= CLASSNAME
;
3327 RegisterClass(&wndclass
);
3330 while (*cmdline
&& isspace((unsigned char)*cmdline
))
3339 for (i
= 0; i
< gamecount
; i
++) {
3340 const char *p
= gamelist
[i
]->name
;
3342 while (*q
&& isspace((unsigned char)*q
))
3345 if (isspace((unsigned char)*p
)) {
3346 while (*q
&& isspace((unsigned char)*q
))
3349 if (tolower((unsigned char)*p
) !=
3350 tolower((unsigned char)*q
))
3360 while (*cmdline
&& isspace((unsigned char)*cmdline
))
3370 fe
= frontend_new(inst
);
3371 if (new_game(fe
, gg
, *cmdline
? cmdline
: NULL
, &error
)) {
3373 sprintf(buf
, "%.100s Error", gg
->name
);
3374 MessageBox(NULL
, error
, buf
, MB_OK
|MB_ICONERROR
);
3379 while (GetMessage(&msg
, NULL
, 0, 0)) {
3380 DispatchMessage(&msg
);
3387 /* vim: set shiftwidth=4 tabstop=8: */