修复窗口设置过大时不显示窗口的BUG
This commit is contained in:
parent
24dbd42970
commit
d311461a48
|
|
@ -30,25 +30,20 @@ bool e2d::Window::__init()
|
||||||
float dpiX = Renderer::getDpiScaleX();
|
float dpiX = Renderer::getDpiScaleX();
|
||||||
float dpiY = Renderer::getDpiScaleY();
|
float dpiY = Renderer::getDpiScaleY();
|
||||||
|
|
||||||
UINT nWidth = static_cast<UINT>(ceil(640 * dpiX / 96.f));
|
int nWidth = static_cast<int>(ceil(640 * dpiX / 96.f));
|
||||||
UINT nHeight = static_cast<UINT>(ceil(480 * dpiY / 96.f));
|
int nHeight = static_cast<int>(ceil(480 * dpiY / 96.f));
|
||||||
|
|
||||||
// 获取屏幕分辨率
|
|
||||||
UINT screenWidth = static_cast<UINT>(::GetSystemMetrics(SM_CXSCREEN));
|
|
||||||
UINT screenHeight = static_cast<UINT>(::GetSystemMetrics(SM_CYSCREEN));
|
|
||||||
// 当输入的窗口大小比分辨率大时,给出警告
|
|
||||||
WARN_IF(screenWidth < nWidth || screenHeight < nHeight, "The window is larger than screen!");
|
|
||||||
// 取最小值
|
|
||||||
nWidth = min(nWidth, screenWidth);
|
|
||||||
nHeight = min(nHeight, screenHeight);
|
|
||||||
|
|
||||||
// 计算窗口大小
|
// 计算窗口大小
|
||||||
DWORD dwStyle = WS_OVERLAPPEDWINDOW &~ WS_MAXIMIZEBOX &~ WS_THICKFRAME;
|
DWORD dwStyle = WS_OVERLAPPEDWINDOW &~ WS_MAXIMIZEBOX &~ WS_THICKFRAME;
|
||||||
RECT wr = { 0, 0, static_cast<LONG>(nWidth), static_cast<LONG>(nHeight) };
|
RECT wr = { 0, 0, static_cast<LONG>(nWidth), static_cast<LONG>(nHeight) };
|
||||||
::AdjustWindowRectEx(&wr, dwStyle, FALSE, NULL);
|
::AdjustWindowRectEx(&wr, dwStyle, FALSE, NULL);
|
||||||
// 获取新的宽高
|
// 获取新的宽高
|
||||||
nWidth = wr.right - wr.left;
|
nWidth = static_cast<int>(wr.right - wr.left);
|
||||||
nHeight = wr.bottom - wr.top;
|
nHeight = static_cast<int>(wr.bottom - wr.top);
|
||||||
|
|
||||||
|
// 获取屏幕分辨率
|
||||||
|
int screenWidth = ::GetSystemMetrics(SM_CXSCREEN);
|
||||||
|
int screenHeight = ::GetSystemMetrics(SM_CYSCREEN);
|
||||||
|
|
||||||
// 创建窗口
|
// 创建窗口
|
||||||
s_HWnd = ::CreateWindowEx(
|
s_HWnd = ::CreateWindowEx(
|
||||||
|
|
@ -158,18 +153,23 @@ HWND e2d::Window::getHWnd()
|
||||||
return s_HWnd;
|
return s_HWnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::Window::setSize(UINT32 width, UINT32 height)
|
void e2d::Window::setSize(int width, int height)
|
||||||
{
|
{
|
||||||
// 计算窗口大小
|
// 计算窗口大小
|
||||||
DWORD dwStyle = WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX;
|
DWORD dwStyle = WS_OVERLAPPEDWINDOW &~ WS_MAXIMIZEBOX &~ WS_THICKFRAME;
|
||||||
RECT wr = { 0, 0, static_cast<LONG>(width), static_cast<LONG>(height) };
|
RECT wr = { 0, 0, static_cast<LONG>(width), static_cast<LONG>(height) };
|
||||||
::AdjustWindowRectEx(&wr, dwStyle, FALSE, NULL);
|
::AdjustWindowRectEx(&wr, dwStyle, FALSE, NULL);
|
||||||
// 获取新的宽高
|
// 获取新的宽高
|
||||||
width = wr.right - wr.left;
|
width = static_cast<int>(wr.right - wr.left);
|
||||||
height = wr.bottom - wr.top;
|
height = static_cast<int>(wr.bottom - wr.top);
|
||||||
// 获取屏幕分辨率
|
// 获取屏幕分辨率
|
||||||
int screenWidth = ::GetSystemMetrics(SM_CXSCREEN);
|
int screenWidth = ::GetSystemMetrics(SM_CXSCREEN);
|
||||||
int screenHeight = ::GetSystemMetrics(SM_CYSCREEN);
|
int screenHeight = ::GetSystemMetrics(SM_CYSCREEN);
|
||||||
|
// 当输入的窗口大小比分辨率大时,给出警告
|
||||||
|
WARN_IF(screenWidth < width || screenHeight < height, "The window is larger than screen!");
|
||||||
|
// 取最小值
|
||||||
|
width = min(width, screenWidth);
|
||||||
|
height = min(height, screenHeight);
|
||||||
// 修改窗口大小,并设置窗口在屏幕居中
|
// 修改窗口大小,并设置窗口在屏幕居中
|
||||||
::MoveWindow(s_HWnd, (screenWidth - width) / 2, (screenHeight - height) / 2, width, height, TRUE);
|
::MoveWindow(s_HWnd, (screenWidth - width) / 2, (screenHeight - height) / 2, width, height, TRUE);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,8 +56,8 @@ class Window
|
||||||
public:
|
public:
|
||||||
// 修改窗口大小
|
// 修改窗口大小
|
||||||
static void setSize(
|
static void setSize(
|
||||||
UINT32 nWidth, /* 窗口宽度 */
|
int nWidth, /* 窗口宽度 */
|
||||||
UINT32 nHeight /* 窗口高度 */
|
int nHeight /* 窗口高度 */
|
||||||
);
|
);
|
||||||
|
|
||||||
// 设置窗口标题
|
// 设置窗口标题
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue