Subversion Repositories eduke32

Rev

Rev 222 | Rev 241 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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