Prevent window resize on DPI change
This commit is contained in:
parent
91afd4ad1b
commit
bd8eda13aa
@ -6,7 +6,7 @@
|
|||||||
namespace nf::cli {
|
namespace nf::cli {
|
||||||
Client::Client(EngineConfig config)
|
Client::Client(EngineConfig config)
|
||||||
: m_currentConfig(config)
|
: m_currentConfig(config)
|
||||||
, m_window()
|
, m_window(1280, 720)
|
||||||
{
|
{
|
||||||
// Setup window and renderer
|
// Setup window and renderer
|
||||||
}
|
}
|
||||||
|
@ -5,10 +5,12 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
namespace nf::cli {
|
namespace nf::cli {
|
||||||
Window::Window()
|
Window::Window(unsigned int width, unsigned int height)
|
||||||
: m_handle(nullptr)
|
: m_handle(nullptr)
|
||||||
, m_wndClassName("NothinFancyWindow")
|
, m_wndClassName("NothinFancyWindow")
|
||||||
, m_windowedStyle(WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX)
|
, m_windowedStyle(WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX)
|
||||||
|
, m_width(width)
|
||||||
|
, m_height(height)
|
||||||
{
|
{
|
||||||
NFLog("Creating window");
|
NFLog("Creating window");
|
||||||
|
|
||||||
@ -20,6 +22,7 @@ namespace nf::cli {
|
|||||||
RegisterClass(&wc);
|
RegisterClass(&wc);
|
||||||
|
|
||||||
m_handle = CreateWindow(m_wndClassName, "NF Window", m_windowedStyle, 0, 0, 0, 0, nullptr, nullptr, nullptr, this);
|
m_handle = CreateWindow(m_wndClassName, "NF Window", m_windowedStyle, 0, 0, 0, 0, nullptr, nullptr, nullptr, this);
|
||||||
|
setSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::runLoop() {
|
void Window::runLoop() {
|
||||||
@ -48,15 +51,15 @@ namespace nf::cli {
|
|||||||
MONITORINFO mi = {};
|
MONITORINFO mi = {};
|
||||||
mi.cbSize = sizeof(mi);
|
mi.cbSize = sizeof(mi);
|
||||||
GetMonitorInfo(MonitorFromPoint(cursor, MONITOR_DEFAULTTONEAREST), &mi);
|
GetMonitorInfo(MonitorFromPoint(cursor, MONITOR_DEFAULTTONEAREST), &mi);
|
||||||
int x = mi.rcMonitor.left + 100, y = mi.rcMonitor.top + 100;
|
int monWidth = mi.rcMonitor.right - mi.rcMonitor.left, monHeight = mi.rcMonitor.bottom - mi.rcMonitor.top;
|
||||||
|
int x = mi.rcMonitor.left + (monWidth / 2) - (wnd->m_width / 2), y = mi.rcMonitor.top + (monHeight / 2) - (wnd->m_height / 2);
|
||||||
|
SetWindowPos(hWnd, nullptr, x , y , 0, 0, SWP_NOZORDER | SWP_NOSIZE);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
RECT cli = {};
|
case WM_DPICHANGED: {
|
||||||
cli.right = 1280;
|
// Prevents resize on DPI change
|
||||||
cli.bottom = 720;
|
wnd->setSize();
|
||||||
AdjustWindowRect(&cli, wnd->m_windowedStyle, FALSE);
|
|
||||||
unsigned int width = cli.right - cli.left, height = cli.bottom - cli.top;
|
|
||||||
|
|
||||||
SetWindowPos(hWnd, nullptr, x, y, width, height, SWP_NOZORDER);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,4 +75,12 @@ namespace nf::cli {
|
|||||||
return DefWindowProc(hWnd, msg, wParam, lParam);
|
return DefWindowProc(hWnd, msg, wParam, lParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Window::setSize() {
|
||||||
|
RECT cli = {};
|
||||||
|
cli.right = m_width;
|
||||||
|
cli.bottom = m_height;
|
||||||
|
AdjustWindowRectExForDpi(&cli, m_windowedStyle, FALSE, NULL, GetDpiForWindow(m_handle));
|
||||||
|
unsigned int width = cli.right - cli.left, height = cli.bottom - cli.top;
|
||||||
|
SetWindowPos(m_handle, nullptr, 0, 0, width, height, SWP_NOZORDER | SWP_NOMOVE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,16 +6,19 @@
|
|||||||
namespace nf::cli {
|
namespace nf::cli {
|
||||||
class Window {
|
class Window {
|
||||||
public:
|
public:
|
||||||
Window();
|
Window(unsigned int width, unsigned int height);
|
||||||
|
|
||||||
void runLoop();
|
void runLoop();
|
||||||
void show(bool show = true);
|
void show(bool show = true);
|
||||||
private:
|
private:
|
||||||
static LRESULT CALLBACK wndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
static LRESULT CALLBACK wndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||||
|
void setSize();
|
||||||
|
|
||||||
HWND m_handle;
|
HWND m_handle;
|
||||||
|
|
||||||
const char* m_wndClassName;
|
const char* m_wndClassName;
|
||||||
const DWORD m_windowedStyle;
|
const DWORD m_windowedStyle;
|
||||||
|
|
||||||
|
unsigned int m_width, m_height;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user