win32_platform.h
Go to the documentation of this file.
1 //========================================================================
2 // GLFW 3.3 Win32 - www.glfw.org
3 //------------------------------------------------------------------------
4 // Copyright (c) 2002-2006 Marcus Geelnard
5 // Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org>
6 //
7 // This software is provided 'as-is', without any express or implied
8 // warranty. In no event will the authors be held liable for any damages
9 // arising from the use of this software.
10 //
11 // Permission is granted to anyone to use this software for any purpose,
12 // including commercial applications, and to alter it and redistribute it
13 // freely, subject to the following restrictions:
14 //
15 // 1. The origin of this software must not be misrepresented; you must not
16 // claim that you wrote the original software. If you use this software
17 // in a product, an acknowledgment in the product documentation would
18 // be appreciated but is not required.
19 //
20 // 2. Altered source versions must be plainly marked as such, and must not
21 // be misrepresented as being the original software.
22 //
23 // 3. This notice may not be removed or altered from any source
24 // distribution.
25 //
26 //========================================================================
27 
28 // We don't need all the fancy stuff
29 #ifndef NOMINMAX
30  #define NOMINMAX
31 #endif
32 
33 #ifndef VC_EXTRALEAN
34  #define VC_EXTRALEAN
35 #endif
36 
37 #ifndef WIN32_LEAN_AND_MEAN
38  #define WIN32_LEAN_AND_MEAN
39 #endif
40 
41 // This is a workaround for the fact that glfw3.h needs to export APIENTRY (for
42 // example to allow applications to correctly declare a GL_ARB_debug_output
43 // callback) but windows.h assumes no one will define APIENTRY before it does
44 #undef APIENTRY
45 
46 // GLFW on Windows is Unicode only and does not work in MBCS mode
47 #ifndef UNICODE
48  #define UNICODE
49 #endif
50 
51 // GLFW requires Windows XP or later
52 #if WINVER < 0x0501
53  #undef WINVER
54  #define WINVER 0x0501
55 #endif
56 #if _WIN32_WINNT < 0x0501
57  #undef _WIN32_WINNT
58  #define _WIN32_WINNT 0x0501
59 #endif
60 
61 // GLFW uses DirectInput8 interfaces
62 #define DIRECTINPUT_VERSION 0x0800
63 
64 #include <wctype.h>
65 #include <windows.h>
66 #include <dinput.h>
67 #include <xinput.h>
68 #include <dbt.h>
69 
70 // HACK: Define macros that some windows.h variants don't
71 #ifndef WM_MOUSEHWHEEL
72  #define WM_MOUSEHWHEEL 0x020E
73 #endif
74 #ifndef WM_DWMCOMPOSITIONCHANGED
75  #define WM_DWMCOMPOSITIONCHANGED 0x031E
76 #endif
77 #ifndef WM_COPYGLOBALDATA
78  #define WM_COPYGLOBALDATA 0x0049
79 #endif
80 #ifndef WM_UNICHAR
81  #define WM_UNICHAR 0x0109
82 #endif
83 #ifndef UNICODE_NOCHAR
84  #define UNICODE_NOCHAR 0xFFFF
85 #endif
86 #ifndef WM_DPICHANGED
87  #define WM_DPICHANGED 0x02E0
88 #endif
89 #ifndef GET_XBUTTON_WPARAM
90  #define GET_XBUTTON_WPARAM(w) (HIWORD(w))
91 #endif
92 #ifndef EDS_ROTATEDMODE
93  #define EDS_ROTATEDMODE 0x00000004
94 #endif
95 #ifndef DISPLAY_DEVICE_ACTIVE
96  #define DISPLAY_DEVICE_ACTIVE 0x00000001
97 #endif
98 #ifndef _WIN32_WINNT_WINBLUE
99  #define _WIN32_WINNT_WINBLUE 0x0602
100 #endif
101 #ifndef WM_GETDPISCALEDSIZE
102  #define WM_GETDPISCALEDSIZE 0x02e4
103 #endif
104 #ifndef USER_DEFAULT_SCREEN_DPI
105  #define USER_DEFAULT_SCREEN_DPI 96
106 #endif
107 
108 #if WINVER < 0x0601
109 typedef struct
110 {
111  DWORD cbSize;
112  DWORD ExtStatus;
114 #ifndef MSGFLT_ALLOW
115  #define MSGFLT_ALLOW 1
116 #endif
117 #endif /*Windows 7*/
118 
119 #if WINVER < 0x0600
120 #define DWM_BB_ENABLE 0x00000001
121 #define DWM_BB_BLURREGION 0x00000002
122 typedef struct
123 {
124  DWORD dwFlags;
125  BOOL fEnable;
126  HRGN hRgnBlur;
129 #else
130  #include <dwmapi.h>
131 #endif /*Windows Vista*/
132 
133 #ifndef DPI_ENUMS_DECLARED
134 typedef enum
135 {
140 typedef enum
141 {
147 #endif /*DPI_ENUMS_DECLARED*/
148 
149 #ifndef DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2
150 #define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 ((HANDLE) -4)
151 #endif /*DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2*/
152 
153 // HACK: Define versionhelpers.h functions manually as MinGW lacks the header
154 #define IsWindowsXPOrGreater() \
155  _glfwIsWindowsVersionOrGreaterWin32(HIBYTE(_WIN32_WINNT_WINXP), \
156  LOBYTE(_WIN32_WINNT_WINXP), 0)
157 #define IsWindowsVistaOrGreater() \
158  _glfwIsWindowsVersionOrGreaterWin32(HIBYTE(_WIN32_WINNT_VISTA), \
159  LOBYTE(_WIN32_WINNT_VISTA), 0)
160 #define IsWindows7OrGreater() \
161  _glfwIsWindowsVersionOrGreaterWin32(HIBYTE(_WIN32_WINNT_WIN7), \
162  LOBYTE(_WIN32_WINNT_WIN7), 0)
163 #define IsWindows8OrGreater() \
164  _glfwIsWindowsVersionOrGreaterWin32(HIBYTE(_WIN32_WINNT_WIN8), \
165  LOBYTE(_WIN32_WINNT_WIN8), 0)
166 #define IsWindows8Point1OrGreater() \
167  _glfwIsWindowsVersionOrGreaterWin32(HIBYTE(_WIN32_WINNT_WINBLUE), \
168  LOBYTE(_WIN32_WINNT_WINBLUE), 0)
169 
170 #define _glfwIsWindows10AnniversaryUpdateOrGreaterWin32() \
171  _glfwIsWindows10BuildOrGreaterWin32(14393)
172 #define _glfwIsWindows10CreatorsUpdateOrGreaterWin32() \
173  _glfwIsWindows10BuildOrGreaterWin32(15063)
174 
175 // HACK: Define macros that some xinput.h variants don't
176 #ifndef XINPUT_CAPS_WIRELESS
177  #define XINPUT_CAPS_WIRELESS 0x0002
178 #endif
179 #ifndef XINPUT_DEVSUBTYPE_WHEEL
180  #define XINPUT_DEVSUBTYPE_WHEEL 0x02
181 #endif
182 #ifndef XINPUT_DEVSUBTYPE_ARCADE_STICK
183  #define XINPUT_DEVSUBTYPE_ARCADE_STICK 0x03
184 #endif
185 #ifndef XINPUT_DEVSUBTYPE_FLIGHT_STICK
186  #define XINPUT_DEVSUBTYPE_FLIGHT_STICK 0x04
187 #endif
188 #ifndef XINPUT_DEVSUBTYPE_DANCE_PAD
189  #define XINPUT_DEVSUBTYPE_DANCE_PAD 0x05
190 #endif
191 #ifndef XINPUT_DEVSUBTYPE_GUITAR
192  #define XINPUT_DEVSUBTYPE_GUITAR 0x06
193 #endif
194 #ifndef XINPUT_DEVSUBTYPE_DRUM_KIT
195  #define XINPUT_DEVSUBTYPE_DRUM_KIT 0x08
196 #endif
197 #ifndef XINPUT_DEVSUBTYPE_ARCADE_PAD
198  #define XINPUT_DEVSUBTYPE_ARCADE_PAD 0x13
199 #endif
200 #ifndef XUSER_MAX_COUNT
201  #define XUSER_MAX_COUNT 4
202 #endif
203 
204 // HACK: Define macros that some dinput.h variants don't
205 #ifndef DIDFT_OPTIONAL
206  #define DIDFT_OPTIONAL 0x80000000
207 #endif
208 
209 // winmm.dll function pointer typedefs
210 typedef DWORD (WINAPI * PFN_timeGetTime)(void);
211 #define timeGetTime _glfw.win32.winmm.GetTime
212 
213 // xinput.dll function pointer typedefs
214 typedef DWORD (WINAPI * PFN_XInputGetCapabilities)(DWORD,DWORD,XINPUT_CAPABILITIES*);
215 typedef DWORD (WINAPI * PFN_XInputGetState)(DWORD,XINPUT_STATE*);
216 #define XInputGetCapabilities _glfw.win32.xinput.GetCapabilities
217 #define XInputGetState _glfw.win32.xinput.GetState
218 
219 // dinput8.dll function pointer typedefs
220 typedef HRESULT (WINAPI * PFN_DirectInput8Create)(HINSTANCE,DWORD,REFIID,LPVOID*,LPUNKNOWN);
221 #define DirectInput8Create _glfw.win32.dinput8.Create
222 
223 // user32.dll function pointer typedefs
224 typedef BOOL (WINAPI * PFN_SetProcessDPIAware)(void);
225 typedef BOOL (WINAPI * PFN_ChangeWindowMessageFilterEx)(HWND,UINT,DWORD,CHANGEFILTERSTRUCT*);
226 typedef BOOL (WINAPI * PFN_EnableNonClientDpiScaling)(HWND);
227 typedef BOOL (WINAPI * PFN_SetProcessDpiAwarenessContext)(HANDLE);
228 typedef UINT (WINAPI * PFN_GetDpiForWindow)(HWND);
229 typedef BOOL (WINAPI * PFN_AdjustWindowRectExForDpi)(LPRECT,DWORD,BOOL,DWORD,UINT);
230 #define SetProcessDPIAware _glfw.win32.user32.SetProcessDPIAware_
231 #define ChangeWindowMessageFilterEx _glfw.win32.user32.ChangeWindowMessageFilterEx_
232 #define EnableNonClientDpiScaling _glfw.win32.user32.EnableNonClientDpiScaling_
233 #define SetProcessDpiAwarenessContext _glfw.win32.user32.SetProcessDpiAwarenessContext_
234 #define GetDpiForWindow _glfw.win32.user32.GetDpiForWindow_
235 #define AdjustWindowRectExForDpi _glfw.win32.user32.AdjustWindowRectExForDpi_
236 
237 // dwmapi.dll function pointer typedefs
238 typedef HRESULT (WINAPI * PFN_DwmIsCompositionEnabled)(BOOL*);
239 typedef HRESULT (WINAPI * PFN_DwmFlush)(VOID);
240 typedef HRESULT(WINAPI * PFN_DwmEnableBlurBehindWindow)(HWND,const DWM_BLURBEHIND*);
241 #define DwmIsCompositionEnabled _glfw.win32.dwmapi.IsCompositionEnabled
242 #define DwmFlush _glfw.win32.dwmapi.Flush
243 #define DwmEnableBlurBehindWindow _glfw.win32.dwmapi.EnableBlurBehindWindow
244 
245 // shcore.dll function pointer typedefs
247 typedef HRESULT (WINAPI * PFN_GetDpiForMonitor)(HMONITOR,MONITOR_DPI_TYPE,UINT*,UINT*);
248 #define SetProcessDpiAwareness _glfw.win32.shcore.SetProcessDpiAwareness_
249 #define GetDpiForMonitor _glfw.win32.shcore.GetDpiForMonitor_
250 
251 // ntdll.dll function pointer typedefs
252 typedef LONG (WINAPI * PFN_RtlVerifyVersionInfo)(OSVERSIONINFOEXW*,ULONG,ULONGLONG);
253 #define RtlVerifyVersionInfo _glfw.win32.ntdll.RtlVerifyVersionInfo_
254 
256 
258 {
260  const void* pNext;
262  HINSTANCE hinstance;
263  HWND hwnd;
265 
268 
269 #include "win32_joystick.h"
270 #include "wgl_context.h"
271 #include "egl_context.h"
272 #include "osmesa_context.h"
273 
274 #if !defined(_GLFW_WNDCLASSNAME)
275  #define _GLFW_WNDCLASSNAME L"GLFW30"
276 #endif
277 
278 #define _glfw_dlopen(name) LoadLibraryA(name)
279 #define _glfw_dlclose(handle) FreeLibrary((HMODULE) handle)
280 #define _glfw_dlsym(handle, name) GetProcAddress((HMODULE) handle, name)
281 
282 #define _GLFW_EGL_NATIVE_WINDOW ((EGLNativeWindowType) window->win32.handle)
283 #define _GLFW_EGL_NATIVE_DISPLAY EGL_DEFAULT_DISPLAY
284 
285 #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowWin32 win32
286 #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryWin32 win32
287 #define _GLFW_PLATFORM_LIBRARY_TIMER_STATE _GLFWtimerWin32 win32
288 #define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorWin32 win32
289 #define _GLFW_PLATFORM_CURSOR_STATE _GLFWcursorWin32 win32
290 #define _GLFW_PLATFORM_TLS_STATE _GLFWtlsWin32 win32
291 #define _GLFW_PLATFORM_MUTEX_STATE _GLFWmutexWin32 win32
292 
293 
294 // Win32-specific per-window data
295 //
296 typedef struct _GLFWwindowWin32
297 {
298  HWND handle;
299  HICON bigIcon;
300  HICON smallIcon;
301 
306  // Whether to enable framebuffer transparency on DWM
309 
310  // The last received cursor position, regardless of source
311  int lastCursorPosX, lastCursorPosY;
312 
314 
315 // Win32-specific global data
316 //
317 typedef struct _GLFWlibraryWin32
318 {
324  short int keycodes[512];
325  short int scancodes[GLFW_KEY_LAST + 1];
326  char keynames[GLFW_KEY_LAST + 1][5];
327  // Where to place the cursor when re-enabled
328  double restoreCursorPosX, restoreCursorPosY;
329  // The window whose disabled cursor mode is active
331  RAWINPUT* rawInput;
334 
335  struct {
336  HINSTANCE instance;
338  } winmm;
339 
340  struct {
341  HINSTANCE instance;
343  IDirectInput8W* api;
344  } dinput8;
345 
346  struct {
347  HINSTANCE instance;
350  } xinput;
351 
352  struct {
353  HINSTANCE instance;
360  } user32;
361 
362  struct {
363  HINSTANCE instance;
367  } dwmapi;
368 
369  struct {
370  HINSTANCE instance;
373  } shcore;
374 
375  struct {
376  HINSTANCE instance;
378  } ntdll;
379 
381 
382 // Win32-specific per-monitor data
383 //
384 typedef struct _GLFWmonitorWin32
385 {
386  HMONITOR handle;
387  // This size matches the static size of DISPLAY_DEVICE.DeviceName
388  WCHAR adapterName[32];
389  WCHAR displayName[32];
390  char publicAdapterName[32];
391  char publicDisplayName[32];
394 
396 
397 // Win32-specific per-cursor data
398 //
399 typedef struct _GLFWcursorWin32
400 {
401  HCURSOR handle;
402 
404 
405 // Win32-specific global timer data
406 //
407 typedef struct _GLFWtimerWin32
408 {
411 
413 
414 // Win32-specific thread local storage data
415 //
416 typedef struct _GLFWtlsWin32
417 {
419  DWORD index;
420 
421 } _GLFWtlsWin32;
422 
423 // Win32-specific mutex data
424 //
425 typedef struct _GLFWmutexWin32
426 {
428  CRITICAL_SECTION section;
429 
431 
432 
435 
436 WCHAR* _glfwCreateWideStringFromUTF8Win32(const char* source);
437 char* _glfwCreateUTF8FromWideStringWin32(const WCHAR* source);
438 BOOL _glfwIsWindowsVersionOrGreaterWin32(WORD major, WORD minor, WORD sp);
440 void _glfwInputErrorWin32(int error, const char* description);
441 void _glfwUpdateKeyNamesWin32(void);
442 
443 void _glfwInitTimerWin32(void);
444 
445 void _glfwPollMonitorsWin32(void);
446 void _glfwSetVideoModeWin32(_GLFWmonitor* monitor, const GLFWvidmode* desired);
448 void _glfwGetMonitorContentScaleWin32(HMONITOR handle, float* xscale, float* yscale);
449 
struct _GLFWtimerWin32 _GLFWtimerWin32
void _glfwSetVideoModeWin32(_GLFWmonitor *monitor, const GLFWvidmode *desired)
BOOL(WINAPI * PFN_SetProcessDpiAwarenessContext)(HANDLE)
struct _GLFWmutexWin32 _GLFWmutexWin32
HRESULT(WINAPI * PFN_DwmEnableBlurBehindWindow)(HWND, const DWM_BLURBEHIND *)
struct VkWin32SurfaceCreateInfoKHR VkWin32SurfaceCreateInfoKHR
VkStructureType
Definition: vulkan_core.h:159
struct _GLFWmonitorWin32 _GLFWmonitorWin32
VkResult(APIENTRY * PFN_vkCreateWin32SurfaceKHR)(VkInstance, const VkWin32SurfaceCreateInfoKHR *, const VkAllocationCallbacks *, VkSurfaceKHR *)
PFN_AdjustWindowRectExForDpi AdjustWindowRectExForDpi_
uint32_t VkBool32
Definition: vulkan_core.h:67
HRESULT(WINAPI * PFN_DwmFlush)(VOID)
typedef void(APIENTRY *GLDEBUGPROC)(GLenum source
VkBool32(APIENTRY * PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR)(VkPhysicalDevice, uint32_t)
VkResult
Definition: vulkan_core.h:122
HRESULT(WINAPI * PFN_GetDpiForMonitor)(HMONITOR, MONITOR_DPI_TYPE, UINT *, UINT *)
PFN_DirectInput8Create Create
#define APIENTRY
struct _GLFWtlsWin32 _GLFWtlsWin32
PFN_GetDpiForWindow GetDpiForWindow_
struct _GLFWwindowWin32 _GLFWwindowWin32
GLuint64 GLenum void * handle
Definition: glext.h:7785
IDirectInput8W * api
PROCESS_DPI_AWARENESS
PFN_XInputGetState GetState
PFN_DwmFlush Flush
_GLFWwindow * disabledCursorWindow
HRESULT(WINAPI * PFN_SetProcessDpiAwareness)(PROCESS_DPI_AWARENESS)
PFN_SetProcessDPIAware SetProcessDPIAware_
struct _GLFWcursorWin32 _GLFWcursorWin32
GLFWbool cursorTracked
void _glfwRestoreVideoModeWin32(_GLFWmonitor *monitor)
BOOL(WINAPI * PFN_ChangeWindowMessageFilterEx)(HWND, UINT, DWORD, CHANGEFILTERSTRUCT *)
BOOL(WINAPI * PFN_EnableNonClientDpiScaling)(HWND)
BOOL fTransitionOnMaximized
void _glfwInitTimerWin32(void)
Definition: win32_time.c:37
PFN_SetProcessDpiAwareness SetProcessDpiAwareness_
char * _glfwCreateUTF8FromWideStringWin32(const WCHAR *source)
Definition: win32_init.c:412
int GLFWbool
Definition: internal.h:61
DWORD(WINAPI * PFN_XInputGetState)(DWORD, XINPUT_STATE *)
VkWin32SurfaceCreateFlagsKHR flags
UINT(WINAPI * PFN_GetDpiForWindow)(HWND)
PFN_timeGetTime GetTime
LONG(WINAPI * PFN_RtlVerifyVersionInfo)(OSVERSIONINFOEXW *, ULONG, ULONGLONG)
void _glfwGetMonitorContentScaleWin32(HMONITOR handle, float *xscale, float *yscale)
void _glfwUpdateKeyNamesWin32(void)
Definition: win32_init.c:461
VkFlags VkWin32SurfaceCreateFlagsKHR
void _glfwPollMonitorsWin32(void)
void * VkInstance
Definition: internal.h:118
unsigned int uint32_t
Definition: stdint.h:80
PFN_GetDpiForMonitor GetDpiForMonitor_
void * VkPhysicalDevice
Definition: internal.h:119
BOOL(WINAPI * PFN_AdjustWindowRectExForDpi)(LPRECT, DWORD, BOOL, DWORD, UINT)
WCHAR * _glfwCreateWideStringFromUTF8Win32(const char *source)
Definition: win32_init.c:384
DWORD(WINAPI * PFN_XInputGetCapabilities)(DWORD, DWORD, XINPUT_CAPABILITIES *)
unsigned __int64 uint64_t
Definition: stdint.h:90
BOOL _glfwIsWindows10BuildOrGreaterWin32(WORD build)
Definition: win32_init.c:530
uint64_t VkSurfaceKHR
Definition: internal.h:120
PFN_ChangeWindowMessageFilterEx ChangeWindowMessageFilterEx_
CRITICAL_SECTION section
MONITOR_DPI_TYPE
void _glfwUnregisterWindowClassWin32(void)
PFN_DwmEnableBlurBehindWindow EnableBlurBehindWindow
uint32_t VkFlags
Definition: vulkan_core.h:66
PFN_SetProcessDpiAwarenessContext SetProcessDpiAwarenessContext_
#define GLFW_KEY_LAST
Definition: glfw3.h:483
HRESULT(WINAPI * PFN_DwmIsCompositionEnabled)(BOOL *)
Video mode type.
Definition: glfw3.h:1525
PFN_EnableNonClientDpiScaling EnableNonClientDpiScaling_
struct _GLFWlibraryWin32 _GLFWlibraryWin32
DWORD(WINAPI * PFN_timeGetTime)(void)
PFN_RtlVerifyVersionInfo RtlVerifyVersionInfo_
HDEVNOTIFY deviceNotificationHandle
GLsizei GLsizei GLchar * source
HRESULT(WINAPI * PFN_DirectInput8Create)(HINSTANCE, DWORD, REFIID, LPVOID *, LPUNKNOWN)
GLFWbool allocated
GLFWbool scaleToMonitor
GLFWbool _glfwRegisterWindowClassWin32(void)
PFN_DwmIsCompositionEnabled IsCompositionEnabled
BOOL(WINAPI * PFN_SetProcessDPIAware)(void)
void _glfwInputErrorWin32(int error, const char *description)
Definition: win32_init.c:440
PFN_XInputGetCapabilities GetCapabilities
BOOL _glfwIsWindowsVersionOrGreaterWin32(WORD major, WORD minor, WORD sp)
Definition: win32_init.c:515


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:50:23