Subversion Repositories eduke32

Rev

Rev 1188 | Rev 1221 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1188 Rev 1205
1
#ifndef RENDERTYPEWIN
1
#ifndef RENDERTYPEWIN
2
#error Only for Windows
2
#error Only for Windows
3
#endif
3
#endif
4
4
5
#include "duke3d.h"
5
#include "duke3d.h"
6
#include "sounds.h"
6
#include "sounds.h"
7
7
8
#include "build.h"
8
#include "build.h"
9
#include "winlayer.h"
9
#include "winlayer.h"
10
#include "compat.h"
10
#include "compat.h"
11
11
12
#include "grpscan.h"
12
#include "grpscan.h"
13
13
14
#define WIN32_LEAN_AND_MEAN
14
#define WIN32_LEAN_AND_MEAN
15
#include <windows.h>
15
#include <windows.h>
16
#include <windowsx.h>
16
#include <windowsx.h>
17
#ifndef _WIN32_IE
17
#ifndef _WIN32_IE
18
#define _WIN32_IE 0x0300
18
#define _WIN32_IE 0x0300
19
#endif
19
#endif
20
#include <commctrl.h>
20
#include <commctrl.h>
21
#include <stdio.h>
21
#include <stdio.h>
22
22
23
#include "startwin.game.h"
23
#include "startwin.game.h"
24
24
25
#define TAB_CONFIG 0
25
#define TAB_CONFIG 0
26
// #define TAB_GAME 1
26
// #define TAB_GAME 1
27
#define TAB_MESSAGES 1
27
#define TAB_MESSAGES 1
28
28
29
static struct audioenumdrv *wavedevs = NULL;
29
static struct audioenumdrv *wavedevs = NULL;
30
30
31
static struct
31
static struct
32
{
32
{
33
    int fullscreen;
33
    int32_t fullscreen;
34
    int xdim, ydim, bpp;
34
    int32_t xdim, ydim, bpp;
35
    int forcesetup;
35
    int32_t forcesetup;
36
    int usemouse, usejoy;
36
    int32_t usemouse, usejoy;
37
    char selectedgrp[BMAX_PATH+1];
37
    char selectedgrp[BMAX_PATH+1];
38
    int game;
38
    int32_t game;
39
    int crcval; // for finding the grp in the list again
39
    int32_t crcval; // for finding the grp in the list again
40
    char *gamedir;
40
    char *gamedir;
41
}
41
}
42
settings;
42
settings;
43
43
44
static HWND startupdlg = NULL;
44
static HWND startupdlg = NULL;
45
static HWND pages[3] =
45
static HWND pages[3] =
46
{
46
{
47
    NULL, NULL, NULL
47
    NULL, NULL, NULL
48
};
48
};
49
static int done = -1, mode = TAB_CONFIG;
49
static int32_t done = -1, mode = TAB_CONFIG;
50
50
51
static CACHE1D_FIND_REC *finddirs=NULL;
51
static CACHE1D_FIND_REC *finddirs=NULL;
52
static int numdirs=0;
52
static int32_t numdirs=0;
53
53
54
static void clearfilenames(void)
54
static void clearfilenames(void)
55
{
55
{
56
    klistfree(finddirs);
56
    klistfree(finddirs);
57
    finddirs = NULL;
57
    finddirs = NULL;
58
    numdirs = 0;
58
    numdirs = 0;
59
}
59
}
60
60
61
static int getfilenames(char *path)
61
static int32_t getfilenames(char *path)
62
{
62
{
63
    CACHE1D_FIND_REC *r;
63
    CACHE1D_FIND_REC *r;
64
64
65
    clearfilenames();
65
    clearfilenames();
66
    finddirs = klistpath(path,"*",CACHE1D_FIND_DIR);
66
    finddirs = klistpath(path,"*",CACHE1D_FIND_DIR);
67
    for (r = finddirs; r; r=r->next) numdirs++;
67
    for (r = finddirs; r; r=r->next) numdirs++;
68
    return(0);
68
    return(0);
69
}
69
}
70
70
71
#define POPULATE_VIDEO 1
71
#define POPULATE_VIDEO 1
72
#define POPULATE_CONFIG 2
72
#define POPULATE_CONFIG 2
73
#define POPULATE_GAME 4
73
#define POPULATE_GAME 4
74
#define POPULATE_GAMEDIRS 8
74
#define POPULATE_GAMEDIRS 8
75
75
76
#if defined(POLYMOST)
76
#if defined(POLYMOST)
77
extern char TEXCACHEFILE[];
77
extern char TEXCACHEFILE[];
78
#endif
78
#endif
79
79
80
extern int g_noSetup;
80
extern int32_t g_noSetup;
81
81
82
static void PopulateForm(int pgs)
82
static void PopulateForm(int32_t pgs)
83
{
83
{
84
    HWND hwnd;
84
    HWND hwnd;
85
    char buf[256];
85
    char buf[256];
86
    int i,j;
86
    int32_t i,j;
87
87
88
    if (pgs & POPULATE_VIDEO)
88
    if (pgs & POPULATE_VIDEO)
89
    {
89
    {
90
        int mode;
90
        int32_t mode;
91
91
92
        hwnd = GetDlgItem(pages[TAB_CONFIG], IDCVMODE);
92
        hwnd = GetDlgItem(pages[TAB_CONFIG], IDCVMODE);
93
93
94
        mode = checkvideomode(&settings.xdim, &settings.ydim, settings.bpp, settings.fullscreen, 1);
94
        mode = checkvideomode(&settings.xdim, &settings.ydim, settings.bpp, settings.fullscreen, 1);
95
        if (mode < 0)
95
        if (mode < 0)
96
        {
96
        {
97
            int cd[] = { 32, 24, 16, 15, 8, 0 };
97
            int32_t cd[] = { 32, 24, 16, 15, 8, 0 };
98
            for (i=0; cd[i];)
98
            for (i=0; cd[i];)
99
            {
99
            {
100
                if (cd[i] >= settings.bpp) i++;
100
                if (cd[i] >= settings.bpp) i++;
101
                else break;
101
                else break;
102
            }
102
            }
103
            for (; cd[i]; i++)
103
            for (; cd[i]; i++)
104
            {
104
            {
105
                mode = checkvideomode(&settings.xdim, &settings.ydim, cd[i], settings.fullscreen, 1);
105
                mode = checkvideomode(&settings.xdim, &settings.ydim, cd[i], settings.fullscreen, 1);
106
                if (mode < 0) continue;
106
                if (mode < 0) continue;
107
                settings.bpp = cd[i];
107
                settings.bpp = cd[i];
108
                break;
108
                break;
109
            }
109
            }
110
        }
110
        }
111
111
112
        Button_SetCheck(GetDlgItem(pages[TAB_CONFIG], IDCFULLSCREEN), (settings.fullscreen ? BST_CHECKED : BST_UNCHECKED));
112
        Button_SetCheck(GetDlgItem(pages[TAB_CONFIG], IDCFULLSCREEN), (settings.fullscreen ? BST_CHECKED : BST_UNCHECKED));
113
        (void)ComboBox_ResetContent(hwnd);
113
        (void)ComboBox_ResetContent(hwnd);
114
        for (i=0; i<validmodecnt; i++)
114
        for (i=0; i<validmodecnt; i++)
115
        {
115
        {
116
            if (validmode[i].fs != settings.fullscreen) continue;
116
            if (validmode[i].fs != settings.fullscreen) continue;
117
117
118
            // all modes get added to the 3D mode list
118
            // all modes get added to the 3D mode list
119
            Bsprintf(buf, "%d x %d %dbpp", validmode[i].xdim, validmode[i].ydim, validmode[i].bpp);
119
            Bsprintf(buf, "%d x %d %dbpp", validmode[i].xdim, validmode[i].ydim, validmode[i].bpp);
120
            j = ComboBox_AddString(hwnd, buf);
120
            j = ComboBox_AddString(hwnd, buf);
121
            (void)ComboBox_SetItemData(hwnd, j, i);
121
            (void)ComboBox_SetItemData(hwnd, j, i);
122
            if (i == mode)(void)ComboBox_SetCurSel(hwnd, j);
122
            if (i == mode)(void)ComboBox_SetCurSel(hwnd, j);
123
        }
123
        }
124
    }
124
    }
125
125
126
    if (pgs & POPULATE_CONFIG)
126
    if (pgs & POPULATE_CONFIG)
127
    {
127
    {
128
        struct audioenumdev *d;
128
        struct audioenumdev *d;
129
        char *n;
129
        char *n;
130
130
131
        hwnd = GetDlgItem(pages[TAB_CONFIG], IDCSOUNDDRV);
131
        hwnd = GetDlgItem(pages[TAB_CONFIG], IDCSOUNDDRV);
132
        (void)ComboBox_ResetContent(hwnd);
132
        (void)ComboBox_ResetContent(hwnd);
133
        if (wavedevs)
133
        if (wavedevs)
134
        {
134
        {
135
            d = wavedevs->devs;
135
            d = wavedevs->devs;
136
            for (i=0; wavedevs->drvs[i]; i++)
136
            for (i=0; wavedevs->drvs[i]; i++)
137
            {
137
            {
138
                strcpy(buf, wavedevs->drvs[i]);
138
                strcpy(buf, wavedevs->drvs[i]);
139
                if (d->devs)
139
                if (d->devs)
140
                {
140
                {
141
                    strcat(buf, ":");
141
                    strcat(buf, ":");
142
                    n = buf + strlen(buf);
142
                    n = buf + strlen(buf);
143
                    for (j=0; d->devs[j]; j++)
143
                    for (j=0; d->devs[j]; j++)
144
                    {
144
                    {
145
                        strcpy(n, d->devs[j]);
145
                        strcpy(n, d->devs[j]);
146
                        (void)ComboBox_AddString(hwnd, buf);
146
                        (void)ComboBox_AddString(hwnd, buf);
147
                    }
147
                    }
148
                }
148
                }
149
                else
149
                else
150
                {
150
                {
151
                    (void)ComboBox_AddString(hwnd, buf);
151
                    (void)ComboBox_AddString(hwnd, buf);
152
                }
152
                }
153
                d = d->next;
153
                d = d->next;
154
            }
154
            }
155
        }
155
        }
156
156
157
        Button_SetCheck(GetDlgItem(pages[TAB_CONFIG], IDCALWAYSSHOW), (settings.forcesetup ? BST_CHECKED : BST_UNCHECKED));
157
        Button_SetCheck(GetDlgItem(pages[TAB_CONFIG], IDCALWAYSSHOW), (settings.forcesetup ? BST_CHECKED : BST_UNCHECKED));
158
158
159
        Button_SetCheck(GetDlgItem(pages[TAB_CONFIG], IDCINPUTMOUSE), (settings.usemouse ? BST_CHECKED : BST_UNCHECKED));
159
        Button_SetCheck(GetDlgItem(pages[TAB_CONFIG], IDCINPUTMOUSE), (settings.usemouse ? BST_CHECKED : BST_UNCHECKED));
160
        Button_SetCheck(GetDlgItem(pages[TAB_CONFIG], IDCINPUTJOY), (settings.usejoy ? BST_CHECKED : BST_UNCHECKED));
160
        Button_SetCheck(GetDlgItem(pages[TAB_CONFIG], IDCINPUTJOY), (settings.usejoy ? BST_CHECKED : BST_UNCHECKED));
161
    }
161
    }
162
162
163
    if (pgs & POPULATE_GAME)
163
    if (pgs & POPULATE_GAME)
164
    {
164
    {
165
        struct grpfile *fg;
165
        struct grpfile *fg;
166
        int i, j;
166
        int32_t i, j;
167
        char buf[128+BMAX_PATH];
167
        char buf[128+BMAX_PATH];
168
168
169
        hwnd = GetDlgItem(pages[TAB_CONFIG], IDCDATA);
169
        hwnd = GetDlgItem(pages[TAB_CONFIG], IDCDATA);
170
170
171
        for (fg = foundgrps; fg; fg=fg->next)
171
        for (fg = foundgrps; fg; fg=fg->next)
172
        {
172
        {
173
            for (i = 0; i<numgrpfiles; i++) if (fg->crcval == grpfiles[i].crcval) break;
173
            for (i = 0; i<numgrpfiles; i++) if (fg->crcval == grpfiles[i].crcval) break;
174
            if (i == numgrpfiles) continue;     // unrecognised grp file
174
            if (i == numgrpfiles) continue;     // unrecognised grp file
175
            Bsprintf(buf, "%s\t%s", grpfiles[i].name, fg->name);
175
            Bsprintf(buf, "%s\t%s", grpfiles[i].name, fg->name);
176
            j = ListBox_AddString(hwnd, buf);
176
            j = ListBox_AddString(hwnd, buf);
177
            (void)ListBox_SetItemData(hwnd, j, (LPARAM)fg);
177
            (void)ListBox_SetItemData(hwnd, j, (LPARAM)fg);
178
            if (!Bstrcasecmp(fg->name, settings.selectedgrp))(void)ListBox_SetCurSel(hwnd, j);
178
            if (!Bstrcasecmp(fg->name, settings.selectedgrp))(void)ListBox_SetCurSel(hwnd, j);
179
        }
179
        }
180
    }
180
    }
181
181
182
    if (pgs & POPULATE_GAMEDIRS)
182
    if (pgs & POPULATE_GAMEDIRS)
183
    {
183
    {
184
        CACHE1D_FIND_REC *dirs = NULL;
184
        CACHE1D_FIND_REC *dirs = NULL;
185
185
186
        hwnd = GetDlgItem(pages[TAB_CONFIG], IDCGAMEDIR);
186
        hwnd = GetDlgItem(pages[TAB_CONFIG], IDCGAMEDIR);
187
187
188
        getfilenames("/");
188
        getfilenames("/");
189
        (void)ComboBox_ResetContent(hwnd);
189
        (void)ComboBox_ResetContent(hwnd);
190
        j = ComboBox_AddString(hwnd, "None");
190
        j = ComboBox_AddString(hwnd, "None");
191
        (void)ComboBox_SetItemData(hwnd, j, 0);
191
        (void)ComboBox_SetItemData(hwnd, j, 0);
192
        (void)ComboBox_SetCurSel(hwnd, j);
192
        (void)ComboBox_SetCurSel(hwnd, j);
193
        for (dirs=finddirs,i=1; dirs != NULL; dirs=dirs->next,i++)
193
        for (dirs=finddirs,i=1; dirs != NULL; dirs=dirs->next,i++)
194
        {
194
        {
195
#if defined(POLYMOST) && defined(USE_OPENGL)
195
#if defined(POLYMOST) && defined(USE_OPENGL)
196
            if (Bstrcasecmp(TEXCACHEFILE,dirs->name) == 0) continue;
196
            if (Bstrcasecmp(TEXCACHEFILE,dirs->name) == 0) continue;
197
#endif
197
#endif
198
            j = ComboBox_AddString(hwnd, dirs->name);
198
            j = ComboBox_AddString(hwnd, dirs->name);
199
            (void)ComboBox_SetItemData(hwnd, j, i);
199
            (void)ComboBox_SetItemData(hwnd, j, i);
200
            if (Bstrcasecmp(dirs->name,settings.gamedir) == 0)
200
            if (Bstrcasecmp(dirs->name,settings.gamedir) == 0)
201
                (void)ComboBox_SetCurSel(hwnd, j);
201
                (void)ComboBox_SetCurSel(hwnd, j);
202
        }
202
        }
203
    }
203
    }
204
}
204
}
205
205
206
static INT_PTR CALLBACK ConfigPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
206
static INT_PTR CALLBACK ConfigPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
207
{
207
{
208
    switch (uMsg)
208
    switch (uMsg)
209
    {
209
    {
210
    case WM_COMMAND:
210
    case WM_COMMAND:
211
        switch (LOWORD(wParam))
211
        switch (LOWORD(wParam))
212
        {
212
        {
213
        case IDCFULLSCREEN:
213
        case IDCFULLSCREEN:
214
            settings.fullscreen = !settings.fullscreen;
214
            settings.fullscreen = !settings.fullscreen;
215
            PopulateForm(POPULATE_VIDEO);
215
            PopulateForm(POPULATE_VIDEO);
216
            return TRUE;
216
            return TRUE;
217
        case IDCVMODE:
217
        case IDCVMODE:
218
            if (HIWORD(wParam) == CBN_SELCHANGE)
218
            if (HIWORD(wParam) == CBN_SELCHANGE)
219
            {
219
            {
220
                int i;
220
                int32_t i;
221
                i = ComboBox_GetCurSel((HWND)lParam);
221
                i = ComboBox_GetCurSel((HWND)lParam);
222
                if (i != CB_ERR) i = ComboBox_GetItemData((HWND)lParam, i);
222
                if (i != CB_ERR) i = ComboBox_GetItemData((HWND)lParam, i);
223
                if (i != CB_ERR)
223
                if (i != CB_ERR)
224
                {
224
                {
225
                    settings.xdim = validmode[i].xdim;
225
                    settings.xdim = validmode[i].xdim;
226
                    settings.ydim = validmode[i].ydim;
226
                    settings.ydim = validmode[i].ydim;
227
                    settings.bpp  = validmode[i].bpp;
227
                    settings.bpp  = validmode[i].bpp;
228
                }
228
                }
229
            }
229
            }
230
            return TRUE;
230
            return TRUE;
231
        case IDCALWAYSSHOW:
231
        case IDCALWAYSSHOW:
232
            settings.forcesetup = IsDlgButtonChecked(hwndDlg, IDCALWAYSSHOW) == BST_CHECKED;
232
            settings.forcesetup = IsDlgButtonChecked(hwndDlg, IDCALWAYSSHOW) == BST_CHECKED;
233
            return TRUE;
233
            return TRUE;
234
        case IDCINPUTMOUSE:
234
        case IDCINPUTMOUSE:
235
            settings.usemouse = IsDlgButtonChecked(hwndDlg, IDCINPUTMOUSE) == BST_CHECKED;
235
            settings.usemouse = IsDlgButtonChecked(hwndDlg, IDCINPUTMOUSE) == BST_CHECKED;
236
            return TRUE;
236
            return TRUE;
237
        case IDCINPUTJOY:
237
        case IDCINPUTJOY:
238
            settings.usejoy = IsDlgButtonChecked(hwndDlg, IDCINPUTJOY) == BST_CHECKED;
238
            settings.usejoy = IsDlgButtonChecked(hwndDlg, IDCINPUTJOY) == BST_CHECKED;
239
            return TRUE;
239
            return TRUE;
240
        case IDCGAMEDIR:
240
        case IDCGAMEDIR:
241
            if (HIWORD(wParam) == CBN_SELCHANGE)
241
            if (HIWORD(wParam) == CBN_SELCHANGE)
242
            {
242
            {
243
                int i,j;
243
                int32_t i,j;
244
                CACHE1D_FIND_REC *dir = NULL;
244
                CACHE1D_FIND_REC *dir = NULL;
245
                i = ComboBox_GetCurSel((HWND)lParam);
245
                i = ComboBox_GetCurSel((HWND)lParam);
246
                if (i != CB_ERR) i = ComboBox_GetItemData((HWND)lParam, i);
246
                if (i != CB_ERR) i = ComboBox_GetItemData((HWND)lParam, i);
247
                if (i != CB_ERR)
247
                if (i != CB_ERR)
248
                {
248
                {
249
                    if (i==0)
249
                    if (i==0)
250
                        settings.gamedir = NULL;
250
                        settings.gamedir = NULL;
251
                    else
251
                    else
252
                    {
252
                    {
253
                        for (j=1,dir=finddirs;dir != NULL;dir=dir->next,j++)
253
                        for (j=1,dir=finddirs;dir != NULL;dir=dir->next,j++)
254
                            if (j == i)
254
                            if (j == i)
255
                            {
255
                            {
256
                                settings.gamedir = dir->name;
256
                                settings.gamedir = dir->name;
257
                                break;
257
                                break;
258
                            }
258
                            }
259
                    }
259
                    }
260
                }
260
                }
261
            }
261
            }
262
            return TRUE;
262
            return TRUE;
263
        case IDCDATA:
263
        case IDCDATA:
264
        {
264
        {
265
            int i;
265
            int32_t i;
266
            if (HIWORD(wParam) != LBN_SELCHANGE) break;
266
            if (HIWORD(wParam) != LBN_SELCHANGE) break;
267
            i = ListBox_GetCurSel((HWND)lParam);
267
            i = ListBox_GetCurSel((HWND)lParam);
268
            if (i != CB_ERR) i = ListBox_GetItemData((HWND)lParam, i);
268
            if (i != CB_ERR) i = ListBox_GetItemData((HWND)lParam, i);
269
            if (i != CB_ERR)
269
            if (i != CB_ERR)
270
            {
270
            {
271
                strcpy(settings.selectedgrp, ((struct grpfile*)i)->name);
271
                strcpy(settings.selectedgrp, ((struct grpfile*)i)->name);
272
                settings.game = ((struct grpfile*)i)->game;
272
                settings.game = ((struct grpfile*)i)->game;
273
                settings.crcval = ((struct grpfile*)i)->crcval;
273
                settings.crcval = ((struct grpfile*)i)->crcval;
274
            }
274
            }
275
            return TRUE;
275
            return TRUE;
276
        }
276
        }
277
        default:
277
        default:
278
            break;
278
            break;
279
        }
279
        }
280
        break;
280
        break;
281
    default:
281
    default:
282
        break;
282
        break;
283
    }
283
    }
284
    return FALSE;
284
    return FALSE;
285
}
285
}
286
286
287
287
288
static void SetPage(int n)
288
static void SetPage(int32_t n)
289
{
289
{
290
    HWND tab;
290
    HWND tab;
291
    int cur;
291
    int32_t cur;
292
    tab = GetDlgItem(startupdlg, WIN_STARTWIN_TABCTL);
292
    tab = GetDlgItem(startupdlg, WIN_STARTWIN_TABCTL);
293
    cur = (int)SendMessage(tab, TCM_GETCURSEL,0,0);
293
    cur = (int32_t)SendMessage(tab, TCM_GETCURSEL,0,0);
294
    ShowWindow(pages[cur],SW_HIDE);
294
    ShowWindow(pages[cur],SW_HIDE);
295
    SendMessage(tab, TCM_SETCURSEL, n, 0);
295
    SendMessage(tab, TCM_SETCURSEL, n, 0);
296
    ShowWindow(pages[n],SW_SHOW);
296
    ShowWindow(pages[n],SW_SHOW);
297
    mode = n;
297
    mode = n;
298
298
299
    SetFocus(GetDlgItem(startupdlg, WIN_STARTWIN_TABCTL));
299
    SetFocus(GetDlgItem(startupdlg, WIN_STARTWIN_TABCTL));
300
}
300
}
301
301
302
static void EnableConfig(int n)
302
static void EnableConfig(int32_t n)
303
{
303
{
304
    //EnableWindow(GetDlgItem(startupdlg, WIN_STARTWIN_CANCEL), n);
304
    //EnableWindow(GetDlgItem(startupdlg, WIN_STARTWIN_CANCEL), n);
305
    EnableWindow(GetDlgItem(startupdlg, WIN_STARTWIN_START), n);
305
    EnableWindow(GetDlgItem(startupdlg, WIN_STARTWIN_START), n);
306
    EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCFULLSCREEN), n);
