Hiya. So in my "Engine" I'm able to switch window resolutions(800x600, 1024x768, & fullscreen), but if I switch into fullscreen then back into a windowed mode the window gets stuck at the top-most window. No matter what. If I click on a window, it displays behind my engine window. This ONLY happens after I come out of fullscreen. I Googled it and I couldn't really find anything useful. Here is my code to change the window:
bool Window::ChangeWindowMode(int windowMode)
{
if(windowMode == Window::m_WindowProperties.m_windowMode)
{
return false;
}
if(windowMode == WindowModes::WM_800X600)
{
Window::m_WindowProperties.m_windowMode = WindowModes::WM_800X600;
m_WindowProperties.m_windowWidth = 800;
m_WindowProperties.m_windowHeight = 600;
m_WindowProperties.m_windowPosX = (GetSystemMetrics(SM_CXSCREEN) - m_WindowProperties.m_windowWidth) / 2;
m_WindowProperties.m_windowPosY = (GetSystemMetrics(SM_CYSCREEN) - m_WindowProperties.m_windowHeight) / 2;
if(m_WindowProperties.m_windowMode == WindowModes::WM_FULLSCREEN)
{
ChangeDisplaySettings(nullptr, 0);
}
SetWindowLongPtr(m_hWnd, GWL_EXSTYLE, WS_EX_OVERLAPPEDWINDOW);
SetWindowLongPtr(m_hWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW ^ WS_THICKFRAME);
SetWindowPos(m_hWnd, nullptr, m_WindowProperties.m_windowPosX, m_WindowProperties.m_windowPosY,
m_WindowProperties.m_windowWidth, m_WindowProperties.m_windowHeight, SWP_SHOWWINDOW | SWP_NOZORDER);
}
else if(windowMode == WindowModes::WM_1024X768)
{
Window::m_WindowProperties.m_windowMode = WindowModes::WM_1024X768;
m_WindowProperties.m_windowWidth = 1024;
m_WindowProperties.m_windowHeight = 768;
m_WindowProperties.m_windowPosX = (GetSystemMetrics(SM_CXSCREEN) - m_WindowProperties.m_windowWidth) / 2;
m_WindowProperties.m_windowPosY = (GetSystemMetrics(SM_CYSCREEN) - m_WindowProperties.m_windowHeight) / 2;
if(m_WindowProperties.m_windowMode == WindowModes::WM_FULLSCREEN)
{
ChangeDisplaySettings(nullptr, CDS_GLOBAL);
}
SetWindowLongPtr(m_hWnd, GWL_EXSTYLE, WS_EX_OVERLAPPEDWINDOW);
SetWindowLongPtr(m_hWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW ^ WS_THICKFRAME);
SetWindowPos(m_hWnd, nullptr, m_WindowProperties.m_windowPosX, m_WindowProperties.m_windowPosY,
m_WindowProperties.m_windowWidth, m_WindowProperties.m_windowHeight, SWP_SHOWWINDOW | SWP_NOZORDER);
return true;
}
else if(windowMode == WindowModes::WM_FULLSCREEN)
{
Window::m_WindowProperties.m_windowMode = WindowModes::WM_FULLSCREEN;
m_WindowProperties.m_windowWidth = GetSystemMetrics(SM_CXSCREEN);
m_WindowProperties.m_windowHeight = GetSystemMetrics(SM_CYSCREEN);
m_WindowProperties.m_windowPosX = m_WindowProperties.m_windowPosY = 0;
DEVMODE dmScreenSettings;
ZeroMemory(&dmScreenSettings, sizeof(DEVMODE));
dmScreenSettings.dmPelsWidth = m_WindowProperties.m_windowWidth;
dmScreenSettings.dmPelsHeight = m_WindowProperties.m_windowHeight;
dmScreenSettings.dmBitsPerPel = 32;
dmScreenSettings.dmDisplayFlags = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;
ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN);
SetWindowLongPtr(m_hWnd, GWL_EXSTYLE, WS_EX_APPWINDOW);
SetWindowLongPtr(m_hWnd, GWL_STYLE, WS_POPUP);
SetWindowPos(m_hWnd, nullptr, m_WindowProperties.m_windowPosX, m_WindowProperties.m_windowPosY,
m_WindowProperties.m_windowWidth, m_WindowProperties.m_windowHeight, SWP_SHOWWINDOW | SWP_NOZORDER);
}
return true;
}
void DeviceResources::ChangeWindowMode(int windowMode)
{
if(m_Window.ChangeWindowMode(windowMode))
{
m_d3dpp.BackBufferWidth = m_Window.m_WindowProperties.m_windowWidth;
m_d3dpp.BackBufferHeight = m_Window.m_WindowProperties.m_windowHeight;
if(windowMode == WindowModes::WM_FULLSCREEN)
{
m_d3dpp.Windowed = false;
}
else
{
m_d3dpp.Windowed = true;
}
m_pDevice->Reset(&m_d3dpp);
}
}