(svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible

pull/155/head
glx 18 years ago
parent fecf81496a
commit f7b378df33

@ -34,9 +34,6 @@ bool _window_maximize;
uint _display_hz;
uint _fullscreen_bpp;
static uint16 _bck_resolution[2];
#if !defined(WINCE)
static DEVMODE _fullscreen_dm;
#endif
#if !defined(UNICODE)
uint _codepage;
#endif
@ -205,6 +202,89 @@ static void CALLBACK TrackMouseTimerProc(HWND hwnd, UINT msg, UINT event, DWORD
}
}
static void MakeWindow(bool full_screen)
{
_fullscreen = full_screen;
// recreate window?
if ((full_screen || _wnd.fullscreen) && _wnd.main_wnd) {
DestroyWindow(_wnd.main_wnd);
_wnd.main_wnd = 0;
}
#if defined(WINCE)
/* WinCE is always fullscreen */
#else
if (full_screen) {
DEVMODE settings;
/* Make sure we are always at least the screen-depth of the blitter */
if (_fullscreen_bpp < BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth()) _fullscreen_bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth();
memset(&settings, 0, sizeof(settings));
settings.dmSize = sizeof(settings);
settings.dmFields =
(_fullscreen_bpp != 0 ? DM_BITSPERPEL : 0) |
DM_PELSWIDTH |
DM_PELSHEIGHT |
(_display_hz != 0 ? DM_DISPLAYFREQUENCY : 0);
settings.dmBitsPerPel = _fullscreen_bpp;
settings.dmPelsWidth = _wnd.width_org;
settings.dmPelsHeight = _wnd.height_org;
settings.dmDisplayFrequency = _display_hz;
if (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) {
MakeWindow(false);
return;
}
} else if (_wnd.fullscreen) {
// restore display?
ChangeDisplaySettings(NULL, 0);
}
#endif
{
RECT r;
DWORD style, showstyle;
int x, y, w, h;
showstyle = SW_SHOWNORMAL;
_wnd.fullscreen = full_screen;
if (_wnd.fullscreen) {
style = WS_POPUP;
SetRect(&r, 0, 0, _wnd.width_org, _wnd.height_org);
} else {
style = WS_OVERLAPPEDWINDOW;
/* On window creation, check if we were in maximize mode before */
if (_window_maximize) showstyle = SW_SHOWMAXIMIZED;
SetRect(&r, 0, 0, _wnd.width, _wnd.height);
}
#if !defined(WINCE)
AdjustWindowRect(&r, style, FALSE);
#endif
w = r.right - r.left;
h = r.bottom - r.top;
x = (GetSystemMetrics(SM_CXSCREEN) - w) / 2;
y = (GetSystemMetrics(SM_CYSCREEN) - h) / 2;
if (_wnd.main_wnd) {
ShowWindow(_wnd.main_wnd, SW_SHOWNORMAL); // remove maximize-flag
SetWindowPos(_wnd.main_wnd, 0, x, y, w, h, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
} else {
extern const char _openttd_revision[];
TCHAR Windowtitle[50];
_sntprintf(Windowtitle, sizeof(Windowtitle), _T("OpenTTD %s"), MB_TO_WIDE(_openttd_revision));
_wnd.main_wnd = CreateWindow(_T("OTTD"), Windowtitle, style, x, y, w, h, 0, 0, GetModuleHandle(NULL), 0);
if (_wnd.main_wnd == NULL) error("CreateWindow failed");
ShowWindow(_wnd.main_wnd, showstyle);
}
}
GameSizeChanged(); // invalidate all windows, force redraw
}
static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static uint32 keycode = 0;
@ -528,9 +608,7 @@ static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP
if (_wnd.has_focus && _wnd.minimized) {
/* Restore the game window */
ShowWindow(hwnd, SW_RESTORE);
ChangeDisplaySettings(&_fullscreen_dm, CDS_FULLSCREEN);
/* Force palette update */
SendMessage(hwnd, WM_QUERYNEWPALETTE, 0, 0);
MakeWindow(true);
} else if (!_wnd.has_focus && !_wnd.minimized) {
/* Minimise the window and restore desktop */
ShowWindow(hwnd, SW_MINIMIZE);
@ -567,87 +645,6 @@ static void RegisterWndClass()
}
}
static void MakeWindow(bool full_screen)
{
_fullscreen = full_screen;
// recreate window?
if ((full_screen || _wnd.fullscreen) && _wnd.main_wnd) {
DestroyWindow(_wnd.main_wnd);
_wnd.main_wnd = 0;
}
#if defined(WINCE)
/* WinCE is always fullscreen */
#else
if (full_screen) {
/* Make sure we are always at least the screen-depth of the blitter */
if (_fullscreen_bpp < BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth()) _fullscreen_bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth();
memset(&_fullscreen_dm, 0, sizeof(_fullscreen_dm));
_fullscreen_dm.dmSize = sizeof(_fullscreen_dm);
_fullscreen_dm.dmFields =
(_fullscreen_bpp != 0 ? DM_BITSPERPEL : 0) |
DM_PELSWIDTH |
DM_PELSHEIGHT |
(_display_hz != 0 ? DM_DISPLAYFREQUENCY : 0);
_fullscreen_dm.dmBitsPerPel = _fullscreen_bpp;
_fullscreen_dm.dmPelsWidth = _wnd.width_org;
_fullscreen_dm.dmPelsHeight = _wnd.height_org;
_fullscreen_dm.dmDisplayFrequency = _display_hz;
if (ChangeDisplaySettings(&_fullscreen_dm, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) {
MakeWindow(false);
return;
}
} else if (_wnd.fullscreen) {
// restore display?
ChangeDisplaySettings(NULL, 0);
}
#endif
{
RECT r;
DWORD style, showstyle;
int x, y, w, h;
showstyle = SW_SHOWNORMAL;
_wnd.fullscreen = full_screen;
if (_wnd.fullscreen) {
style = WS_POPUP;
SetRect(&r, 0, 0, _wnd.width_org, _wnd.height_org);
} else {
style = WS_OVERLAPPEDWINDOW;
/* On window creation, check if we were in maximize mode before */
if (_window_maximize) showstyle = SW_SHOWMAXIMIZED;
SetRect(&r, 0, 0, _wnd.width, _wnd.height);
}
#if !defined(WINCE)
AdjustWindowRect(&r, style, FALSE);
#endif
w = r.right - r.left;
h = r.bottom - r.top;
x = (GetSystemMetrics(SM_CXSCREEN) - w) / 2;
y = (GetSystemMetrics(SM_CYSCREEN) - h) / 2;
if (_wnd.main_wnd) {
ShowWindow(_wnd.main_wnd, SW_SHOWNORMAL); // remove maximize-flag
SetWindowPos(_wnd.main_wnd, 0, x, y, w, h, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
} else {
extern const char _openttd_revision[];
TCHAR Windowtitle[50];
_sntprintf(Windowtitle, sizeof(Windowtitle), _T("OpenTTD %s"), MB_TO_WIDE(_openttd_revision));
_wnd.main_wnd = CreateWindow(_T("OTTD"), Windowtitle, style, x, y, w, h, 0, 0, GetModuleHandle(NULL), 0);
if (_wnd.main_wnd == NULL) error("CreateWindow failed");
ShowWindow(_wnd.main_wnd, showstyle);
}
}
GameSizeChanged(); // invalidate all windows, force redraw
}
static bool AllocateDibSection(int w, int h)
{
BITMAPINFO *bi;

Loading…
Cancel
Save