306
    EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCFULLSCREEN), n);
307
    EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCVMODE), n);
307
    EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCVMODE), n);
308
    EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCINPUTMOUSE), n);
308
    EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCINPUTMOUSE), n);
309
    EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCINPUTJOY), n);
309
    EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCINPUTJOY), n);
310
310
311
    EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCDATA), n);
311
    EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCDATA), n);
312
    EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCGAMEDIR), n);
312
    EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCGAMEDIR), n);
313
}
313
}
314
314
315
static INT_PTR CALLBACK startup_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
315
static INT_PTR CALLBACK startup_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
316
{
316
{
317
    static HBITMAP hbmp = NULL;
317
    static HBITMAP hbmp = NULL;
318
    HDC hdc;
318
    HDC hdc;
319
319
320
    switch (uMsg)
320
    switch (uMsg)
321
    {
321
    {
322
    case WM_INITDIALOG:
322
    case WM_INITDIALOG:
323
    {
323
    {
324
        HWND hwnd;
324
        HWND hwnd;
325
        RECT r, rdlg, chrome, rtab, rcancel, rstart;
325
        RECT r, rdlg, chrome, rtab, rcancel, rstart;
326
        int xoffset = 0, yoffset = 0;
326
        int32_t xoffset = 0, yoffset = 0;
327
327
328
        // Fetch the positions (in screen coordinates) of all the windows we need to tweak
328
        // Fetch the positions (in screen coordinates) of all the windows we need to tweak
329
        ZeroMemory(&chrome, sizeof(chrome));
329
        ZeroMemory(&chrome, sizeof(chrome));
330
        AdjustWindowRect(&chrome, GetWindowLong(hwndDlg, GWL_STYLE), FALSE);
330
        AdjustWindowRect(&chrome, GetWindowLong(hwndDlg, GWL_STYLE), FALSE);
331
        GetWindowRect(hwndDlg, &rdlg);
331
        GetWindowRect(hwndDlg, &rdlg);
332
        GetWindowRect(GetDlgItem(hwndDlg, WIN_STARTWIN_TABCTL), &rtab);
332
        GetWindowRect(GetDlgItem(hwndDlg, WIN_STARTWIN_TABCTL), &rtab);
333
        GetWindowRect(GetDlgItem(hwndDlg, WIN_STARTWIN_CANCEL), &rcancel);
333
        GetWindowRect(GetDlgItem(hwndDlg, WIN_STARTWIN_CANCEL), &rcancel);
334
        GetWindowRect(GetDlgItem(hwndDlg, WIN_STARTWIN_START), &rstart);
334
        GetWindowRect(GetDlgItem(hwndDlg, WIN_STARTWIN_START), &rstart);
335
335
336
        // Knock off the non-client area of the main dialogue to give just the client area
336
        // Knock off the non-client area of the main dialogue to give just the client area
337
        rdlg.left -= chrome.left;
337
        rdlg.left -= chrome.left;
338
        rdlg.top -= chrome.top;
338
        rdlg.top -= chrome.top;
339
        rdlg.right -= chrome.right;
339
        rdlg.right -= chrome.right;
340
        rdlg.bottom -= chrome.bottom;
340
        rdlg.bottom -= chrome.bottom;
341
341
342
        // Translate them to client-relative coordinates wrt the main dialogue window
342
        // Translate them to client-relative coordinates wrt the main dialogue window
343
        rtab.right -= rtab.left - 1;
343
        rtab.right -= rtab.left - 1;
344
        rtab.bottom -= rtab.top - 1;
344
        rtab.bottom -= rtab.top - 1;
345
        rtab.left  -= rdlg.left;
345
        rtab.left  -= rdlg.left;
346
        rtab.top -= rdlg.top;
346
        rtab.top -= rdlg.top;
347
347
348
        rcancel.right -= rcancel.left - 1;
348
        rcancel.right -= rcancel.left - 1;
349
        rcancel.bottom -= rcancel.top - 1;
349
        rcancel.bottom -= rcancel.top - 1;
350
        rcancel.left -= rdlg.left;
350
        rcancel.left -= rdlg.left;
351
        rcancel.top -= rdlg.top;
351
        rcancel.top -= rdlg.top;
352
352
353
        rstart.right -= rstart.left - 1;
353
        rstart.right -= rstart.left - 1;
354
        rstart.bottom -= rstart.top - 1;
354
        rstart.bottom -= rstart.top - 1;
355
        rstart.left -= rdlg.left;
355
        rstart.left -= rdlg.left;
356
        rstart.top -= rdlg.top;
356
        rstart.top -= rdlg.top;
357
357
358
        // And then convert the main dialogue coordinates to just width/length
358
        // And then convert the main dialogue coordinates to just width/length
359
        rdlg.right -= rdlg.left - 1;
359
        rdlg.right -= rdlg.left - 1;
360
        rdlg.bottom -= rdlg.top - 1;
360
        rdlg.bottom -= rdlg.top - 1;
361
        rdlg.left = 0;
361
        rdlg.left = 0;
362
        rdlg.top = 0;
362
        rdlg.top = 0;
363
363
364
        // Load the bitmap into the bitmap control and fetch its dimensions
364
        // Load the bitmap into the bitmap control and fetch its dimensions
365
        hbmp = LoadBitmap((HINSTANCE)win_gethinstance(), MAKEINTRESOURCE(RSRC_BMP));
365
        hbmp = LoadBitmap((HINSTANCE)win_gethinstance(), MAKEINTRESOURCE(RSRC_BMP));
366
        hwnd = GetDlgItem(hwndDlg,WIN_STARTWIN_BITMAP);
366
        hwnd = GetDlgItem(hwndDlg,WIN_STARTWIN_BITMAP);
367
        SendMessage(hwnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hbmp);
367
        SendMessage(hwnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hbmp);
368
        GetClientRect(hwnd, &r);
368
        GetClientRect(hwnd, &r);
369
        xoffset = r.right;
369
        xoffset = r.right;
370
        yoffset = r.bottom - rdlg.bottom;
370
        yoffset = r.bottom - rdlg.bottom;
371
371
372
        // Shift and resize the controls that require it
372
        // Shift and resize the controls that require it
373
        rtab.left += xoffset;
373
        rtab.left += xoffset;
374
        rtab.bottom += yoffset;
374
        rtab.bottom += yoffset;
375
        rcancel.left += xoffset;
375
        rcancel.left += xoffset;
376
        rcancel.top += yoffset;
376
        rcancel.top += yoffset;
377
        rstart.left += xoffset;
377
        rstart.left += xoffset;
378
        rstart.top += yoffset;
378
        rstart.top += yoffset;
379
        rdlg.right += xoffset;
379
        rdlg.right += xoffset;
380
        rdlg.bottom += yoffset;
380
        rdlg.bottom += yoffset;
381
381
382
        // Move the controls to their new positions
382
        // Move the controls to their new positions
383
        MoveWindow(GetDlgItem(hwndDlg, WIN_STARTWIN_TABCTL), rtab.left, rtab.top, rtab.right, rtab.bottom, FALSE);
383
        MoveWindow(GetDlgItem(hwndDlg, WIN_STARTWIN_TABCTL), rtab.left, rtab.top, rtab.right, rtab.bottom, FALSE);
384
        MoveWindow(GetDlgItem(hwndDlg, WIN_STARTWIN_CANCEL), rcancel.left, rcancel.top, rcancel.right, rcancel.bottom, FALSE);
384
        MoveWindow(GetDlgItem(hwndDlg, WIN_STARTWIN_CANCEL), rcancel.left, rcancel.top, rcancel.right, rcancel.bottom, FALSE);
385
        MoveWindow(GetDlgItem(hwndDlg, WIN_STARTWIN_START), rstart.left, rstart.top, rstart.right, rstart.bottom, FALSE);
385
        MoveWindow(GetDlgItem(hwndDlg, WIN_STARTWIN_START), rstart.left, rstart.top, rstart.right, rstart.bottom, FALSE);
386
386
387
        // Move the main dialogue to the centre of the screen
387
        // Move the main dialogue to the centre of the screen
388
        hdc = GetDC(NULL);
388
        hdc = GetDC(NULL);
389
        rdlg.left = (GetDeviceCaps(hdc, HORZRES) - rdlg.right) / 2;
389
        rdlg.left = (GetDeviceCaps(hdc, HORZRES) - rdlg.right) / 2;
390
        rdlg.top = (GetDeviceCaps(hdc, VERTRES) - rdlg.bottom) / 2;
390
        rdlg.top = (GetDeviceCaps(hdc, VERTRES) - rdlg.bottom) / 2;
391
        ReleaseDC(NULL, hdc);
391
        ReleaseDC(NULL, hdc);
392
        MoveWindow(hwndDlg, rdlg.left + chrome.left, rdlg.top + chrome.left,
392
        MoveWindow(hwndDlg, rdlg.left + chrome.left, rdlg.top + chrome.left,
393
                   rdlg.right + (-chrome.left+chrome.right), rdlg.bottom + (-chrome.top+chrome.bottom), TRUE);
393
                   rdlg.right + (-chrome.left+chrome.right), rdlg.bottom + (-chrome.top+chrome.bottom), TRUE);
394
394
395
        // Add tabs to the tab control
395
        // Add tabs to the tab control
396
        {
396
        {
397
            TCITEM tab;
397
            TCITEM tab;
398
398
399
            hwnd = GetDlgItem(hwndDlg, WIN_STARTWIN_TABCTL);
399
            hwnd = GetDlgItem(hwndDlg, WIN_STARTWIN_TABCTL);
400
400
401
            ZeroMemory(&tab, sizeof(tab));
401
            ZeroMemory(&tab, sizeof(tab));
402
            tab.mask = TCIF_TEXT;
402
            tab.mask = TCIF_TEXT;
403
            tab.pszText = TEXT("Setup");
403
            tab.pszText = TEXT("Setup");
404
            SendMessage(hwnd, TCM_INSERTITEM, (WPARAM)TAB_CONFIG, (LPARAM)&tab);
404
            SendMessage(hwnd, TCM_INSERTITEM, (WPARAM)TAB_CONFIG, (LPARAM)&tab);
405
            tab.mask = TCIF_TEXT;
405
            tab.mask = TCIF_TEXT;
406
            tab.pszText = TEXT("Message Log");
406
            tab.pszText = TEXT("Message Log");
407
            SendMessage(hwnd, TCM_INSERTITEM, (WPARAM)TAB_MESSAGES, (LPARAM)&tab);
407
            SendMessage(hwnd, TCM_INSERTITEM, (WPARAM)TAB_MESSAGES, (LPARAM)&tab);
408
408
409
            // Work out the position and size of the area inside the tab control for the pages
409
            // Work out the position and size of the area inside the tab control for the pages
410
            ZeroMemory(&r, sizeof(r));
410
            ZeroMemory(&r, sizeof(r));
411
            GetClientRect(hwnd, &r);
411
            GetClientRect(hwnd, &r);
412
            SendMessage(hwnd, TCM_ADJUSTRECT, FALSE, (LPARAM)&r);
412
            SendMessage(hwnd, TCM_ADJUSTRECT, FALSE, (LPARAM)&r);
413
            r.right -= r.left-1;
413
            r.right -= r.left-1;
414
            r.bottom -= r.top-1;
414
            r.bottom -= r.top-1;
415
            r.top += rtab.top;
415
            r.top += rtab.top;
416
            r.left += rtab.left;
416
            r.left += rtab.left;
417
417
418
            // Create the pages and position them in the tab control, but hide them
418
            // Create the pages and position them in the tab control, but hide them
419
            pages[TAB_CONFIG] = CreateDialog((HINSTANCE)win_gethinstance(),
419
            pages[TAB_CONFIG] = CreateDialog((HINSTANCE)win_gethinstance(),
420
                                             MAKEINTRESOURCE(WIN_STARTWINPAGE_CONFIG), hwndDlg, ConfigPageProc);
420
                                             MAKEINTRESOURCE(WIN_STARTWINPAGE_CONFIG), hwndDlg, ConfigPageProc);
421
            pages[TAB_MESSAGES] = GetDlgItem(hwndDlg, WIN_STARTWIN_MESSAGES);
421
            pages[TAB_MESSAGES] = GetDlgItem(hwndDlg, WIN_STARTWIN_MESSAGES);
422
            SetWindowPos(pages[TAB_CONFIG], hwnd,r.left,r.top,r.right,r.bottom,SWP_HIDEWINDOW);
422
            SetWindowPos(pages[TAB_CONFIG], hwnd,r.left,r.top,r.right,r.bottom,SWP_HIDEWINDOW);
423
            SetWindowPos(pages[TAB_MESSAGES], hwnd,r.left,r.top,r.right,r.bottom,SWP_HIDEWINDOW);
423
            SetWindowPos(pages[TAB_MESSAGES], hwnd,r.left,r.top,r.right,r.bottom,SWP_HIDEWINDOW);
424
424
425
            // Tell the editfield acting as the console to exclude the width of the scrollbar
425
            // Tell the editfield acting as the console to exclude the width of the scrollbar
426
            GetClientRect(pages[TAB_MESSAGES],&r);
426
            GetClientRect(pages[TAB_MESSAGES],&r);
427
            r.right -= GetSystemMetrics(SM_CXVSCROLL)+4;
427
            r.right -= GetSystemMetrics(SM_CXVSCROLL)+4;
428
            r.left = r.top = 0;
428
            r.left = r.top = 0;
429
            SendMessage(pages[TAB_MESSAGES], EM_SETRECTNP,0,(LPARAM)&r);
429
            SendMessage(pages[TAB_MESSAGES], EM_SETRECTNP,0,(LPARAM)&r);
430
430
431
            // Set a tab stop in the game data listbox
431
            // Set a tab stop in the game data listbox
432
            {
432
            {
433
                DWORD tabs[1] = { 150 };
433
                DWORD tabs[1] = { 150 };
434
                (void)ListBox_SetTabStops(GetDlgItem(pages[TAB_CONFIG], IDCDATA), 1, tabs);
434
                (void)ListBox_SetTabStops(GetDlgItem(pages[TAB_CONFIG], IDCDATA), 1, tabs);
435
            }
435
            }
436
436
437
            SetFocus(GetDlgItem(hwndDlg, WIN_STARTWIN_START));
437
            SetFocus(GetDlgItem(hwndDlg, WIN_STARTWIN_START));
438
            SetWindowText(hwndDlg, apptitle);
438
            SetWindowText(hwndDlg, apptitle);
439
        }
439
        }
440
        return FALSE;
440
        return FALSE;
441
    }
441
    }
442
442
443
    case WM_NOTIFY:
443
    case WM_NOTIFY:
444
    {
444
    {
445
        LPNMHDR nmhdr = (LPNMHDR)lParam;
445
        LPNMHDR nmhdr = (LPNMHDR)lParam;
446
        int cur;
446
        int32_t cur;
447
        if (nmhdr->idFrom != WIN_STARTWIN_TABCTL) break;
447
        if (nmhdr->idFrom != WIN_STARTWIN_TABCTL) break;
448
        cur = (int)SendMessage(nmhdr->hwndFrom, TCM_GETCURSEL,0,0);
448
        cur = (int32_t)SendMessage(nmhdr->hwndFrom, TCM_GETCURSEL,0,0);
449
        switch (nmhdr->code)
449
        switch (nmhdr->code)
450
        {
450
        {
451
        case TCN_SELCHANGING:
451
        case TCN_SELCHANGING:
452
        {
452
        {
453
            if (cur < 0 || !pages[cur]) break;
453
            if (cur < 0 || !pages[cur]) break;
454
            ShowWindow(pages[cur],SW_HIDE);
454
            ShowWindow(pages[cur],SW_HIDE);
455
            return TRUE;
455
            return TRUE;
456
        }
456
        }
457
        case TCN_SELCHANGE:
457
        case TCN_SELCHANGE:
458
        {
458
        {
459
            if (cur < 0 || !pages[cur]) break;
459
            if (cur < 0 || !pages[cur]) break;
460
            ShowWindow(pages[cur],SW_SHOW);
460
            ShowWindow(pages[cur],SW_SHOW);
461
            return TRUE;
461
            return TRUE;
462
        }
462
        }
463
        }
463
        }
464
        break;
464
        break;
465
    }
465
    }
466
466
467
    case WM_CLOSE:
467
    case WM_CLOSE:
468
        if (mode == TAB_CONFIG) done = 0;
468
        if (mode == TAB_CONFIG) done = 0;
469
        else quitevent++;
469
        else quitevent++;
470
        return TRUE;
470
        return TRUE;
471
471
472
    case WM_DESTROY:
472
    case WM_DESTROY:
473
        if (hbmp)
473
        if (hbmp)
474
        {
474
        {
475
            DeleteObject(hbmp);
475
            DeleteObject(hbmp);
476
            hbmp = NULL;
476
            hbmp = NULL;
477
        }
477
        }
478
478
479
        if (pages[TAB_CONFIG])
479
        if (pages[TAB_CONFIG])
480
        {
480
        {
481
            DestroyWindow(pages[TAB_CONFIG]);
481
            DestroyWindow(pages[TAB_CONFIG]);
482
            pages[TAB_CONFIG] = NULL;
482
            pages[TAB_CONFIG] = NULL;
483
        }
483
        }
484
484
485
        startupdlg = NULL;
485
        startupdlg = NULL;
486
        return TRUE;
486
        return TRUE;
487
487
488
    case WM_COMMAND:
488
    case WM_COMMAND:
489
        switch (LOWORD(wParam))
489
        switch (LOWORD(wParam))
490
        {
490
        {
491
        case WIN_STARTWIN_CANCEL:
491
        case WIN_STARTWIN_CANCEL:
492
            if (mode == TAB_CONFIG) done = 0;
492
            if (mode == TAB_CONFIG) done = 0;
493
            else quitevent++;
493
            else quitevent++;
494
            return TRUE;
494
            return TRUE;
495
        case WIN_STARTWIN_START:
495
        case WIN_STARTWIN_START:
496
            done = 1;
496
            done = 1;
497
            return TRUE;
497
            return TRUE;
498
        }
498
        }
499
        return FALSE;
499
        return FALSE;
500
500
501
    case WM_CTLCOLORSTATIC:
501
    case WM_CTLCOLORSTATIC:
502
        if ((HWND)lParam == pages[TAB_MESSAGES])
502
        if ((HWND)lParam == pages[TAB_MESSAGES])
503
            return (BOOL)GetSysColorBrush(COLOR_WINDOW);
503
            return (BOOL)GetSysColorBrush(COLOR_WINDOW);
504
        break;
504
        break;
505
505
506
    default:
506
    default:
507
        break;
507
        break;
508
    }
508
    }
509
509
510
    return FALSE;
510
    return FALSE;
511
}
511
}
512
512
513
513
514
int startwin_open(void)
514
int32_t startwin_open(void)
515
{
515
{
516
    INITCOMMONCONTROLSEX icc;
516
    INITCOMMONCONTROLSEX icc;
517
    if (startupdlg) return 1;
517
    if (startupdlg) return 1;
518
    icc.dwSize = sizeof(icc);
518
    icc.dwSize = sizeof(icc);
519
    icc.dwICC = ICC_TAB_CLASSES;
519
    icc.dwICC = ICC_TAB_CLASSES;
520
    InitCommonControlsEx(&icc);
520
    InitCommonControlsEx(&icc);
521
    startupdlg = CreateDialog((HINSTANCE)win_gethinstance(), MAKEINTRESOURCE(WIN_STARTWIN), NULL, startup_dlgproc);
521
    startupdlg = CreateDialog((HINSTANCE)win_gethinstance(), MAKEINTRESOURCE(WIN_STARTWIN), NULL, startup_dlgproc);
522
    if (startupdlg)
522
    if (startupdlg)
523
    {
523
    {
524
        SetPage(TAB_MESSAGES);
524
        SetPage(TAB_MESSAGES);
525
        EnableConfig(0);
525
        EnableConfig(0);
526
        return 0;
526
        return 0;
527
    }
527
    }
528
    return -1;
528
    return -1;
529
}
529
}
530
530
531
int startwin_close(void)
531
int32_t startwin_close(void)
532
{
532
{
533
    if (!startupdlg) return 1;
533
    if (!startupdlg) return 1;
534
    DestroyWindow(startupdlg);
534
    DestroyWindow(startupdlg);
535
    startupdlg = NULL;
535
    startupdlg = NULL;
536
    return 0;
536
    return 0;
537
}
537
}
538
538
539
int startwin_puts(const char *buf)
539
int32_t startwin_puts(const char *buf)
540
{
540
{
541
    const char *p = NULL, *q = NULL;
541
    const char *p = NULL, *q = NULL;
542
    static char workbuf[1024];
542
    static char workbuf[1024];
543
    static int newline = 0;
543
    static int32_t newline = 0;
544
    int curlen, linesbefore, linesafter;
544
    int32_t curlen, linesbefore, linesafter;
545
    HWND edctl;
545
    HWND edctl;
546
    int vis;
546
    int32_t vis;
547
    static HWND dactrl = NULL;
547
    static HWND dactrl = NULL;
548
548
549
    if (!startupdlg) return 1;
549
    if (!startupdlg) return 1;
550
550
551
    edctl = pages[TAB_MESSAGES];
551
    edctl = pages[TAB_MESSAGES];
552
    if (!edctl) return -1;
552
    if (!edctl) return -1;
553
553
554
    if (!dactrl) dactrl = GetDlgItem(startupdlg, WIN_STARTWIN_TABCTL);
554
    if (!dactrl) dactrl = GetDlgItem(startupdlg, WIN_STARTWIN_TABCTL);
555
555
556
    vis = ((int)SendMessage(dactrl, TCM_GETCURSEL,0,0) == TAB_MESSAGES);
556
    vis = ((int32_t)SendMessage(dactrl, TCM_GETCURSEL,0,0) == TAB_MESSAGES);
557
557
558
    if (vis) SendMessage(edctl, WM_SETREDRAW, FALSE,0);
558
    if (vis) SendMessage(edctl, WM_SETREDRAW, FALSE,0);
559
    curlen = SendMessage(edctl, WM_GETTEXTLENGTH, 0,0);
559
    curlen = SendMessage(edctl, WM_GETTEXTLENGTH, 0,0);
560
    SendMessage(edctl, EM_SETSEL, (WPARAM)curlen, (LPARAM)curlen);
560
    SendMessage(edctl, EM_SETSEL, (WPARAM)curlen, (LPARAM)curlen);
561
    linesbefore = SendMessage(edctl, EM_GETLINECOUNT, 0,0);
561
    linesbefore = SendMessage(edctl, EM_GETLINECOUNT, 0,0);
562
    p = buf;
562
    p = buf;
563
    while (*p)
563
    while (*p)
564
    {
564
    {
565
        if (newline)
565
        if (newline)
566
        {
566
        {
567
            SendMessage(edctl, EM_REPLACESEL, 0, (LPARAM)"\r\n");
567
            SendMessage(edctl, EM_REPLACESEL, 0, (LPARAM)"\r\n");
568
            newline = 0;
568
            newline = 0;
569
        }
569
        }
570
        q = p;
570
        q = p;
571
        while (*q && *q != '\n') q++;
571
        while (*q && *q != '\n') q++;
572
        memcpy(workbuf, p, q-p);
572
        memcpy(workbuf, p, q-p);
573
        if (*q == '\n')
573
        if (*q == '\n')
574
        {
574
        {
575
            if (!q[1])
575
            if (!q[1])
576
            {
576
            {
577
                newline = 1;
577
                newline = 1;
578
                workbuf[q-p] = 0;
578
                workbuf[q-p] = 0;
579
            }
579
            }
580
            else
580
            else
581
            {
581
            {
582
                workbuf[q-p] = '\r';
582
                workbuf[q-p] = '\r';
583
                workbuf[q-p+1] = '\n';
583
                workbuf[q-p+1] = '\n';
584
                workbuf[q-p+2] = 0;
584
                workbuf[q-p+2] = 0;
585
            }
585
            }
586
            p = q+1;
586
            p = q+1;
587
        }
587
        }
588
        else
588
        else
589
        {
589
        {
590
            workbuf[q-p] = 0;
590
            workbuf[q-p] = 0;
591
            p = q;
591
            p = q;
592
        }
592
        }
593
        SendMessage(edctl, EM_REPLACESEL, 0, (LPARAM)workbuf);
593
        SendMessage(edctl, EM_REPLACESEL, 0, (LPARAM)workbuf);
594
    }
594
    }
595
    linesafter = SendMessage(edctl, EM_GETLINECOUNT, 0,0);
595
    linesafter = SendMessage(edctl, EM_GETLINECOUNT, 0,0);
596
    SendMessage(edctl, EM_LINESCROLL, 0, linesafter-linesbefore);
596
    SendMessage(edctl, EM_LINESCROLL, 0, linesafter-linesbefore);
597
    if (vis) SendMessage(edctl, WM_SETREDRAW, TRUE,0);
597
    if (vis) SendMessage(edctl, WM_SETREDRAW, TRUE,0);
598
    return 0;
598
    return 0;
599
}
599
}
600
600
601
int startwin_settitle(const char *str)
601
int32_t startwin_settitle(const char *str)
602
{
602
{
603
    if (!startupdlg) return 1;
603
    if (!startupdlg) return 1;
604
    SetWindowText(startupdlg, str);
604
    SetWindowText(startupdlg, str);
605
    return 0;
605
    return 0;
606
}
606
}
607
607
608
int startwin_idle(void *v)
608
int32_t startwin_idle(void *v)
609
{
609
{
610
    if (!startupdlg || !IsWindow(startupdlg)) return 0;
610
    if (!startupdlg || !IsWindow(startupdlg)) return 0;
611
    if (IsDialogMessage(startupdlg, (MSG*)v)) return 1;
611
    if (IsDialogMessage(startupdlg, (MSG*)v)) return 1;
612
    return 0;
612
    return 0;
613
}
613
}
614
614
615
int startwin_run(void)
615
int32_t startwin_run(void)
616
{
616
{
617
    MSG msg;
617
    MSG msg;
618
    if (!startupdlg) return 1;
618
    if (!startupdlg) return 1;
619
619
620
    done = -1;
620
    done = -1;
621
621
622
#ifdef JFAUD
622
#ifdef JFAUD
623
    EnumAudioDevs(&wavedevs, NULL, NULL);
623
    EnumAudioDevs(&wavedevs, NULL, NULL);
624
#endif
624
#endif
625
    SetPage(TAB_CONFIG);
625
    SetPage(TAB_CONFIG);
626
    EnableConfig(1);
626
    EnableConfig(1);
627
627
628
    settings.fullscreen = ud.config.ScreenMode;
628
    settings.fullscreen = ud.config.ScreenMode;
629
    settings.xdim = ud.config.ScreenWidth;
629
    settings.xdim = ud.config.ScreenWidth;
630
    settings.ydim = ud.config.ScreenHeight;
630
    settings.ydim = ud.config.ScreenHeight;
631
    settings.bpp = ud.config.ScreenBPP;
631
    settings.bpp = ud.config.ScreenBPP;
632
    settings.forcesetup = ud.config.ForceSetup;
632
    settings.forcesetup = ud.config.ForceSetup;
633
    settings.usemouse = ud.config.UseMouse;
633
    settings.usemouse = ud.config.UseMouse;
634
    settings.usejoy = ud.config.UseJoystick;
634
    settings.usejoy = ud.config.UseJoystick;
635
    settings.game = g_gameType;
635
    settings.game = g_gameType;
636
//    settings.crcval = 0;
636
//    settings.crcval = 0;
637
    strncpy(settings.selectedgrp, duke3dgrp, BMAX_PATH);
637
    strncpy(settings.selectedgrp, duke3dgrp, BMAX_PATH);
638
    settings.gamedir = mod_dir;
638
    settings.gamedir = mod_dir;
639
    PopulateForm(-1);
639
    PopulateForm(-1);
640
640
641
    while (done < 0)
641
    while (done < 0)
642
    {
642
    {
643
        switch (GetMessage(&msg, NULL, 0,0))
643
        switch (GetMessage(&msg, NULL, 0,0))
644
        {
644
        {
645
        case 0:
645
        case 0:
646
            done = 1;
646
            done = 1;
647
            break;
647
            break;
648
        case -1:
648
        case -1:
649
            return -1;
649
            return -1;
650
        default:
650
        default:
651
            if (IsWindow(startupdlg) && IsDialogMessage(startupdlg, &msg)) break;
651
            if (IsWindow(startupdlg) && IsDialogMessage(startupdlg, &msg)) break;
652
            TranslateMessage(&msg);
652
            TranslateMessage(&msg);
653
            DispatchMessage(&msg);
653
            DispatchMessage(&msg);
654
            break;
654
            break;
655
        }
655
        }
656
    }
656
    }
657
657
658
    SetPage(TAB_MESSAGES);
658
    SetPage(TAB_MESSAGES);
659
    EnableConfig(0);
659
    EnableConfig(0);
660
    if (done)
660
    if (done)
661
    {
661
    {
662
        int i;
662
        int32_t i;
663
663
664
        ud.config.ScreenMode = settings.fullscreen;
664
        ud.config.ScreenMode = settings.fullscreen;
665
        ud.config.ScreenWidth = settings.xdim;
665
        ud.config.ScreenWidth = settings.xdim;
666
        ud.config.ScreenHeight = settings.ydim;
666
        ud.config.ScreenHeight = settings.ydim;
667
        ud.config.ScreenBPP = settings.bpp;
667
        ud.config.ScreenBPP = settings.bpp;
668
        ud.config.ForceSetup = settings.forcesetup;
668
        ud.config.ForceSetup = settings.forcesetup;
669
        ud.config.UseMouse = settings.usemouse;
669
        ud.config.UseMouse = settings.usemouse;
670
        ud.config.UseJoystick = settings.usejoy;
670
        ud.config.UseJoystick = settings.usejoy;
671
        duke3dgrp = settings.selectedgrp;
671
        duke3dgrp = settings.selectedgrp;
672
        g_gameType = settings.game;
672
        g_gameType = settings.game;
673
673
674
        if (g_noSetup == 0 && settings.gamedir != NULL)
674
        if (g_noSetup == 0 && settings.gamedir != NULL)
675
            Bstrcpy(mod_dir,settings.gamedir);
675
            Bstrcpy(mod_dir,settings.gamedir);
676
        else Bsprintf(mod_dir,"/");
676
        else Bsprintf(mod_dir,"/");
677
677
678
        for (i = 0; i<numgrpfiles; i++) if (settings.crcval == grpfiles[i].crcval) break;
678
        for (i = 0; i<numgrpfiles; i++) if (settings.crcval == grpfiles[i].crcval) break;
679
        if (i != numgrpfiles)
679
        if (i != numgrpfiles)
680
            duke3dgrpstring = (char *)grpfiles[i].name;
680
            duke3dgrpstring = (char *)grpfiles[i].name;
681
    }
681
    }
682
682
683
    if (wavedevs)
683
    if (wavedevs)
684
    {
684
    {
685
        struct audioenumdev *d, *e;
685
        struct audioenumdev *d, *e;
686
        free(wavedevs->drvs);
686
        free(wavedevs->drvs);
687
        for (e=wavedevs->devs; e; e=d)
687
        for (e=wavedevs->devs; e; e=d)
688
        {
688
        {
689
            d = e->next;
689
            d = e->next;
690
            if (e->devs) free(e->devs);
690
            if (e->devs) free(e->devs);
691
            free(e);
691
            free(e);
692
        }
692
        }
693
        free(wavedevs);
693
        free(wavedevs);
694
    }
694
    }
695
695
696
    return done;
696
    return done;
697
}
697
}
698
698
699
 
699