#ifndef _WIN32 #error Only for Windows #endif #include "compat.h" #include "build.h" #include "winlayer.h" #define WIN32_LEAN_AND_MEAN #include #include #define _WIN32_IE 0x0600 #include #include #include "startwin.game.h" #define TAB_CONFIG 0 #define TAB_MESSAGES 1 static struct { int fullscreen; int xdim3d, ydim3d, bpp3d; int forcesetup; } settings; static HWND startupdlg = NULL; static HWND pages[2] = { NULL, NULL}; static int done = -1, mode = TAB_CONFIG; static void PopulateForm(void) { int i,j; char buf[64]; int mode3d; HWND hwnd3d; hwnd3d = GetDlgItem(pages[TAB_CONFIG], IDC3DVMODE); mode3d = checkvideomode(&settings.xdim3d, &settings.ydim3d, settings.bpp3d, settings.fullscreen, 1); if (mode3d < 0) { int cd[] = { 32, 24, 16, 15, 8, 0 }; for (i=0; cd[i]; ) { if (cd[i] >= settings.bpp3d) i++; else break; } for (; cd[i]; i++) { mode3d = checkvideomode(&settings.xdim3d, &settings.ydim3d, cd[i], settings.fullscreen, 1); if (mode3d < 0) continue; settings.bpp3d = cd[i]; break; } } Button_SetCheck(GetDlgItem(pages[TAB_CONFIG], IDCFULLSCREEN), (settings.fullscreen ? BST_CHECKED : BST_UNCHECKED)); Button_SetCheck(GetDlgItem(pages[TAB_CONFIG], IDCALWAYSSHOW), (settings.forcesetup ? BST_CHECKED : BST_UNCHECKED)); ComboBox_ResetContent(hwnd3d); for (i=0; iidFrom != WIN_STARTWIN_TABCTL) break; cur = (int)SendMessage(nmhdr->hwndFrom, TCM_GETCURSEL,0,0); switch (nmhdr->code) { case TCN_SELCHANGING: { if (cur < 0 || !pages[cur]) break; ShowWindow(pages[cur],SW_HIDE); return TRUE; } case TCN_SELCHANGE: { if (cur < 0 || !pages[cur]) break; ShowWindow(pages[cur],SW_SHOW); return TRUE; } } break; } case WM_CLOSE: if (mode == TAB_CONFIG) done = 0; else quitevent++; return TRUE; case WM_DESTROY: if (hbmp) { DeleteObject(hbmp); hbmp = NULL; } if (pages[TAB_CONFIG]) { DestroyWindow(pages[TAB_CONFIG]); pages[TAB_CONFIG] = NULL; } startupdlg = NULL; return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case WIN_STARTWIN_CANCEL: if (mode == TAB_CONFIG) done = 0; else quitevent++; return TRUE; case WIN_STARTWIN_START: done = 1; return TRUE; } return FALSE; case WM_CTLCOLORSTATIC: if ((HWND)lParam == pages[TAB_MESSAGES]) return (BOOL)GetSysColorBrush(COLOR_WINDOW); break; default: break; } return FALSE; } int startwin_open(void) { INITCOMMONCONTROLSEX icc; if (startupdlg) return 1; icc.dwSize = sizeof(icc); icc.dwICC = ICC_TAB_CLASSES; InitCommonControlsEx(&icc); startupdlg = CreateDialog((HINSTANCE)win_gethinstance(), MAKEINTRESOURCE(WIN_STARTWIN), NULL, startup_dlgproc); if (startupdlg) { SetPage(TAB_MESSAGES); EnableConfig(0); return 0; } return -1; } int startwin_close(void) { if (!startupdlg) return 1; DestroyWindow(startupdlg); startupdlg = NULL; return 0; } int startwin_puts(const char *buf) { const char *p = NULL, *q = NULL; char workbuf[1024]; static int newline = 0; int curlen, linesbefore, linesafter; HWND edctl; int vis; if (!startupdlg) return 1; edctl = pages[TAB_MESSAGES]; if (!edctl) return -1; vis = ((int)SendMessage(GetDlgItem(startupdlg, WIN_STARTWIN_TABCTL), TCM_GETCURSEL,0,0) == TAB_MESSAGES); if (vis) SendMessage(edctl, WM_SETREDRAW, FALSE,0); curlen = SendMessage(edctl, WM_GETTEXTLENGTH, 0,0); SendMessage(edctl, EM_SETSEL, (WPARAM)curlen, (LPARAM)curlen); linesbefore = SendMessage(edctl, EM_GETLINECOUNT, 0,0); p = buf; while (*p) { if (newline) { SendMessage(edctl, EM_REPLACESEL, 0, (LPARAM)"\r\n"); newline = 0; } q = p; while (*q && *q != '\n') q++; memcpy(workbuf, p, q-p); if (*q == '\n') { if (!q[1]) { newline = 1; workbuf[q-p] = 0; } else { workbuf[q-p] = '\r'; workbuf[q-p+1] = '\n'; workbuf[q-p+2] = 0; } p = q+1; } else { workbuf[q-p] = 0; p = q; } SendMessage(edctl, EM_REPLACESEL, 0, (LPARAM)workbuf); } linesafter = SendMessage(edctl, EM_GETLINECOUNT, 0,0); SendMessage(edctl, EM_LINESCROLL, 0, linesafter-linesbefore); if (vis) SendMessage(edctl, WM_SETREDRAW, TRUE,0); return 0; } int startwin_settitle(const char *str) { if (!startupdlg) return 1; SetWindowText(startupdlg, str); return 0; } int startwin_idle(void *v) { if (!startupdlg || !IsWindow(startupdlg)) return 0; if (IsDialogMessage(startupdlg, (MSG *)v)) return 1; return 0; } extern int xdimgame, ydimgame, bppgame, forcesetup; int startwin_run(void) { MSG msg; if (!startupdlg) return 1; done = -1; SetPage(TAB_CONFIG); EnableConfig(1); settings.fullscreen = fullscreen; settings.xdim3d = xdimgame; settings.ydim3d = ydimgame; settings.bpp3d = bppgame; settings.forcesetup = forcesetup; PopulateForm(); while (done < 0) { switch (GetMessage(&msg, NULL, 0,0)) { case 0: done = 1; break; case -1: return -1; default: if (IsWindow(startupdlg) && IsDialogMessage(startupdlg, &msg)) break; TranslateMessage(&msg); DispatchMessage(&msg); break; } } SetPage(TAB_MESSAGES); EnableConfig(0); if (done) { fullscreen = settings.fullscreen; xdimgame = settings.xdim3d; ydimgame = settings.ydim3d; bppgame = settings.bpp3d; forcesetup = settings.forcesetup; } return done; }