44 ZeroMemory(&mi,
sizeof(mi));
45 mi.cbSize =
sizeof(mi);
47 if (GetMonitorInfoW(handle, (MONITORINFO*) &mi))
50 if (wcscmp(mi.szDevice, monitor->win32.adapterName) == 0)
51 monitor->win32.handle = handle;
63 int widthMM, heightMM;
76 ZeroMemory(&dm,
sizeof(dm));
77 dm.dmSize =
sizeof(dm);
78 EnumDisplaySettingsW(adapter->DeviceName, ENUM_CURRENT_SETTINGS, &dm);
80 dc = CreateDCW(L
"DISPLAY", adapter->DeviceName,
NULL,
NULL);
84 widthMM = GetDeviceCaps(dc, HORZSIZE);
85 heightMM = GetDeviceCaps(dc, VERTSIZE);
89 widthMM = (int) (dm.dmPelsWidth * 25.4f / GetDeviceCaps(dc, LOGPIXELSX));
90 heightMM = (int) (dm.dmPelsHeight * 25.4f / GetDeviceCaps(dc, LOGPIXELSY));
98 if (adapter->StateFlags & DISPLAY_DEVICE_MODESPRUNED)
101 wcscpy(monitor->win32.adapterName, adapter->DeviceName);
102 WideCharToMultiByte(CP_UTF8, 0,
103 adapter->DeviceName, -1,
104 monitor->win32.publicAdapterName,
105 sizeof(monitor->win32.publicAdapterName),
110 wcscpy(monitor->win32.displayName, display->DeviceName);
111 WideCharToMultiByte(CP_UTF8, 0,
112 display->DeviceName, -1,
113 monitor->win32.publicDisplayName,
114 sizeof(monitor->win32.publicDisplayName),
118 rect.left = dm.dmPosition.x;
119 rect.top = dm.dmPosition.y;
120 rect.right = dm.dmPosition.x + dm.dmPelsWidth;
121 rect.bottom = dm.dmPosition.y + dm.dmPelsHeight;
136 int i, disconnectedCount;
138 DWORD adapterIndex, displayIndex;
139 DISPLAY_DEVICEW adapter,
display;
143 if (disconnectedCount)
151 for (adapterIndex = 0; ; adapterIndex++)
155 ZeroMemory(&adapter,
sizeof(adapter));
156 adapter.cb =
sizeof(adapter);
158 if (!EnumDisplayDevicesW(
NULL, adapterIndex, &adapter, 0))
164 if (adapter.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
167 for (displayIndex = 0; ; displayIndex++)
169 ZeroMemory(&display,
sizeof(display));
172 if (!EnumDisplayDevicesW(adapter.DeviceName, displayIndex, &display, 0))
178 for (i = 0; i < disconnectedCount; i++)
180 if (disconnected[i] &&
181 wcscmp(disconnected[i]->win32.displayName,
182 display.DeviceName) == 0)
184 disconnected[
i] =
NULL;
189 if (i < disconnectedCount)
206 if (displayIndex == 0)
208 for (i = 0; i < disconnectedCount; i++)
210 if (disconnected[i] &&
211 wcscmp(disconnected[i]->win32.adapterName,
212 adapter.DeviceName) == 0)
214 disconnected[
i] =
NULL;
219 if (i < disconnectedCount)
233 for (i = 0; i < disconnectedCount; i++)
256 ZeroMemory(&dm,
sizeof(dm));
257 dm.dmSize =
sizeof(dm);
258 dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL |
260 dm.dmPelsWidth = best->
width;
261 dm.dmPelsHeight = best->
height;
265 if (dm.dmBitsPerPel < 15 || dm.dmBitsPerPel >= 24)
266 dm.dmBitsPerPel = 32;
268 result = ChangeDisplaySettingsExW(monitor->win32.adapterName,
273 if (result == DISP_CHANGE_SUCCESSFUL)
277 const char* description =
"Unknown error";
279 if (result == DISP_CHANGE_BADDUALVIEW)
280 description =
"The system uses DualView";
281 else if (result == DISP_CHANGE_BADFLAGS)
282 description =
"Invalid flags";
283 else if (result == DISP_CHANGE_BADMODE)
284 description =
"Graphics mode not supported";
285 else if (result == DISP_CHANGE_BADPARAM)
286 description =
"Invalid parameter";
287 else if (result == DISP_CHANGE_FAILED)
288 description =
"Graphics mode failed";
289 else if (result == DISP_CHANGE_NOTUPDATED)
290 description =
"Failed to write to registry";
291 else if (result == DISP_CHANGE_RESTART)
292 description =
"Computer restart required";
295 "Win32: Failed to set video mode: %s",
304 if (monitor->win32.modeChanged)
306 ChangeDisplaySettingsExW(monitor->win32.adapterName,
320 const HDC dc = GetDC(
NULL);
321 xdpi = GetDeviceCaps(dc, LOGPIXELSX);
322 ydpi = GetDeviceCaps(dc, LOGPIXELSY);
344 ZeroMemory(&dm,
sizeof(dm));
345 dm.dmSize =
sizeof(dm);
347 EnumDisplaySettingsExW(monitor->win32.adapterName,
348 ENUM_CURRENT_SETTINGS,
353 *xpos = dm.dmPosition.x;
355 *ypos = dm.dmPosition.y;
359 float* xscale,
float* yscale)
366 int modeIndex = 0,
size = 0;
377 ZeroMemory(&dm,
sizeof(dm));
378 dm.dmSize =
sizeof(dm);
380 if (!EnumDisplaySettingsW(monitor->win32.adapterName, modeIndex, &dm))
386 if (dm.dmBitsPerPel < 15)
389 mode.
width = dm.dmPelsWidth;
390 mode.
height = dm.dmPelsHeight;
397 for (i = 0; i < *
count; i++)
407 if (monitor->win32.modesPruned)
410 if (ChangeDisplaySettingsExW(monitor->win32.adapterName,
414 NULL) != DISP_CHANGE_SUCCESSFUL)
427 result[*count - 1] =
mode;
444 ZeroMemory(&dm,
sizeof(dm));
445 dm.dmSize =
sizeof(dm);
447 EnumDisplaySettingsW(monitor->win32.adapterName, ENUM_CURRENT_SETTINGS, &dm);
449 mode->
width = dm.dmPelsWidth;
450 mode->
height = dm.dmPelsHeight;
463 dc = CreateDCW(L
"DISPLAY", monitor->win32.adapterName,
NULL,
NULL);
464 GetDeviceGammaRamp(dc, values);
469 memcpy(ramp->
red, values + 0, 256 *
sizeof(
unsigned short));
470 memcpy(ramp->
green, values + 256, 256 *
sizeof(
unsigned short));
471 memcpy(ramp->
blue, values + 512, 256 *
sizeof(
unsigned short));
479 if (ramp->
size != 256)
482 "Win32: Gamma ramp size must be 256");
486 memcpy(values + 0, ramp->
red, 256 *
sizeof(
unsigned short));
487 memcpy(values + 256, ramp->
green, 256 *
sizeof(
unsigned short));
488 memcpy(values + 512, ramp->
blue, 256 *
sizeof(
unsigned short));
490 dc = CreateDCW(L
"DISPLAY", monitor->win32.adapterName,
NULL,
NULL);
491 SetDeviceGammaRamp(dc, values);
504 return monitor->win32.publicAdapterName;
511 return monitor->win32.publicDisplayName;
void _glfwGetMonitorContentScaleWin32(HMONITOR handle, float *xscale, float *yscale)
void _glfwRestoreVideoModeWin32(_GLFWmonitor *monitor)
GLuint const GLchar * name
static BOOL CALLBACK monitorCallback(HMONITOR handle, HDC dc, RECT *rect, LPARAM data)
void _glfwAllocGammaArrays(GLFWgammaramp *ramp, unsigned int size)
GLuint64 GLenum void * handle
void _glfwPlatformGetVideoMode(_GLFWmonitor *monitor, GLFWvidmode *mode)
void _glfwSplitBPP(int bpp, int *red, int *green, int *blue)
struct GLFWmonitor GLFWmonitor
char * _glfwCreateUTF8FromWideStringWin32(const WCHAR *source)
_GLFWmonitor * _glfwAllocMonitor(const char *name, int widthMM, int heightMM)
GLFWvidmode * _glfwPlatformGetVideoModes(_GLFWmonitor *monitor, int *count)
void _glfwPlatformFreeMonitor(_GLFWmonitor *monitor)
void _glfwPlatformGetMonitorContentScale(_GLFWmonitor *monitor, float *xscale, float *yscale)
#define GLFW_DISCONNECTED
#define _GLFW_REQUIRE_INIT_OR_RETURN(x)
void _glfwPlatformGetGammaRamp(_GLFWmonitor *monitor, GLFWgammaramp *ramp)
#define GLFW_PLATFORM_ERROR
A platform-specific error occurred that does not match any of the more specific categories.
void _glfwInputError(int code, const char *format,...)
GLFWAPI const char * glfwGetWin32Monitor(GLFWmonitor *handle)
void _glfwPollMonitorsWin32(void)
void _glfwInputMonitor(_GLFWmonitor *monitor, int action, int placement)
void _glfwSetVideoModeWin32(_GLFWmonitor *monitor, const GLFWvidmode *desired)
int _glfwCompareVideoModes(const GLFWvidmode *first, const GLFWvidmode *second)
GLsizei const GLfloat * values
#define _GLFW_INSERT_FIRST
GLFWAPI const char * glfwGetWin32Adapter(GLFWmonitor *handle)
static _GLFWmonitor * createMonitor(DISPLAY_DEVICEW *adapter, DISPLAY_DEVICEW *display)
void _glfwPlatformGetMonitorPos(_GLFWmonitor *monitor, int *xpos, int *ypos)
const GLFWvidmode * _glfwChooseVideoMode(_GLFWmonitor *monitor, const GLFWvidmode *desired)
void _glfwPlatformSetGammaRamp(_GLFWmonitor *monitor, const GLFWgammaramp *ramp)
#define _GLFW_INSERT_LAST