Code: Select all
static void MakeWindow(bool full_screen)
{
DEVMODE displayMode;
DWORD dwModeNumber = 0;
DWORD dwRefreshRate = 0;
_fullscreen = full_screen;
_wnd.double_size = _double_size && !full_screen;
// recreate window?
if ((full_screen|_wnd.fullscreen) && _wnd.main_wnd) {
DestroyWindow(_wnd.main_wnd);
_wnd.main_wnd = 0;
}
ZeroMemory(&displayMode, sizeof(DEVMODE));
while(EnumDisplaySettings(NULL, dwModeNumber++, &displayMode))
{
if((displayMode.dmPelsWidth == _wnd.width_org) & (displayMode.dmPelsHeight == _wnd.height_org))
{
if(displayMode.dmDisplayFrequency > dwRefreshRate) dwRefreshRate = displayMode.dmDisplayFrequency;
}
}
if(full_screen)
{
displayMode.dmSize = sizeof(DEVMODE);
displayMode.dmPelsWidth = _wnd.width_org;
displayMode.dmPelsHeight = _wnd.height_org;
displayMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
if(_fullscreen_bpp)
{
displayMode.dmBitsPerPel = _fullscreen_bpp;
displayMode.dmFields |= DM_BITSPERPEL;
}
displayMode.dmDisplayFrequency = dwRefreshRate;
displayMode.dmFields |= DM_DISPLAYFREQUENCY;
if(ChangeDisplaySettings(&displayMode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
{
if(MessageBox(NULL,
"Failed to create fullscreen window. Ignore this?", "ERROR", MB_ICONERROR|MB_YESNO)!=IDYES)
{
MakeWindow(false);
return;
}
}
}
else if(_wnd.fullscreen)
{
// restore display?
ChangeDisplaySettings(NULL, 0);
}
{
RECT r;
uint style;
int x, y, w, h;
if ((_wnd.fullscreen=full_screen) != false) {
style = WS_POPUP | WS_VISIBLE;
SetRect(&r, 0, 0, _wnd.width_org, _wnd.height_org);
} else {
style = WS_OVERLAPPEDWINDOW | WS_VISIBLE;
SetRect(&r, 0, 0, _wnd.width, _wnd.height);
}
AdjustWindowRect(&r, style, FALSE);
w = r.right - r.left;
h = r.bottom - r.top;
x = (GetSystemMetrics(SM_CXSCREEN)-w)>>1;
y = (GetSystemMetrics(SM_CYSCREEN)-h)>>1;
if (_wnd.main_wnd) {
SetWindowPos(_wnd.main_wnd, 0, x, y, w, h, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
} else {
char Windowtitle[50] = "OpenTTD ";
#ifdef WITH_REV_HACK
// also show revision number/release in window title
extern const char _openttd_revision[];
strncat(Windowtitle, _openttd_revision, sizeof(Windowtitle)-(strlen(Windowtitle) + 1));
#endif
_wnd.main_wnd = CreateWindow("TTD", Windowtitle, style, x, y, w, h, 0, 0, _inst, 0);
if (_wnd.main_wnd == NULL)
error("CreateWindow failed");
}
}
GameSizeChanged(); // invalidate all windows, force redraw
}
PS. Hello all. This is my first post in open ttd. I make many changes to code, especially for better performance, and for better work under win32 platform. And, for sample, i make c++ port of openttd, this is better actually, i think.
I realy want to join open ttd developes. How can i do this?)
Thank.