Adding WM_POINTER family to win32_window.h + changing WINVER in win32_platform.h

This commit is contained in:
Raja 2017-10-17 20:11:31 -04:00
parent 56ecd62f58
commit 04d5e94eb0
3 changed files with 1491 additions and 1431 deletions

View File

@ -49,13 +49,13 @@
#endif #endif
// GLFW requires Windows XP or later // GLFW requires Windows XP or later
#if WINVER < 0x0501 #if WINVER < 0x0604
#undef WINVER #undef WINVER
#define WINVER 0x0501 #define WINVER 0x0604
#endif #endif
#if _WIN32_WINNT < 0x0501 #if _WIN32_WINNT < 0x0604
#undef _WIN32_WINNT #undef _WIN32_WINNT
#define _WIN32_WINNT 0x0501 #define _WIN32_WINNT 0x0604
#endif #endif
// GLFW uses DirectInput8 interfaces // GLFW uses DirectInput8 interfaces
@ -104,7 +104,7 @@
#define _WIN32_WINNT_WINBLUE 0x0602 #define _WIN32_WINNT_WINBLUE 0x0602
#endif #endif
#if WINVER < 0x0601 #if WINVER < 0x0400
typedef struct tagCHANGEFILTERSTRUCT typedef struct tagCHANGEFILTERSTRUCT
{ {
DWORD cbSize; DWORD cbSize;
@ -116,7 +116,7 @@ typedef struct tagCHANGEFILTERSTRUCT
#endif #endif
#endif /*Windows 7*/ #endif /*Windows 7*/
#if WINVER < 0x0600 #if WINVER > 0x0400 //Changed from 0x0600 to 0x0400
#define DWM_BB_ENABLE 0x00000001 #define DWM_BB_ENABLE 0x00000001
#define DWM_BB_BLURREGION 0x00000002 #define DWM_BB_BLURREGION 0x00000002
typedef struct typedef struct

View File

@ -31,8 +31,10 @@
#include <stdlib.h> #include <stdlib.h>
#include <malloc.h> #include <malloc.h>
#include <string.h> #include <string.h>
#include <WinUser.h>
#include <windowsx.h> #include <windowsx.h>
#include <shellapi.h> #include <shellapi.h>
#include <stdio.h>
#define _GLFW_KEY_INVALID -2 #define _GLFW_KEY_INVALID -2
@ -124,11 +126,11 @@ static HICON createIcon(const GLFWimage* image,
dc = GetDC(NULL); dc = GetDC(NULL);
color = CreateDIBSection(dc, color = CreateDIBSection(dc,
(BITMAPINFO*) &bi, (BITMAPINFO*)&bi,
DIB_RGB_COLORS, DIB_RGB_COLORS,
(void**) &target, (void**)&target,
NULL, NULL,
(DWORD) 0); (DWORD)0);
ReleaseDC(NULL, dc); ReleaseDC(NULL, dc);
if (!color) if (!color)
@ -203,7 +205,7 @@ static void getFullWindowSize(DWORD style, DWORD exStyle,
static void applyAspectRatio(_GLFWwindow* window, int edge, RECT* area) static void applyAspectRatio(_GLFWwindow* window, int edge, RECT* area)
{ {
int xoff, yoff; int xoff, yoff;
const float ratio = (float) window->numer / (float) window->denom; const float ratio = (float)window->numer / (float)window->denom;
getFullWindowSize(getWindowStyle(window), getWindowExStyle(window), getFullWindowSize(getWindowStyle(window), getWindowExStyle(window),
0, 0, &xoff, &yoff); 0, 0, &xoff, &yoff);
@ -212,17 +214,17 @@ static void applyAspectRatio(_GLFWwindow* window, int edge, RECT* area)
edge == WMSZ_RIGHT || edge == WMSZ_BOTTOMRIGHT) edge == WMSZ_RIGHT || edge == WMSZ_BOTTOMRIGHT)
{ {
area->bottom = area->top + yoff + area->bottom = area->top + yoff +
(int) ((area->right - area->left - xoff) / ratio); (int)((area->right - area->left - xoff) / ratio);
} }
else if (edge == WMSZ_TOPLEFT || edge == WMSZ_TOPRIGHT) else if (edge == WMSZ_TOPLEFT || edge == WMSZ_TOPRIGHT)
{ {
area->top = area->bottom - yoff - area->top = area->bottom - yoff -
(int) ((area->right - area->left - xoff) / ratio); (int)((area->right - area->left - xoff) / ratio);
} }
else if (edge == WMSZ_TOP || edge == WMSZ_BOTTOM) else if (edge == WMSZ_TOP || edge == WMSZ_BOTTOM)
{ {
area->right = area->left + xoff + area->right = area->left + xoff +
(int) ((area->bottom - area->top - yoff) * ratio); (int)((area->bottom - area->top - yoff) * ratio);
} }
} }
@ -249,8 +251,8 @@ static GLFWbool cursorInClientArea(_GLFWwindow* window)
return GLFW_FALSE; return GLFW_FALSE;
GetClientRect(window->win32.handle, &area); GetClientRect(window->win32.handle, &area);
ClientToScreen(window->win32.handle, (POINT*) &area.left); ClientToScreen(window->win32.handle, (POINT*)&area.left);
ClientToScreen(window->win32.handle, (POINT*) &area.right); ClientToScreen(window->win32.handle, (POINT*)&area.right);
return PtInRect(&area, pos); return PtInRect(&area, pos);
} }
@ -278,8 +280,8 @@ static void updateClipRect(_GLFWwindow* window)
{ {
RECT clipRect; RECT clipRect;
GetClientRect(window->win32.handle, &clipRect); GetClientRect(window->win32.handle, &clipRect);
ClientToScreen(window->win32.handle, (POINT*) &clipRect.left); ClientToScreen(window->win32.handle, (POINT*)&clipRect.left);
ClientToScreen(window->win32.handle, (POINT*) &clipRect.right); ClientToScreen(window->win32.handle, (POINT*)&clipRect.right);
ClipCursor(&clipRect); ClipCursor(&clipRect);
} }
else else
@ -297,8 +299,8 @@ static void updateWindowStyles(const _GLFWwindow* window)
GetClientRect(window->win32.handle, &rect); GetClientRect(window->win32.handle, &rect);
AdjustWindowRectEx(&rect, style, FALSE, getWindowExStyle(window)); AdjustWindowRectEx(&rect, style, FALSE, getWindowExStyle(window));
ClientToScreen(window->win32.handle, (POINT*) &rect.left); ClientToScreen(window->win32.handle, (POINT*)&rect.left);
ClientToScreen(window->win32.handle, (POINT*) &rect.right); ClientToScreen(window->win32.handle, (POINT*)&rect.right);
SetWindowLongW(window->win32.handle, GWL_STYLE, style); SetWindowLongW(window->win32.handle, GWL_STYLE, style);
SetWindowPos(window->win32.handle, HWND_TOP, SetWindowPos(window->win32.handle, HWND_TOP,
rect.left, rect.top, rect.left, rect.top,
@ -316,7 +318,7 @@ static void updateFramebufferTransparency(const _GLFWwindow* window)
if (_glfwIsCompositionEnabledWin32()) if (_glfwIsCompositionEnabledWin32())
{ {
HRGN region = CreateRectRgn(0, 0, -1, -1); HRGN region = CreateRectRgn(0, 0, -1, -1);
DWM_BLURBEHIND bb = {0}; DWM_BLURBEHIND bb = { 0 };
bb.dwFlags = DWM_BB_ENABLE | DWM_BB_BLURREGION; bb.dwFlags = DWM_BB_ENABLE | DWM_BB_BLURREGION;
bb.hRgnBlur = region; bb.hRgnBlur = region;
bb.fEnable = TRUE; bb.fEnable = TRUE;
@ -524,13 +526,13 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
{ {
if (wParam == DBT_DEVICEARRIVAL) if (wParam == DBT_DEVICEARRIVAL)
{ {
DEV_BROADCAST_HDR* dbh = (DEV_BROADCAST_HDR*) lParam; DEV_BROADCAST_HDR* dbh = (DEV_BROADCAST_HDR*)lParam;
if (dbh && dbh->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) if (dbh && dbh->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
_glfwDetectJoystickConnectionWin32(); _glfwDetectJoystickConnectionWin32();
} }
else if (wParam == DBT_DEVICEREMOVECOMPLETE) else if (wParam == DBT_DEVICEREMOVECOMPLETE)
{ {
DEV_BROADCAST_HDR* dbh = (DEV_BROADCAST_HDR*) lParam; DEV_BROADCAST_HDR* dbh = (DEV_BROADCAST_HDR*)lParam;
if (dbh && dbh->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) if (dbh && dbh->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
_glfwDetectJoystickDisconnectionWin32(); _glfwDetectJoystickDisconnectionWin32();
} }
@ -561,6 +563,63 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
break; break;
} }
case WM_POINTERDOWN:
{
POINTER_TOUCH_INFO touchInfo;
POINTER_PEN_INFO penInfo;
POINTER_INFO pointerInfo;
UINT32 pointerId = GET_POINTERID_WPARAM(wParam);
POINTER_INPUT_TYPE pointerType = PT_POINTER;
// default to unhandled to enable call to DefWindowProc
BOOL fHandled = FALSE;
// Retrieve common pointer information
if (!GetPointerType(pointerId, &pointerType))
{
// failure, call
GetLastError();
// set PT_POINTER to fall to default case below
pointerType = PT_POINTER;
}
switch (pointerType)
{
case (PT_PEN):
//Retrieve pen information
if (!GetPointerPenInfo(pointerId, &penInfo))
{
// failure, call
GetLastError();
}
else
{
// success, process penInfo
int xPos = GET_X_LPARAM(lParam);
int yPos = GET_Y_LPARAM(lParam);
if (IS_POINTER_INCONTACT_WPARAM(wParam))
{
printf("The pen pressure is = %d", penInfo.pressure);
}
// mark as handled to skip call to DefWindowProc
fHandled = TRUE;
}
break;
}
default:
if (!GetPointerInfo(pointerId, &pointerInfo))
{
// failure.
GetLastError();
}
else
{
// success, proceed with pointerInfo.
// fHandled = HandleGenericPointerMessage(&pointerInfo);
}
break;
}
case WM_CAPTURECHANGED: case WM_CAPTURECHANGED:
{ {
// HACK: Disable the cursor once the caption button action has been // HACK: Disable the cursor once the caption button action has been
@ -653,7 +712,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
return TRUE; return TRUE;
} }
_glfwInputChar(window, (unsigned int) wParam, getKeyMods(), plain); _glfwInputChar(window, (unsigned int)wParam, getKeyMods(), plain);
return 0; return 0;
} }
@ -779,7 +838,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
case WM_INPUT: case WM_INPUT:
{ {
UINT size; UINT size;
HRAWINPUT ri = (HRAWINPUT) lParam; HRAWINPUT ri = (HRAWINPUT)lParam;
RAWINPUT* data; RAWINPUT* data;
int dx, dy; int dx, dy;
@ -788,7 +847,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
break; break;
GetRawInputData(ri, RID_INPUT, NULL, &size, sizeof(RAWINPUTHEADER)); GetRawInputData(ri, RID_INPUT, NULL, &size, sizeof(RAWINPUTHEADER));
if (size > (UINT) _glfw.win32.rawInputSize) if (size > (UINT)_glfw.win32.rawInputSize)
{ {
free(_glfw.win32.rawInput); free(_glfw.win32.rawInput);
_glfw.win32.rawInput = calloc(size, 1); _glfw.win32.rawInput = calloc(size, 1);
@ -798,7 +857,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
size = _glfw.win32.rawInputSize; size = _glfw.win32.rawInputSize;
if (GetRawInputData(ri, RID_INPUT, if (GetRawInputData(ri, RID_INPUT,
_glfw.win32.rawInput, &size, _glfw.win32.rawInput, &size,
sizeof(RAWINPUTHEADER)) == (UINT) -1) sizeof(RAWINPUTHEADER)) == (UINT)-1)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
"Win32: Failed to retrieve raw input data"); "Win32: Failed to retrieve raw input data");
@ -835,7 +894,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
case WM_MOUSEWHEEL: case WM_MOUSEWHEEL:
{ {
_glfwInputScroll(window, 0.0, (SHORT) HIWORD(wParam) / (double) WHEEL_DELTA); _glfwInputScroll(window, 0.0, (SHORT)HIWORD(wParam) / (double)WHEEL_DELTA);
return 0; return 0;
} }
@ -843,7 +902,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
{ {
// This message is only sent on Windows Vista and later // This message is only sent on Windows Vista and later
// NOTE: The X-axis is inverted for consistency with macOS and X11 // NOTE: The X-axis is inverted for consistency with macOS and X11
_glfwInputScroll(window, -((SHORT) HIWORD(wParam) / (double) WHEEL_DELTA), 0.0); _glfwInputScroll(window, -((SHORT)HIWORD(wParam) / (double)WHEEL_DELTA), 0.0);
return 0; return 0;
} }
@ -922,14 +981,14 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
break; break;
} }
applyAspectRatio(window, (int) wParam, (RECT*) lParam); applyAspectRatio(window, (int)wParam, (RECT*)lParam);
return TRUE; return TRUE;
} }
case WM_GETMINMAXINFO: case WM_GETMINMAXINFO:
{ {
int xoff, yoff; int xoff, yoff;
MINMAXINFO* mmi = (MINMAXINFO*) lParam; MINMAXINFO* mmi = (MINMAXINFO*)lParam;
if (window->monitor) if (window->monitor)
break; break;
@ -985,7 +1044,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
case WM_DPICHANGED: case WM_DPICHANGED:
{ {
RECT* rect = (RECT*) lParam; RECT* rect = (RECT*)lParam;
SetWindowPos(window->win32.handle, SetWindowPos(window->win32.handle,
HWND_TOP, HWND_TOP,
rect->left, rect->left,
@ -998,7 +1057,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
case WM_DROPFILES: case WM_DROPFILES:
{ {
HDROP drop = (HDROP) wParam; HDROP drop = (HDROP)wParam;
POINT pt; POINT pt;
int i; int i;
@ -1020,7 +1079,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
free(buffer); free(buffer);
} }
_glfwInputDrop(window, count, (const char**) paths); _glfwInputDrop(window, count, (const char**)paths);
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
free(paths[i]); free(paths[i]);
@ -1029,9 +1088,9 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
DragFinish(drop); DragFinish(drop);
return 0; return 0;
} }
} }
return DefWindowProcW(hWnd, uMsg, wParam, lParam); return DefWindowProcW(hWnd, uMsg, wParam, lParam);
} }
// Creates the GLFW window // Creates the GLFW window
@ -1131,7 +1190,7 @@ GLFWbool _glfwRegisterWindowClassWin32(void)
ZeroMemory(&wc, sizeof(wc)); ZeroMemory(&wc, sizeof(wc));
wc.cbSize = sizeof(wc); wc.cbSize = sizeof(wc);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = (WNDPROC) windowProc; wc.lpfnWndProc = (WNDPROC)windowProc;
wc.hInstance = GetModuleHandleW(NULL); wc.hInstance = GetModuleHandleW(NULL);
wc.hCursor = LoadCursorW(NULL, IDC_ARROW); wc.hCursor = LoadCursorW(NULL, IDC_ARROW);
wc.lpszClassName = _GLFW_WNDCLASSNAME; wc.lpszClassName = _GLFW_WNDCLASSNAME;
@ -1285,12 +1344,12 @@ void _glfwPlatformSetWindowIcon(_GLFWwindow* window,
} }
else else
{ {
bigIcon = (HICON) GetClassLongPtrW(window->win32.handle, GCLP_HICON); bigIcon = (HICON)GetClassLongPtrW(window->win32.handle, GCLP_HICON);
smallIcon = (HICON) GetClassLongPtrW(window->win32.handle, GCLP_HICONSM); smallIcon = (HICON)GetClassLongPtrW(window->win32.handle, GCLP_HICONSM);
} }
SendMessage(window->win32.handle, WM_SETICON, ICON_BIG, (LPARAM) bigIcon); SendMessage(window->win32.handle, WM_SETICON, ICON_BIG, (LPARAM)bigIcon);
SendMessage(window->win32.handle, WM_SETICON, ICON_SMALL, (LPARAM) smallIcon); SendMessage(window->win32.handle, WM_SETICON, ICON_SMALL, (LPARAM)smallIcon);
if (window->win32.bigIcon) if (window->win32.bigIcon)
DestroyIcon(window->win32.bigIcon); DestroyIcon(window->win32.bigIcon);
@ -1661,7 +1720,7 @@ void _glfwPlatformWaitEvents(void)
void _glfwPlatformWaitEventsTimeout(double timeout) void _glfwPlatformWaitEventsTimeout(double timeout)
{ {
MsgWaitForMultipleObjects(0, NULL, FALSE, (DWORD) (timeout * 1e3), QS_ALLEVENTS); MsgWaitForMultipleObjects(0, NULL, FALSE, (DWORD)(timeout * 1e3), QS_ALLEVENTS);
_glfwPlatformPollEvents(); _glfwPlatformPollEvents();
} }
@ -1688,7 +1747,7 @@ void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos)
void _glfwPlatformSetCursorPos(_GLFWwindow* window, double xpos, double ypos) void _glfwPlatformSetCursorPos(_GLFWwindow* window, double xpos, double ypos)
{ {
POINT pos = { (int) xpos, (int) ypos }; POINT pos = { (int)xpos, (int)ypos };
// Store the new position so it can be recognized later // Store the new position so it can be recognized later
window->win32.lastCursorPosX = pos.x; window->win32.lastCursorPosX = pos.x;
@ -1752,7 +1811,7 @@ int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
const GLFWimage* image, const GLFWimage* image,
int xhot, int yhot) int xhot, int yhot)
{ {
cursor->win32.handle = (HCURSOR) createIcon(image, xhot, yhot, GLFW_FALSE); cursor->win32.handle = (HCURSOR)createIcon(image, xhot, yhot, GLFW_FALSE);
if (!cursor->win32.handle) if (!cursor->win32.handle)
return GLFW_FALSE; return GLFW_FALSE;
@ -1776,7 +1835,7 @@ int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
void _glfwPlatformDestroyCursor(_GLFWcursor* cursor) void _glfwPlatformDestroyCursor(_GLFWcursor* cursor)
{ {
if (cursor->win32.handle) if (cursor->win32.handle)
DestroyIcon((HICON) cursor->win32.handle); DestroyIcon((HICON)cursor->win32.handle);
} }
void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor) void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor)
@ -1935,7 +1994,7 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
GLFWAPI HWND glfwGetWin32Window(GLFWwindow* handle) GLFWAPI HWND glfwGetWin32Window(GLFWwindow* handle)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*)handle;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL); _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
return window->win32.handle; return window->win32.handle;
} }

View File

@ -27,7 +27,8 @@
//======================================================================== //========================================================================
#include "internal.h" #include "internal.h"
#include <WinUser.h>
#include <windowsx.h>
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>