34 {0x4d1e55b2,0xf16f,0x11cf,{0x88,0xcb,0x00,0x11,0x11,0x00,0x00,0x30}};
36 #define GUID_DEVINTERFACE_HID _glfw_GUID_DEVINTERFACE_HID 38 #if defined(_GLFW_USE_HYBRID_HPG) || defined(_GLFW_USE_OPTIMUS_HPG) 44 __declspec(dllexport) DWORD NvOptimusEnablement = 1;
50 __declspec(dllexport)
int AmdPowerXpressRequestHighPerformance = 1;
52 #endif // _GLFW_USE_HYBRID_HPG 54 #if defined(_GLFW_BUILD_DLL) 58 BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
63 #endif // _GLFW_BUILD_DLL 69 _glfw.win32.winmm.instance = LoadLibraryA(
"winmm.dll");
70 if (!
_glfw.win32.winmm.instance)
73 "Win32: Failed to load winmm.dll");
78 GetProcAddress(
_glfw.win32.winmm.instance,
"timeGetTime");
80 _glfw.win32.user32.instance = LoadLibraryA(
"user32.dll");
81 if (!
_glfw.win32.user32.instance)
84 "Win32: Failed to load user32.dll");
89 GetProcAddress(
_glfw.win32.user32.instance,
"SetProcessDPIAware");
91 GetProcAddress(
_glfw.win32.user32.instance,
"ChangeWindowMessageFilterEx");
93 GetProcAddress(
_glfw.win32.user32.instance,
"EnableNonClientDpiScaling");
95 GetProcAddress(
_glfw.win32.user32.instance,
"SetProcessDpiAwarenessContext");
97 GetProcAddress(
_glfw.win32.user32.instance,
"GetDpiForWindow");
99 GetProcAddress(
_glfw.win32.user32.instance,
"AdjustWindowRectExForDpi");
101 _glfw.win32.dinput8.instance = LoadLibraryA(
"dinput8.dll");
102 if (
_glfw.win32.dinput8.instance)
105 GetProcAddress(
_glfw.win32.dinput8.instance,
"DirectInput8Create");
110 const char*
names[] =
120 for (i = 0; names[
i]; i++)
122 _glfw.win32.xinput.instance = LoadLibraryA(names[i]);
123 if (
_glfw.win32.xinput.instance)
126 GetProcAddress(
_glfw.win32.xinput.instance,
"XInputGetCapabilities");
128 GetProcAddress(
_glfw.win32.xinput.instance,
"XInputGetState");
135 _glfw.win32.dwmapi.instance = LoadLibraryA(
"dwmapi.dll");
136 if (
_glfw.win32.dwmapi.instance)
139 GetProcAddress(
_glfw.win32.dwmapi.instance,
"DwmIsCompositionEnabled");
141 GetProcAddress(
_glfw.win32.dwmapi.instance,
"DwmFlush");
143 GetProcAddress(
_glfw.win32.dwmapi.instance,
"DwmEnableBlurBehindWindow");
146 _glfw.win32.shcore.instance = LoadLibraryA(
"shcore.dll");
147 if (
_glfw.win32.shcore.instance)
150 GetProcAddress(
_glfw.win32.shcore.instance,
"SetProcessDpiAwareness");
152 GetProcAddress(
_glfw.win32.shcore.instance,
"GetDpiForMonitor");
155 _glfw.win32.ntdll.instance = LoadLibraryA(
"ntdll.dll");
156 if (
_glfw.win32.ntdll.instance)
159 GetProcAddress(
_glfw.win32.ntdll.instance,
"RtlVerifyVersionInfo");
169 if (
_glfw.win32.xinput.instance)
170 FreeLibrary(
_glfw.win32.xinput.instance);
172 if (
_glfw.win32.dinput8.instance)
173 FreeLibrary(
_glfw.win32.dinput8.instance);
175 if (
_glfw.win32.winmm.instance)
176 FreeLibrary(
_glfw.win32.winmm.instance);
178 if (
_glfw.win32.user32.instance)
179 FreeLibrary(
_glfw.win32.user32.instance);
181 if (
_glfw.win32.dwmapi.instance)
182 FreeLibrary(
_glfw.win32.dwmapi.instance);
184 if (
_glfw.win32.shcore.instance)
185 FreeLibrary(
_glfw.win32.shcore.instance);
187 if (
_glfw.win32.ntdll.instance)
188 FreeLibrary(
_glfw.win32.ntdll.instance);
197 memset(
_glfw.win32.keycodes, -1,
sizeof(
_glfw.win32.keycodes));
198 memset(
_glfw.win32.scancodes, -1,
sizeof(
_glfw.win32.scancodes));
323 for (scancode = 0; scancode < 512; scancode++)
325 if (
_glfw.win32.keycodes[scancode] > 0)
326 _glfw.win32.scancodes[
_glfw.win32.keycodes[scancode]] = scancode;
335 HWND
window = CreateWindowExW(WS_EX_OVERLAPPEDWINDOW,
337 L
"GLFW message window",
338 WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
341 GetModuleHandleW(
NULL),
346 "Win32: Failed to create helper window");
352 ShowWindow(window, SW_HIDE);
356 DEV_BROADCAST_DEVICEINTERFACE_W dbi;
357 ZeroMemory(&dbi,
sizeof(dbi));
358 dbi.dbcc_size =
sizeof(dbi);
359 dbi.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
362 _glfw.win32.deviceNotificationHandle =
363 RegisterDeviceNotificationW(window,
364 (DEV_BROADCAST_HDR*) &dbi,
365 DEVICE_NOTIFY_WINDOW_HANDLE);
368 while (PeekMessageW(&msg,
_glfw.win32.helperWindowHandle, 0, 0, PM_REMOVE))
370 TranslateMessage(&msg);
371 DispatchMessageW(&msg);
389 count = MultiByteToWideChar(CP_UTF8, 0, source, -1,
NULL, 0);
393 "Win32: Failed to convert string from UTF-8");
397 target = calloc(count,
sizeof(WCHAR));
399 if (!MultiByteToWideChar(CP_UTF8, 0, source, -1, target, count))
402 "Win32: Failed to convert string from UTF-8");
417 size = WideCharToMultiByte(CP_UTF8, 0, source, -1,
NULL, 0,
NULL,
NULL);
421 "Win32: Failed to convert string to UTF-8");
425 target = calloc(size, 1);
427 if (!WideCharToMultiByte(CP_UTF8, 0, source, -1, target, size,
NULL,
NULL))
430 "Win32: Failed to convert string to UTF-8");
445 FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM |
446 FORMAT_MESSAGE_IGNORE_INSERTS |
447 FORMAT_MESSAGE_MAX_WIDTH_MASK,
449 GetLastError() & 0xffff,
450 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
454 WideCharToMultiByte(CP_UTF8, 0, buffer, -1, message,
sizeof(message),
NULL,
NULL);
466 memset(
_glfw.win32.keynames, 0,
sizeof(
_glfw.win32.keynames));
474 scancode =
_glfw.win32.scancodes[
key];
481 VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3,
482 VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7,
483 VK_NUMPAD8, VK_NUMPAD9, VK_DECIMAL, VK_DIVIDE,
484 VK_MULTIPLY, VK_SUBTRACT, VK_ADD
490 vk = MapVirtualKey(scancode, MAPVK_VSC_TO_VK);
492 length = ToUnicode(vk, scancode, state,
493 chars,
sizeof(chars) /
sizeof(WCHAR),
498 length = ToUnicode(vk, scancode, state,
499 chars,
sizeof(chars) /
sizeof(WCHAR),
506 WideCharToMultiByte(CP_UTF8, 0, chars, 1,
507 _glfw.win32.keynames[key],
508 sizeof(
_glfw.win32.keynames[key]),
517 OSVERSIONINFOEXW osvi = {
sizeof(osvi), major, minor, 0, 0, {0}, sp };
518 DWORD
mask = VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR;
519 ULONGLONG cond = VerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL);
520 cond = VerSetConditionMask(cond, VER_MINORVERSION, VER_GREATER_EQUAL);
521 cond = VerSetConditionMask(cond, VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL);
532 OSVERSIONINFOEXW osvi = {
sizeof(osvi), 10, 0, build };
533 DWORD
mask = VER_MAJORVERSION | VER_MINORVERSION | VER_BUILDNUMBER;
534 ULONGLONG cond = VerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL);
535 cond = VerSetConditionMask(cond, VER_MINORVERSION, VER_GREATER_EQUAL);
536 cond = VerSetConditionMask(cond, VER_BUILDNUMBER, VER_GREATER_EQUAL);
553 SystemParametersInfoW(SPI_GETFOREGROUNDLOCKTIMEOUT, 0,
554 &
_glfw.win32.foregroundLockTimeout, 0);
555 SystemParametersInfoW(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, UIntToPtr(0),
575 if (!
_glfw.win32.helperWindowHandle)
587 if (
_glfw.win32.deviceNotificationHandle)
588 UnregisterDeviceNotification(
_glfw.win32.deviceNotificationHandle);
590 if (
_glfw.win32.helperWindowHandle)
591 DestroyWindow(
_glfw.win32.helperWindowHandle);
596 SystemParametersInfoW(SPI_SETFOREGROUNDLOCKTIMEOUT, 0,
597 UIntToPtr(
_glfw.win32.foregroundLockTimeout),
600 free(
_glfw.win32.clipboardString);
601 free(
_glfw.win32.rawInput);
614 #if defined(__MINGW32__) 616 #elif defined(_MSC_VER) 619 #if defined(_GLFW_USE_HYBRID_HPG) || defined(_GLFW_USE_OPTIMUS_HPG) 622 #if defined(_GLFW_BUILD_DLL) #define GLFW_KEY_SCROLL_LOCK
static void createKeyTables(void)
GLenum GLuint GLenum GLsizei const GLchar * message
#define GLFW_KEY_RIGHT_CONTROL
WCHAR * _glfwCreateWideStringFromUTF8Win32(const char *source)
#define GLFW_KEY_KP_DIVIDE
#define _GLFW_VERSION_NUMBER
#define GLFW_KEY_SEMICOLON
static GLFWbool loadLibraries(void)
static GLFWwindow * window
void _glfwTerminateJoysticksWin32(void)
#define GLFW_KEY_GRAVE_ACCENT
char * _glfwCreateUTF8FromWideStringWin32(const WCHAR *source)
#define GLFW_KEY_LEFT_SHIFT
void _glfwPlatformTerminate(void)
BOOL _glfwIsWindowsVersionOrGreaterWin32(WORD major, WORD minor, WORD sp)
#define GLFW_KEY_PAGE_DOWN
#define GLFW_KEY_LEFT_BRACKET
#define GLFW_KEY_BACKSPACE
#define GLFW_KEY_KP_DECIMAL
const char * _glfwPlatformGetVersionString(void)
#define GLFW_KEY_RIGHT_SUPER
#define GUID_DEVINTERFACE_HID
#define GLFW_PLATFORM_ERROR
A platform-specific error occurred that does not match any of the more specific categories.
#define GLFW_KEY_CAPS_LOCK
#define GLFW_KEY_KP_MULTIPLY
void _glfwInputErrorWin32(int error, const char *description)
void _glfwTerminateEGL(void)
#define GLFW_KEY_NUM_LOCK
static void freeLibraries(void)
BOOL _glfwIsWindows10BuildOrGreaterWin32(WORD build)
void _glfwInputError(int code, const char *format,...)
static const GUID _glfw_GUID_DEVINTERFACE_HID
int _glfwPlatformInit(void)
void _glfwPollMonitorsWin32(void)
void _glfwInitJoysticksWin32(void)
#define GLFW_KEY_RIGHT_BRACKET
static HWND createHelperWindow(void)
void _glfwTerminateWGL(void)
#define GLFW_KEY_KP_ENTER
#define GLFW_KEY_KP_SUBTRACT
#define GLFW_KEY_RIGHT_ALT
#define GLFW_KEY_PRINT_SCREEN
#define GLFW_KEY_LEFT_CONTROL
#define GLFW_KEY_KP_EQUAL
GLsizei GLsizei GLchar * source
GLenum GLuint GLenum GLsizei length
#define GLFW_KEY_LEFT_ALT
#define _GLFW_MESSAGE_SIZE
#define GLFW_KEY_RIGHT_SHIFT
#define GLFW_KEY_BACKSLASH
#define GLFW_KEY_APOSTROPHE
void _glfwUpdateKeyNamesWin32(void)
#define GLFW_KEY_LEFT_SUPER