1 /* aNetHack 0.0.1 mhsplash.c $ANH-Date: 1449751714 2015/12/10 12:48:34 $ $ANH-Branch: aNetHack-3.6.0 $:$ANH-Revision: 1.27 $ */
2 /* Copyright (C) 2001 by Alex Kompel */
3 /* aNetHack may be freely redistributed. See license for details. */
11 #include "patchlevel.h"
16 PNHWinApp
GetNHApp(void);
18 INT_PTR CALLBACK
NHSplashWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
20 #define SPLASH_WIDTH 440
21 #define SPLASH_HEIGHT 322
22 #define SPLASH_VERSION_X 290
23 #define SPLASH_VERSION_Y 10
24 #define SPLASH_OFFSET_X 10
25 #define SPLASH_OFFSET_Y 10
27 extern HFONT version_splash_font
;
30 mswin_display_splash_window(BOOL show_ver
)
41 char *buf
= malloc(bufsize
);
44 panic("out of memory");
47 hWnd
= CreateDialog(GetNHApp()->hApp
, MAKEINTRESOURCE(IDD_SPLASH
),
48 GetNHApp()->hMainWnd
, NHSplashWndProc
);
50 panic("Cannot create Splash window");
51 mswin_init_splashfonts(hWnd
);
52 GetNHApp()->hPopupWnd
= hWnd
;
53 /* Get control size */
54 GetWindowRect(GetDlgItem(hWnd
, IDOK
), &controlrt
);
55 controlrt
.right
-= controlrt
.left
;
56 controlrt
.bottom
-= controlrt
.top
;
57 /* Get current client area */
58 GetClientRect(hWnd
, &clientrt
);
60 GetWindowRect(hWnd
, &splashrt
);
61 splashrt
.right
-= splashrt
.left
;
62 splashrt
.bottom
-= splashrt
.top
;
63 /* Get difference between requested client area and current value */
64 splashrt
.right
+= SPLASH_WIDTH
+ SPLASH_OFFSET_X
* 2 - clientrt
.right
;
65 splashrt
.bottom
+= SPLASH_HEIGHT
+ controlrt
.bottom
+ SPLASH_OFFSET_Y
* 3
67 /* Place the window centered */
68 /* On the screen, not on the parent window */
69 left
= (GetSystemMetrics(SM_CXSCREEN
) - splashrt
.right
) / 2;
70 top
= (GetSystemMetrics(SM_CYSCREEN
) - splashrt
.bottom
) / 2;
71 MoveWindow(hWnd
, left
, top
, splashrt
.right
, splashrt
.bottom
, TRUE
);
72 /* Place the OK control */
73 GetClientRect(hWnd
, &clientrt
);
74 MoveWindow(GetDlgItem(hWnd
, IDOK
),
75 (clientrt
.right
- clientrt
.left
- controlrt
.right
) / 2,
76 clientrt
.bottom
- controlrt
.bottom
- SPLASH_OFFSET_Y
,
77 controlrt
.right
, controlrt
.bottom
, TRUE
);
78 buttop
= clientrt
.bottom
- controlrt
.bottom
- SPLASH_OFFSET_Y
;
79 /* Place the text control */
80 GetWindowRect(GetDlgItem(hWnd
, IDC_EXTRAINFO
), &controlrt
);
81 controlrt
.right
-= controlrt
.left
;
82 controlrt
.bottom
-= controlrt
.top
;
83 GetClientRect(hWnd
, &clientrt
);
84 MoveWindow(GetDlgItem(hWnd
, IDC_EXTRAINFO
),
85 clientrt
.left
+ SPLASH_OFFSET_X
,
86 buttop
- controlrt
.bottom
- SPLASH_OFFSET_Y
,
87 clientrt
.right
- 2 * SPLASH_OFFSET_X
, controlrt
.bottom
, TRUE
);
89 /* Fill the text control */
90 Sprintf(buf
, "%s\r\n%s\r\n%s\r\n%s\r\n\r\n", COPYRIGHT_BANNER_A
,
91 COPYRIGHT_BANNER_B
, COPYRIGHT_BANNER_C
, COPYRIGHT_BANNER_D
);
92 strsize
= strlen(buf
);
95 /* Show complete version information */
100 getversionstring(verbuf
);
101 verstrsize
= strlen(verbuf
);
102 if (verstrsize
+ strlen("\r\n\r\n") + 1 < BUFSZ
- 1)
103 strcat(verbuf
, "\r\n\r\n");
104 verstrsize
= strlen(verbuf
);
106 if (strsize
+ verstrsize
+ 1 > bufsize
) {
108 buf
= realloc(buf
, bufsize
);
110 panic("out of memory");
113 strsize
= strlen(buf
);
115 /* Add compile options */
116 f
= dlb_fopen(OPTIONS_USED
, RDTMODE
);
120 while (dlb_fgets(line
, LLEN
, f
)) {
123 if (len
> 0 && line
[len
- 1] == '\n') {
124 line
[len
- 1] = '\r';
126 line
[len
+ 1] = '\0';
129 if (strsize
+ (int) len
+ 1 > bufsize
) {
131 buf
= realloc(buf
, bufsize
);
133 panic("out of memory");
138 (void) dlb_fclose(f
);
141 /* Show news, if any */
145 iflags
.news
= 0; /* prevent newgame() from re-displaying news */
146 nf
= fopen(NEWS
, "r");
150 while (fgets(line
, LLEN
, nf
)) {
153 if (len
> 0 && line
[len
- 1] == '\n') {
154 line
[len
- 1] = '\r';
156 line
[len
+ 1] = '\0';
159 if (strsize
+ (int) len
+ 1 > bufsize
) {
161 buf
= realloc(buf
, bufsize
);
163 panic("out of memory");
170 strcat(buf
, "No news.");
174 SetWindowText(GetDlgItem(hWnd
, IDC_EXTRAINFO
), buf
);
176 ShowWindow(hWnd
, SW_SHOW
);
178 while (IsWindow(hWnd
) && GetMessage(&msg
, NULL
, 0, 0) != 0) {
179 if (!IsDialogMessage(hWnd
, &msg
)) {
180 TranslateMessage(&msg
);
181 DispatchMessage(&msg
);
185 GetNHApp()->hPopupWnd
= NULL
;
186 mswin_destroy_splashfonts();
190 NHSplashWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
194 UNREFERENCED_PARAMETER(lParam
);
198 /* set text control font */
200 SendMessage(hWnd
, WM_SETFONT
,
201 (WPARAM
) mswin_get_font(NHW_TEXT
, ATR_NONE
, hdc
, FALSE
),
203 ReleaseDC(hWnd
, hdc
);
205 SetFocus(GetDlgItem(hWnd
, IDOK
));
209 char VersionString
[BUFSZ
];
216 hdc
= BeginPaint(hWnd
, &ps
);
217 /* Show splash graphic */
219 hdcBitmap
= CreateCompatibleDC(hdc
);
220 SetBkMode(hdc
, OPAQUE
);
221 OldBitmap
= SelectObject(hdcBitmap
, GetNHApp()->bmpSplash
);
222 (*GetNHApp()->lpfnTransparentBlt
)(hdc
, SPLASH_OFFSET_X
, SPLASH_OFFSET_Y
,
223 SPLASH_WIDTH
, SPLASH_HEIGHT
, hdcBitmap
, 0,
224 0, SPLASH_WIDTH
, SPLASH_HEIGHT
,
227 SelectObject(hdcBitmap
, OldBitmap
);
230 SetBkMode(hdc
, TRANSPARENT
);
231 /* Print version number */
233 SetTextColor(hdc
, RGB(0, 0, 0));
234 rt
.right
= rt
.left
= SPLASH_VERSION_X
;
235 rt
.bottom
= rt
.top
= SPLASH_VERSION_Y
;
236 Sprintf(VersionString
, "%d.%d.%d", VERSION_MAJOR
, VERSION_MINOR
,
238 OldFont
= SelectObject(hdc
, version_splash_font
);
239 DrawText(hdc
, VersionString
, strlen(VersionString
), &rt
,
240 DT_LEFT
| DT_NOPREFIX
| DT_CALCRECT
);
241 DrawText(hdc
, VersionString
, strlen(VersionString
), &rt
,
242 DT_LEFT
| DT_NOPREFIX
);
247 switch (LOWORD(wParam
)) {
249 mswin_window_mark_dead(mswin_winid_from_handle(hWnd
));
250 if (GetNHApp()->hMainWnd
== hWnd
)
251 GetNHApp()->hMainWnd
= NULL
;
253 SetFocus(GetNHApp()->hMainWnd
);