Files
UpdateDisplay/Display.cpp
2025-12-13 18:19:55 +01:00

43 lines
864 B
C++

#include "Display.h"
#include "Exception.h"
Display::Display()
{
_devmode.dmSize = sizeof(DEVMODE);
BOOL success = EnumDisplaySettingsEx(
nullptr,
ENUM_CURRENT_SETTINGS,
&_devmode,
0
);
if (!success)
throw SystemException(GetLastError());
}
void Display::rotate(Rotation rot)
{
DWORD& orient = _devmode.dmDisplayOrientation;
DWORD& width = _devmode.dmPelsWidth;
DWORD& height = _devmode.dmPelsHeight;
if (orient == DMDO_90 || orient == DMDO_270)
std::swap(width, height);
orient = (DWORD)rot;
if (orient == DMDO_90 || orient == DMDO_270)
std::swap(width, height);
}
void Display::apply()
{
LONG res = ChangeDisplaySettingsEx(nullptr, &_devmode, nullptr, CDS_RESET, nullptr);
if (res != DISP_CHANGE_SUCCESSFUL)
throw DisplayException(res);
}