41static DWORD getWindowStyle(
const _GLFWwindow* window)
43 DWORD style = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
49 style |= WS_SYSMENU | WS_MINIMIZEBOX;
56 style |= WS_MAXIMIZEBOX | WS_THICKFRAME;
67static DWORD getWindowExStyle(
const _GLFWwindow* window)
69 DWORD style = WS_EX_APPWINDOW;
72 style |= WS_EX_TOPMOST;
80 int width,
int height)
82 int i, leastDiff = INT_MAX;
85 for (i = 0; i < count; i++)
87 const int currDiff = abs(images[i].width * images[i].height -
89 if (currDiff < leastDiff)
101static HICON createIcon(
const GLFWimage* image,
110 unsigned char* target =
NULL;
111 unsigned char* source = image->
pixels;
113 ZeroMemory(&bi,
sizeof(bi));
114 bi.bV5Size =
sizeof(bi);
115 bi.bV5Width = image->
width;
116 bi.bV5Height = -image->
height;
119 bi.bV5Compression = BI_BITFIELDS;
120 bi.bV5RedMask = 0x00ff0000;
121 bi.bV5GreenMask = 0x0000ff00;
122 bi.bV5BlueMask = 0x000000ff;
123 bi.bV5AlphaMask = 0xff000000;
126 color = CreateDIBSection(dc,
137 "Win32: Failed to create RGBA bitmap");
145 "Win32: Failed to create mask bitmap");
152 target[0] = source[2];
153 target[1] = source[1];
154 target[2] = source[0];
155 target[3] = source[3];
160 ZeroMemory(&ii,
sizeof(ii));
167 handle = CreateIconIndirect(&ii);
177 "Win32: Failed to create icon");
182 "Win32: Failed to create cursor");
191static void getFullWindowSize(DWORD style, DWORD exStyle,
192 int contentWidth,
int contentHeight,
193 int* fullWidth,
int* fullHeight,
196 RECT rect = { 0, 0, contentWidth, contentHeight };
201 AdjustWindowRectEx(&rect, style, FALSE, exStyle);
203 *fullWidth = rect.right - rect.left;
204 *fullHeight = rect.bottom - rect.top;
209static void applyAspectRatio(
_GLFWwindow* window,
int edge, RECT* area)
213 const float ratio = (float) window->
numer / (
float) window->
denom;
218 getFullWindowSize(getWindowStyle(window), getWindowExStyle(window),
219 0, 0, &xoff, &yoff, dpi);
221 if (edge == WMSZ_LEFT || edge == WMSZ_BOTTOMLEFT ||
222 edge == WMSZ_RIGHT || edge == WMSZ_BOTTOMRIGHT)
224 area->bottom = area->top + yoff +
225 (int) ((area->right - area->left - xoff) / ratio);
227 else if (edge == WMSZ_TOPLEFT || edge == WMSZ_TOPRIGHT)
229 area->top = area->bottom - yoff -
230 (int) ((area->right - area->left - xoff) / ratio);
232 else if (edge == WMSZ_TOP || edge == WMSZ_BOTTOM)
234 area->right = area->left + xoff +
235 (int) ((area->bottom - area->top - yoff) * ratio);
246 SetCursor(window->
cursor->win32.handle);
248 SetCursor(LoadCursorW(
NULL, IDC_ARROW));
261 GetClientRect(window->win32.handle, &clipRect);
262 ClientToScreen(window->win32.handle, (POINT*) &clipRect.left);
263 ClientToScreen(window->win32.handle, (POINT*) &clipRect.right);
264 ClipCursor(&clipRect);
272static void enableRawMouseMotion(
_GLFWwindow* window)
274 const RAWINPUTDEVICE rid = { 0x01, 0x02, 0, window->win32.handle };
276 if (!RegisterRawInputDevices(&rid, 1,
sizeof(rid)))
279 "Win32: Failed to register raw input device");
285static void disableRawMouseMotion(
_GLFWwindow* window)
287 const RAWINPUTDEVICE rid = { 0x01, 0x02, RIDEV_REMOVE,
NULL };
289 if (!RegisterRawInputDevices(&rid, 1,
sizeof(rid)))
292 "Win32: Failed to remove raw input device");
300 _glfw.win32.disabledCursorWindow = window;
302 &
_glfw.win32.restoreCursorPosX,
303 &
_glfw.win32.restoreCursorPosY);
304 updateCursorImage(window);
306 updateClipRect(window);
309 enableRawMouseMotion(window);
317 disableRawMouseMotion(window);
320 updateClipRect(
NULL);
322 _glfw.win32.restoreCursorPosX,
323 _glfw.win32.restoreCursorPosY);
324 updateCursorImage(window);
334 if (!GetCursorPos(&pos))
337 if (WindowFromPoint(pos) != window->win32.handle)
340 GetClientRect(window->win32.handle, &area);
341 ClientToScreen(window->win32.handle, (POINT*) &area.left);
342 ClientToScreen(window->win32.handle, (POINT*) &area.right);
344 return PtInRect(&area, pos);
349static void updateWindowStyles(
const _GLFWwindow* window)
352 DWORD style = GetWindowLongW(window->win32.handle, GWL_STYLE);
353 style &= ~(WS_OVERLAPPEDWINDOW | WS_POPUP);
354 style |= getWindowStyle(window);
356 GetClientRect(window->win32.handle, &rect);
361 getWindowExStyle(window),
365 AdjustWindowRectEx(&rect, style, FALSE, getWindowExStyle(window));
367 ClientToScreen(window->win32.handle, (POINT*) &rect.left);
368 ClientToScreen(window->win32.handle, (POINT*) &rect.right);
369 SetWindowLongW(window->win32.handle, GWL_STYLE, style);
370 SetWindowPos(window->win32.handle, HWND_TOP,
372 rect.right - rect.left, rect.bottom - rect.top,
373 SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOZORDER);
378static void updateFramebufferTransparency(
const _GLFWwindow* window)
380 BOOL composition, opaque;
392 HRGN region = CreateRectRgn(0, 0, -1, -1);
399 DeleteObject(region);
415static int getKeyMods(
void)
419 if (GetKeyState(VK_SHIFT) & 0x8000)
421 if (GetKeyState(VK_CONTROL) & 0x8000)
423 if (GetKeyState(VK_MENU) & 0x8000)
425 if ((GetKeyState(VK_LWIN) | GetKeyState(VK_RWIN)) & 0x8000)
427 if (GetKeyState(VK_CAPITAL) & 1)
429 if (GetKeyState(VK_NUMLOCK) & 1)
437 MONITORINFO mi = {
sizeof(mi) };
438 GetMonitorInfo(window->
monitor->win32.handle, &mi);
439 SetWindowPos(window->win32.handle, HWND_TOPMOST,
442 mi.rcMonitor.right - mi.rcMonitor.left,
443 mi.rcMonitor.bottom - mi.rcMonitor.top,
444 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOCOPYBITS);
451 if (!
_glfw.win32.acquiredMonitorCount)
453 SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED);
457 SystemParametersInfo(SPI_GETMOUSETRAILS, 0, &
_glfw.win32.mouseTrailSize, 0);
458 SystemParametersInfo(SPI_SETMOUSETRAILS, 0, 0, 0);
462 _glfw.win32.acquiredMonitorCount++;
475 _glfw.win32.acquiredMonitorCount--;
476 if (!
_glfw.win32.acquiredMonitorCount)
478 SetThreadExecutionState(ES_CONTINUOUS);
481 SystemParametersInfo(SPI_SETMOUSETRAILS,
_glfw.win32.mouseTrailSize, 0, 0);
490static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
491 WPARAM wParam, LPARAM lParam)
505 const CREATESTRUCTW* cs = (
const CREATESTRUCTW*) lParam;
519 case WM_DISPLAYCHANGE:
523 case WM_DEVICECHANGE:
528 if (wParam == DBT_DEVICEARRIVAL)
530 DEV_BROADCAST_HDR* dbh = (DEV_BROADCAST_HDR*) lParam;
531 if (dbh && dbh->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
534 else if (wParam == DBT_DEVICEREMOVECOMPLETE)
536 DEV_BROADCAST_HDR* dbh = (DEV_BROADCAST_HDR*) lParam;
537 if (dbh && dbh->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
545 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
550 case WM_MOUSEACTIVATE:
554 if (HIWORD(lParam) == WM_LBUTTONDOWN)
556 if (LOWORD(lParam) != HTCLIENT)
563 case WM_CAPTURECHANGED:
567 if (lParam == 0 && window->win32.frameAction)
570 disableCursor(window);
584 if (window->win32.frameAction)
588 disableCursor(window);
596 enableCursor(window);
607 switch (wParam & 0xfff0)
610 case SC_MONITORPOWER:
625 if (!window->win32.keymenu)
640 case WM_INPUTLANGCHANGE:
649 if (wParam >= 0xd800 && wParam <= 0xdbff)
650 window->win32.highSurrogate = (WCHAR) wParam;
653 unsigned int codepoint = 0;
655 if (wParam >= 0xdc00 && wParam <= 0xdfff)
657 if (window->win32.highSurrogate)
659 codepoint += (window->win32.highSurrogate - 0xd800) << 10;
660 codepoint += (WCHAR) wParam - 0xdc00;
661 codepoint += 0x10000;
665 codepoint = (WCHAR) wParam;
667 window->win32.highSurrogate = 0;
668 _glfwInputChar(window, codepoint, getKeyMods(), uMsg != WM_SYSCHAR);
671 if (uMsg == WM_SYSCHAR && window->win32.keymenu)
698 const int mods = getKeyMods();
700 scancode = (HIWORD(lParam) & (KF_EXTENDED | 0xff));
705 scancode = MapVirtualKeyW((UINT) wParam, MAPVK_VK_TO_VSC);
708 key =
_glfw.win32.keycodes[scancode];
711 if (wParam == VK_CONTROL)
713 if (HIWORD(lParam) & KF_EXTENDED)
725 const DWORD time = GetMessageTime();
727 if (PeekMessageW(&next,
NULL, 0, 0, PM_NOREMOVE))
729 if (next.message == WM_KEYDOWN ||
730 next.message == WM_SYSKEYDOWN ||
731 next.message == WM_KEYUP ||
732 next.message == WM_SYSKEYUP)
734 if (next.wParam == VK_MENU &&
735 (HIWORD(next.lParam) & KF_EXTENDED) &&
748 else if (wParam == VK_PROCESSKEY)
763 else if (wParam == VK_SNAPSHOT)
784 int i, button, action;
786 if (uMsg == WM_LBUTTONDOWN || uMsg == WM_LBUTTONUP)
788 else if (uMsg == WM_RBUTTONDOWN || uMsg == WM_RBUTTONUP)
790 else if (uMsg == WM_MBUTTONDOWN || uMsg == WM_MBUTTONUP)
797 if (uMsg == WM_LBUTTONDOWN || uMsg == WM_RBUTTONDOWN ||
798 uMsg == WM_MBUTTONDOWN || uMsg == WM_XBUTTONDOWN)
825 if (uMsg == WM_XBUTTONDOWN || uMsg == WM_XBUTTONUP)
833 const int x = GET_X_LPARAM(lParam);
834 const int y = GET_Y_LPARAM(lParam);
836 if (!window->win32.cursorTracked)
839 ZeroMemory(&tme,
sizeof(tme));
840 tme.cbSize =
sizeof(tme);
841 tme.dwFlags = TME_LEAVE;
842 tme.hwndTrack = window->win32.handle;
843 TrackMouseEvent(&tme);
851 const int dx = x - window->win32.lastCursorPosX;
852 const int dy = y - window->win32.lastCursorPosY;
854 if (
_glfw.win32.disabledCursorWindow != window)
866 window->win32.lastCursorPosX = x;
867 window->win32.lastCursorPosY = y;
875 HRAWINPUT ri = (HRAWINPUT) lParam;
876 RAWINPUT* data =
NULL;
879 if (
_glfw.win32.disabledCursorWindow != window)
884 GetRawInputData(ri, RID_INPUT,
NULL, &size,
sizeof(RAWINPUTHEADER));
885 if (size > (UINT)
_glfw.win32.rawInputSize)
887 free(
_glfw.win32.rawInput);
888 _glfw.win32.rawInput = calloc(size, 1);
889 _glfw.win32.rawInputSize = size;
892 size =
_glfw.win32.rawInputSize;
893 if (GetRawInputData(ri, RID_INPUT,
894 _glfw.win32.rawInput, &size,
895 sizeof(RAWINPUTHEADER)) == (UINT) -1)
898 "Win32: Failed to retrieve raw input data");
902 data =
_glfw.win32.rawInput;
903 if (data->data.mouse.usFlags & MOUSE_MOVE_ABSOLUTE)
905 dx = data->data.mouse.lLastX - window->win32.lastCursorPosX;
906 dy = data->data.mouse.lLastY - window->win32.lastCursorPosY;
910 dx = data->data.mouse.lLastX;
911 dy = data->data.mouse.lLastY;
918 window->win32.lastCursorPosX += dx;
919 window->win32.lastCursorPosY += dy;
932 _glfwInputScroll(window, 0.0, (SHORT) HIWORD(wParam) / (
double) WHEEL_DELTA);
940 _glfwInputScroll(window, -((SHORT) HIWORD(wParam) / (
double) WHEEL_DELTA), 0.0);
944 case WM_ENTERSIZEMOVE:
945 case WM_ENTERMENULOOP:
947 if (window->win32.frameAction)
953 enableCursor(window);
958 case WM_EXITSIZEMOVE:
959 case WM_EXITMENULOOP:
961 if (window->win32.frameAction)
967 disableCursor(window);
974 const int width = LOWORD(lParam);
975 const int height = HIWORD(lParam);
976 const GLFWbool iconified = wParam == SIZE_MINIMIZED;
977 const GLFWbool maximized = wParam == SIZE_MAXIMIZED ||
978 (window->win32.maximized &&
979 wParam != SIZE_RESTORED);
981 if (
_glfw.win32.disabledCursorWindow == window)
982 updateClipRect(window);
984 if (window->win32.iconified != iconified)
987 if (window->win32.maximized != maximized)
990 if (width != window->win32.width || height != window->win32.height)
992 window->win32.width = width;
993 window->win32.height = height;
999 if (window->
monitor && window->win32.iconified != iconified)
1002 releaseMonitor(window);
1005 acquireMonitor(window);
1006 fitToMonitor(window);
1010 window->win32.iconified = iconified;
1011 window->win32.maximized = maximized;
1017 if (
_glfw.win32.disabledCursorWindow == window)
1018 updateClipRect(window);
1023 GET_X_LPARAM(lParam),
1024 GET_Y_LPARAM(lParam));
1036 applyAspectRatio(window, (
int) wParam, (RECT*) lParam);
1040 case WM_GETMINMAXINFO:
1044 MINMAXINFO* mmi = (MINMAXINFO*) lParam;
1052 getFullWindowSize(getWindowStyle(window), getWindowExStyle(window),
1053 0, 0, &xoff, &yoff, dpi);
1058 mmi->ptMinTrackSize.x = window->
minwidth + xoff;
1059 mmi->ptMinTrackSize.y = window->
minheight + yoff;
1065 mmi->ptMaxTrackSize.x = window->
maxwidth + xoff;
1066 mmi->ptMaxTrackSize.y = window->
maxheight + yoff;
1072 const HMONITOR mh = MonitorFromWindow(window->win32.handle,
1073 MONITOR_DEFAULTTONEAREST);
1075 ZeroMemory(&mi,
sizeof(mi));
1076 mi.cbSize =
sizeof(mi);
1077 GetMonitorInfo(mh, &mi);
1079 mmi->ptMaxPosition.x = mi.rcWork.left - mi.rcMonitor.left;
1080 mmi->ptMaxPosition.y = mi.rcWork.top - mi.rcMonitor.top;
1081 mmi->ptMaxSize.x = mi.rcWork.right - mi.rcWork.left;
1082 mmi->ptMaxSize.y = mi.rcWork.bottom - mi.rcWork.top;
1113 if (window->win32.transparent)
1114 updateFramebufferTransparency(window);
1120 if (window->win32.scaleToMonitor)
1126 RECT source = {0}, target = {0};
1127 SIZE* size = (SIZE*) lParam;
1130 FALSE, getWindowExStyle(window),
1133 FALSE, getWindowExStyle(window),
1136 size->cx += (target.right - target.left) -
1137 (source.right - source.left);
1138 size->cy += (target.bottom - target.top) -
1139 (source.bottom - source.top);
1154 (window->win32.scaleToMonitor ||
1157 RECT* suggested = (RECT*) lParam;
1158 SetWindowPos(window->win32.handle, HWND_TOP,
1161 suggested->right - suggested->left,
1162 suggested->bottom - suggested->top,
1163 SWP_NOACTIVATE | SWP_NOZORDER);
1172 if (LOWORD(lParam) == HTCLIENT)
1174 updateCursorImage(window);
1183 HDROP drop = (HDROP) wParam;
1187 const int count = DragQueryFileW(drop, 0xffffffff,
NULL, 0);
1188 char** paths = calloc(count,
sizeof(
char*));
1191 DragQueryPoint(drop, &pt);
1194 for (i = 0; i < count; i++)
1196 const UINT length = DragQueryFileW(drop, i,
NULL, 0);
1197 WCHAR* buffer = calloc((
size_t) length + 1,
sizeof(WCHAR));
1199 DragQueryFileW(drop, i, buffer, length + 1);
1207 for (i = 0; i < count; i++)
1216 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
1225 int xpos, ypos, fullWidth, fullHeight;
1227 DWORD style = getWindowStyle(window);
1228 DWORD exStyle = getWindowExStyle(window);
1239 fullWidth = mode.
width;
1240 fullHeight = mode.
height;
1244 xpos = CW_USEDEFAULT;
1245 ypos = CW_USEDEFAULT;
1247 window->win32.maximized = wndconfig->
maximized;
1249 style |= WS_MAXIMIZE;
1251 getFullWindowSize(style, exStyle,
1253 &fullWidth, &fullHeight,
1261 window->win32.handle = CreateWindowExW(exStyle,
1266 fullWidth, fullHeight,
1269 GetModuleHandleW(
NULL),
1270 (LPVOID) wndconfig);
1274 if (!window->win32.handle)
1277 "Win32: Failed to create window");
1281 SetPropW(window->win32.handle, L
"GLFW", window);
1301 RECT rect = { 0, 0, wndconfig->
width, wndconfig->
height };
1302 WINDOWPLACEMENT wp = {
sizeof(wp) };
1306 float xscale, yscale;
1308 rect.right = (int) (rect.right * xscale);
1309 rect.bottom = (int) (rect.bottom * yscale);
1312 ClientToScreen(window->win32.handle, (POINT*) &rect.left);
1313 ClientToScreen(window->win32.handle, (POINT*) &rect.right);
1321 AdjustWindowRectEx(&rect, style, FALSE, exStyle);
1324 GetWindowPlacement(window->win32.handle, &wp);
1325 wp.rcNormalPosition = rect;
1326 wp.showCmd = SW_HIDE;
1327 SetWindowPlacement(window->win32.handle, &wp);
1330 DragAcceptFiles(window->win32.handle, TRUE);
1334 updateFramebufferTransparency(window);
1354 ZeroMemory(&wc,
sizeof(wc));
1355 wc.cbSize =
sizeof(wc);
1356 wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
1357 wc.lpfnWndProc = (WNDPROC) windowProc;
1358 wc.hInstance = GetModuleHandleW(
NULL);
1359 wc.hCursor = LoadCursorW(
NULL, IDC_ARROW);
1363 wc.hIcon = LoadImageW(GetModuleHandleW(
NULL),
1364 L
"GLFW_ICON", IMAGE_ICON,
1365 0, 0, LR_DEFAULTSIZE | LR_SHARED);
1369 wc.hIcon = LoadImageW(
NULL,
1370 IDI_APPLICATION, IMAGE_ICON,
1371 0, 0, LR_DEFAULTSIZE | LR_SHARED);
1374 if (!RegisterClassExW(&wc))
1377 "Win32: Failed to register window class");
1401 if (!createNativeWindow(window, wndconfig, fbconfig))
1433 acquireMonitor(window);
1434 fitToMonitor(window);
1443 releaseMonitor(window);
1448 if (
_glfw.win32.disabledCursorWindow == window)
1449 _glfw.win32.disabledCursorWindow =
NULL;
1451 if (window->win32.handle)
1453 RemovePropW(window->win32.handle, L
"GLFW");
1454 DestroyWindow(window->win32.handle);
1455 window->win32.handle =
NULL;
1458 if (window->win32.bigIcon)
1459 DestroyIcon(window->win32.bigIcon);
1461 if (window->win32.smallIcon)
1462 DestroyIcon(window->win32.smallIcon);
1471 SetWindowTextW(window->win32.handle, wideTitle);
1478 HICON bigIcon =
NULL, smallIcon =
NULL;
1482 const GLFWimage* bigImage = chooseImage(count, images,
1483 GetSystemMetrics(SM_CXICON),
1484 GetSystemMetrics(SM_CYICON));
1485 const GLFWimage* smallImage = chooseImage(count, images,
1486 GetSystemMetrics(SM_CXSMICON),
1487 GetSystemMetrics(SM_CYSMICON));
1489 bigIcon = createIcon(bigImage, 0, 0,
GLFW_TRUE);
1490 smallIcon = createIcon(smallImage, 0, 0,
GLFW_TRUE);
1494 bigIcon = (HICON) GetClassLongPtrW(window->win32.handle, GCLP_HICON);
1495 smallIcon = (HICON) GetClassLongPtrW(window->win32.handle, GCLP_HICONSM);
1498 SendMessage(window->win32.handle, WM_SETICON, ICON_BIG, (LPARAM) bigIcon);
1499 SendMessage(window->win32.handle, WM_SETICON, ICON_SMALL, (LPARAM) smallIcon);
1501 if (window->win32.bigIcon)
1502 DestroyIcon(window->win32.bigIcon);
1504 if (window->win32.smallIcon)
1505 DestroyIcon(window->win32.smallIcon);
1509 window->win32.bigIcon = bigIcon;
1510 window->win32.smallIcon = smallIcon;
1516 POINT pos = { 0, 0 };
1517 ClientToScreen(window->win32.handle, &pos);
1527 RECT rect = { xpos, ypos, xpos, ypos };
1532 FALSE, getWindowExStyle(window),
1537 AdjustWindowRectEx(&rect, getWindowStyle(window),
1538 FALSE, getWindowExStyle(window));
1541 SetWindowPos(window->win32.handle,
NULL, rect.left, rect.top, 0, 0,
1542 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE);
1548 GetClientRect(window->win32.handle, &area);
1551 *width = area.right;
1553 *height = area.bottom;
1562 acquireMonitor(window);
1563 fitToMonitor(window);
1568 RECT rect = { 0, 0, width, height };
1573 FALSE, getWindowExStyle(window),
1578 AdjustWindowRectEx(&rect, getWindowStyle(window),
1579 FALSE, getWindowExStyle(window));
1582 SetWindowPos(window->win32.handle, HWND_TOP,
1583 0, 0, rect.right - rect.left, rect.bottom - rect.top,
1584 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOZORDER);
1589 int minwidth,
int minheight,
1590 int maxwidth,
int maxheight)
1600 GetWindowRect(window->win32.handle, &area);
1601 MoveWindow(window->win32.handle,
1602 area.left, area.top,
1603 area.right - area.left,
1604 area.bottom - area.top, TRUE);
1614 GetWindowRect(window->win32.handle, &area);
1615 applyAspectRatio(window, WMSZ_BOTTOMRIGHT, &area);
1616 MoveWindow(window->win32.handle,
1617 area.left, area.top,
1618 area.right - area.left,
1619 area.bottom - area.top, TRUE);
1628 int* left,
int* top,
1629 int* right,
int* bottom)
1635 SetRect(&rect, 0, 0, width, height);
1640 FALSE, getWindowExStyle(window),
1645 AdjustWindowRectEx(&rect, getWindowStyle(window),
1646 FALSE, getWindowExStyle(window));
1654 *right = rect.right - width;
1656 *bottom = rect.bottom - height;
1660 float* xscale,
float* yscale)
1662 const HANDLE handle = MonitorFromWindow(window->win32.handle,
1663 MONITOR_DEFAULTTONEAREST);
1669 ShowWindow(window->win32.handle, SW_MINIMIZE);
1674 ShowWindow(window->win32.handle, SW_RESTORE);
1679 ShowWindow(window->win32.handle, SW_MAXIMIZE);
1684 ShowWindow(window->win32.handle, SW_SHOWNA);
1689 ShowWindow(window->win32.handle, SW_HIDE);
1694 FlashWindow(window->win32.handle, TRUE);
1699 BringWindowToTop(window->win32.handle);
1700 SetForegroundWindow(window->win32.handle);
1701 SetFocus(window->win32.handle);
1707 int width,
int height,
1710 if (window->
monitor == monitor)
1714 if (monitor->
window == window)
1716 acquireMonitor(window);
1717 fitToMonitor(window);
1722 RECT rect = { xpos, ypos, xpos + width, ypos + height };
1727 FALSE, getWindowExStyle(window),
1732 AdjustWindowRectEx(&rect, getWindowStyle(window),
1733 FALSE, getWindowExStyle(window));
1736 SetWindowPos(window->win32.handle, HWND_TOP,
1737 rect.left, rect.top,
1738 rect.right - rect.left, rect.bottom - rect.top,
1739 SWP_NOCOPYBITS | SWP_NOACTIVATE | SWP_NOZORDER);
1746 releaseMonitor(window);
1752 MONITORINFO mi = {
sizeof(mi) };
1753 UINT flags = SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOCOPYBITS;
1757 DWORD style = GetWindowLongW(window->win32.handle, GWL_STYLE);
1758 style &= ~WS_OVERLAPPEDWINDOW;
1759 style |= getWindowStyle(window);
1760 SetWindowLongW(window->win32.handle, GWL_STYLE, style);
1761 flags |= SWP_FRAMECHANGED;
1764 acquireMonitor(window);
1766 GetMonitorInfo(window->
monitor->win32.handle, &mi);
1767 SetWindowPos(window->win32.handle, HWND_TOPMOST,
1770 mi.rcMonitor.right - mi.rcMonitor.left,
1771 mi.rcMonitor.bottom - mi.rcMonitor.top,
1777 RECT rect = { xpos, ypos, xpos + width, ypos + height };
1778 DWORD style = GetWindowLongW(window->win32.handle, GWL_STYLE);
1779 UINT flags = SWP_NOACTIVATE | SWP_NOCOPYBITS;
1784 style |= getWindowStyle(window);
1785 SetWindowLongW(window->win32.handle, GWL_STYLE, style);
1787 flags |= SWP_FRAMECHANGED;
1791 after = HWND_TOPMOST;
1793 after = HWND_NOTOPMOST;
1798 FALSE, getWindowExStyle(window),
1803 AdjustWindowRectEx(&rect, getWindowStyle(window),
1804 FALSE, getWindowExStyle(window));
1807 SetWindowPos(window->win32.handle, after,
1808 rect.left, rect.top,
1809 rect.right - rect.left, rect.bottom - rect.top,
1816 return window->win32.handle == GetActiveWindow();
1821 return IsIconic(window->win32.handle);
1826 return IsWindowVisible(window->win32.handle);
1831 return IsZoomed(window->win32.handle);
1836 return cursorInContentArea(window);
1841 BOOL composition, opaque;
1844 if (!window->win32.transparent)
1868 updateWindowStyles(window);
1873 updateWindowStyles(window);
1878 const HWND after = enabled ? HWND_TOPMOST : HWND_NOTOPMOST;
1879 SetWindowPos(window->win32.handle, after, 0, 0, 0, 0,
1880 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1888 DWORD exStyle = GetWindowLongW(window->win32.handle, GWL_EXSTYLE);
1890 if (exStyle & WS_EX_LAYERED)
1891 GetLayeredWindowAttributes(window->win32.handle, &key, &alpha, &flags);
1894 exStyle |= (WS_EX_TRANSPARENT | WS_EX_LAYERED);
1897 exStyle &= ~WS_EX_TRANSPARENT;
1900 if (exStyle & WS_EX_LAYERED)
1902 if (!(flags & LWA_ALPHA))
1903 exStyle &= ~WS_EX_LAYERED;
1907 SetWindowLongW(window->win32.handle, GWL_EXSTYLE, exStyle);
1910 SetLayeredWindowAttributes(window->win32.handle, key, alpha, flags);
1918 if ((GetWindowLongW(window->win32.handle, GWL_EXSTYLE) & WS_EX_LAYERED) &&
1919 GetLayeredWindowAttributes(window->win32.handle,
NULL, &alpha, &flags))
1921 if (flags & LWA_ALPHA)
1922 return alpha / 255.f;
1930 LONG exStyle = GetWindowLongW(window->win32.handle, GWL_EXSTYLE);
1931 if (opacity < 1.f || (exStyle & WS_EX_TRANSPARENT))
1933 const BYTE alpha = (BYTE) (255 * opacity);
1934 exStyle |= WS_EX_LAYERED;
1935 SetWindowLongW(window->win32.handle, GWL_EXSTYLE, exStyle);
1936 SetLayeredWindowAttributes(window->win32.handle, 0, alpha, LWA_ALPHA);
1938 else if (exStyle & WS_EX_TRANSPARENT)
1940 SetLayeredWindowAttributes(window->win32.handle, 0, 0, 0);
1944 exStyle &= ~WS_EX_LAYERED;
1945 SetWindowLongW(window->win32.handle, GWL_EXSTYLE, exStyle);
1951 if (
_glfw.win32.disabledCursorWindow != window)
1955 enableRawMouseMotion(window);
1957 disableRawMouseMotion(window);
1971 while (PeekMessageW(&msg,
NULL, 0, 0, PM_REMOVE))
1973 if (msg.message == WM_QUIT)
1983 window = window->
next;
1988 TranslateMessage(&msg);
1989 DispatchMessageW(&msg);
2000 handle = GetActiveWindow();
2003 window = GetPropW(handle, L
"GLFW");
2007 const int keys[4][2] =
2015 for (i = 0; i < 4; i++)
2017 const int vk = keys[i][0];
2018 const int key = keys[i][1];
2019 const int scancode =
_glfw.win32.scancodes[key];
2021 if ((GetKeyState(vk) & 0x8000))
2031 window =
_glfw.win32.disabledCursorWindow;
2039 if (window->win32.lastCursorPosX != width / 2 ||
2040 window->win32.lastCursorPosY != height / 2)
2056 MsgWaitForMultipleObjects(0,
NULL, FALSE, (DWORD) (timeout * 1e3), QS_ALLEVENTS);
2063 PostMessage(
_glfw.win32.helperWindowHandle, WM_NULL, 0, 0);
2070 if (GetCursorPos(&pos))
2072 ScreenToClient(window->win32.handle, &pos);
2083 POINT pos = { (int) xpos, (
int) ypos };
2086 window->win32.lastCursorPosX = pos.x;
2087 window->win32.lastCursorPosY = pos.y;
2089 ClientToScreen(window->win32.handle, &pos);
2090 SetCursorPos(pos.x, pos.y);
2098 disableCursor(window);
2100 else if (
_glfw.win32.disabledCursorWindow == window)
2101 enableCursor(window);
2102 else if (cursorInContentArea(window))
2103 updateCursorImage(window);
2108 if (scancode < 0 || scancode > (KF_EXTENDED | 0xff) ||
2115 return _glfw.win32.keynames[
_glfw.win32.keycodes[scancode]];
2120 return _glfw.win32.scancodes[key];
2127 cursor->win32.handle = (HCURSOR) createIcon(image, xhot, yhot,
GLFW_FALSE);
2128 if (!cursor->win32.handle)
2175 cursor->win32.handle = LoadImageW(
NULL,
2176 MAKEINTRESOURCEW(
id), IMAGE_CURSOR, 0, 0,
2177 LR_DEFAULTSIZE | LR_SHARED);
2178 if (!cursor->win32.handle)
2181 "Win32: Failed to create standard cursor");
2190 if (cursor->win32.handle)
2191 DestroyIcon((HICON) cursor->win32.handle);
2196 if (cursorInContentArea(window))
2197 updateCursorImage(window);
2206 characterCount = MultiByteToWideChar(CP_UTF8, 0,
string, -1,
NULL, 0);
2207 if (!characterCount)
2210 object = GlobalAlloc(GMEM_MOVEABLE, characterCount *
sizeof(WCHAR));
2214 "Win32: Failed to allocate global handle for clipboard");
2218 buffer = GlobalLock(
object);
2222 "Win32: Failed to lock global handle");
2227 MultiByteToWideChar(CP_UTF8, 0,
string, -1, buffer, characterCount);
2228 GlobalUnlock(
object);
2230 if (!OpenClipboard(
_glfw.win32.helperWindowHandle))
2233 "Win32: Failed to open clipboard");
2239 SetClipboardData(CF_UNICODETEXT,
object);
2248 if (!OpenClipboard(
_glfw.win32.helperWindowHandle))
2251 "Win32: Failed to open clipboard");
2255 object = GetClipboardData(CF_UNICODETEXT);
2259 "Win32: Failed to convert clipboard to string");
2264 buffer = GlobalLock(
object);
2268 "Win32: Failed to lock global handle");
2273 free(
_glfw.win32.clipboardString);
2276 GlobalUnlock(
object);
2279 return _glfw.win32.clipboardString;
2312 *attribs = calloc(3,
sizeof(
EGLint));
2314 (*attribs)[1] = type;
2325 return GetDC(
_glfw.win32.helperWindowHandle);
2330 return window->win32.handle;
2338 extensions[0] =
"VK_KHR_surface";
2339 extensions[1] =
"VK_KHR_win32_surface";
2347 vkGetPhysicalDeviceWin32PresentationSupportKHR =
2350 if (!vkGetPhysicalDeviceWin32PresentationSupportKHR)
2353 "Win32: Vulkan instance missing VK_KHR_win32_surface extension");
2357 return vkGetPhysicalDeviceWin32PresentationSupportKHR(device, queuefamily);
2371 if (!vkCreateWin32SurfaceKHR)
2374 "Win32: Vulkan instance missing VK_KHR_win32_surface extension");
2378 memset(&sci, 0,
sizeof(sci));
2381 sci.
hwnd = window->win32.handle;
2383 err = vkCreateWin32SurfaceKHR(instance, &sci, allocator, surface);
2387 "Win32: Failed to create Vulkan surface: %s",
2403 return window->win32.handle;
void _glfwPlatformGetVideoMode(_GLFWmonitor *monitor, GLFWvidmode *mode)
void _glfwPlatformGetMonitorPos(_GLFWmonitor *monitor, int *xpos, int *ypos)
GLFWbool _glfwInitEGL(void)
GLFWbool _glfwCreateContextEGL(_GLFWwindow *window, const _GLFWctxconfig *ctxconfig, const _GLFWfbconfig *fbconfig)
#define EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE
#define EGL_PLATFORM_ANGLE_TYPE_ANGLE
#define EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE
#define EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE
void * EGLNativeDisplayType
void * EGLNativeWindowType
#define EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE
#define EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE
#define EGL_PLATFORM_ANGLE_ANGLE
#define GLFW_ANGLE_PLATFORM_TYPE_OPENGLES
#define GLFW_EGL_CONTEXT_API
#define GLFW_NATIVE_CONTEXT_API
#define GLFW_CURSOR_DISABLED
#define GLFW_ANGLE_PLATFORM_TYPE_VULKAN
#define GLFW_ANGLE_PLATFORM_TYPE_D3D9
#define GLFW_ANGLE_PLATFORM_TYPE_D3D11
#define GLFW_ANGLE_PLATFORM_TYPE_OPENGL
#define GLFW_CURSOR_NORMAL
#define GLFW_OSMESA_CONTEXT_API
#define GLFW_FORMAT_UNAVAILABLE
The requested format is not supported or available.
#define GLFW_API_UNAVAILABLE
GLFW could not find support for the requested API on the system.
#define GLFW_INVALID_VALUE
One of the arguments to the function was an invalid value.
#define GLFW_PLATFORM_ERROR
A platform-specific error occurred that does not match any of the more specific categories.
#define GLFW_KEY_LEFT_SHIFT
#define GLFW_KEY_LEFT_CONTROL
#define GLFW_KEY_RIGHT_CONTROL
#define GLFW_KEY_RIGHT_SUPER
#define GLFW_KEY_LEFT_SUPER
#define GLFW_KEY_RIGHT_SHIFT
#define GLFW_MOD_SHIFT
If this bit is set one or more Shift keys were held down.
#define GLFW_MOD_NUM_LOCK
If this bit is set the Num Lock key is enabled.
#define GLFW_MOD_SUPER
If this bit is set one or more Super keys were held down.
#define GLFW_MOD_CONTROL
If this bit is set one or more Control keys were held down.
#define GLFW_MOD_ALT
If this bit is set one or more Alt keys were held down.
#define GLFW_MOD_CAPS_LOCK
If this bit is set the Caps Lock key is enabled.
#define GLFW_RESIZE_EW_CURSOR
The horizontal resize/move arrow shape.
#define GLFW_NOT_ALLOWED_CURSOR
The operation-not-allowed shape.
#define GLFW_IBEAM_CURSOR
The text input I-beam cursor shape.
#define GLFW_RESIZE_ALL_CURSOR
The omni-directional resize/move cursor shape.
#define GLFW_ARROW_CURSOR
The regular arrow cursor shape.
#define GLFW_CROSSHAIR_CURSOR
The crosshair cursor shape.
#define GLFW_RESIZE_NS_CURSOR
The vertical resize/move arrow shape.
#define GLFW_POINTING_HAND_CURSOR
The pointing hand cursor shape.
#define GLFW_RESIZE_NESW_CURSOR
The top-right to bottom-left diagonal resize/move arrow shape.
#define GLFW_RESIZE_NWSE_CURSOR
The top-left to bottom-right diagonal resize/move arrow shape.
struct GLFWwindow GLFWwindow
Opaque window object.
void _glfwInputError(int code, const char *format,...)
void _glfwInputMonitorWindow(_GLFWmonitor *monitor, _GLFWwindow *window)
void _glfwInputFramebufferSize(_GLFWwindow *window, int width, int height)
void _glfwInputWindowIconify(_GLFWwindow *window, GLFWbool iconified)
void _glfwInputWindowMaximize(_GLFWwindow *window, GLFWbool maximized)
void _glfwInputWindowSize(_GLFWwindow *window, int width, int height)
void _glfwInputWindowMonitor(_GLFWwindow *window, _GLFWmonitor *monitor)
#define _GLFW_REQUIRE_INIT_OR_RETURN(x)
void _glfwInputWindowPos(_GLFWwindow *window, int xpos, int ypos)
const char * _glfwGetVulkanResultString(VkResult result)
void _glfwInputWindowContentScale(_GLFWwindow *window, float xscale, float yscale)
void _glfwInputWindowDamage(_GLFWwindow *window)
void _glfwInputWindowCloseRequest(_GLFWwindow *window)
void _glfwInputWindowFocus(_GLFWwindow *window, GLFWbool focused)
@ VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR
GLFWbool _glfwCreateContextOSMesa(_GLFWwindow *window, const _GLFWctxconfig *ctxconfig, const _GLFWfbconfig *fbconfig)
GLFWbool _glfwInitOSMesa(void)
_GLFWdestroycontextfun destroy
GLFWbool ANGLE_platform_angle_d3d
GLFWbool ANGLE_platform_angle
GLFWbool ANGLE_platform_angle_vulkan
GLFWbool ANGLE_platform_angle_opengl
struct _GLFWlibrary::@25 vk
_GLFWwindow * windowListHead
GLFWbool joysticksInitialized
struct _GLFWlibrary::@23 hints
char mouseButtons[GLFW_MOUSE_BUTTON_LAST+1]
struct _GLFWwindow * next
char keys[GLFW_KEY_LAST+1]
struct _GLFWwndconfig::@20 win32
@ VK_ERROR_EXTENSION_NOT_PRESENT
#define vkGetInstanceProcAddr
GLFWbool _glfwCreateContextWGL(_GLFWwindow *window, const _GLFWctxconfig *ctxconfig, const _GLFWfbconfig *fbconfig)
GLFWbool _glfwInitWGL(void)
void _glfwInputErrorWin32(int error, const char *description)
WCHAR * _glfwCreateWideStringFromUTF8Win32(const char *source)
char * _glfwCreateUTF8FromWideStringWin32(const WCHAR *source)
void _glfwUpdateKeyNamesWin32(void)
void _glfwDetectJoystickDisconnectionWin32(void)
void _glfwDetectJoystickConnectionWin32(void)
void _glfwPollMonitorsWin32(void)
void _glfwSetVideoModeWin32(_GLFWmonitor *monitor, const GLFWvidmode *desired)
void _glfwGetMonitorContentScaleWin32(HMONITOR handle, float *xscale, float *yscale)
void _glfwRestoreVideoModeWin32(_GLFWmonitor *monitor)
void _glfwPlatformSetWindowMonitor(_GLFWwindow *window, _GLFWmonitor *monitor, int xpos, int ypos, int width, int height, int refreshRate)
void _glfwPlatformSetWindowPos(_GLFWwindow *window, int xpos, int ypos)
void _glfwPlatformGetWindowContentScale(_GLFWwindow *window, float *xscale, float *yscale)
void _glfwPlatformSetWindowResizable(_GLFWwindow *window, GLFWbool enabled)
int _glfwPlatformWindowIconified(_GLFWwindow *window)
void _glfwPlatformMaximizeWindow(_GLFWwindow *window)
EGLenum _glfwPlatformGetEGLPlatform(EGLint **attribs)
void _glfwPlatformIconifyWindow(_GLFWwindow *window)
void _glfwPlatformSetWindowSize(_GLFWwindow *window, int width, int height)
void _glfwPlatformWaitEvents(void)
void _glfwPlatformSetWindowSizeLimits(_GLFWwindow *window, int minwidth, int minheight, int maxwidth, int maxheight)
void _glfwPlatformGetRequiredInstanceExtensions(char **extensions)
VkResult _glfwPlatformCreateWindowSurface(VkInstance instance, _GLFWwindow *window, const VkAllocationCallbacks *allocator, VkSurfaceKHR *surface)
int _glfwPlatformFramebufferTransparent(_GLFWwindow *window)
int _glfwPlatformCreateCursor(_GLFWcursor *cursor, const GLFWimage *image, int xhot, int yhot)
void _glfwPlatformPollEvents(void)
void _glfwPlatformGetFramebufferSize(_GLFWwindow *window, int *width, int *height)
int _glfwPlatformWindowVisible(_GLFWwindow *window)
GLFWbool _glfwRegisterWindowClassWin32(void)
void _glfwPlatformSetCursor(_GLFWwindow *window, _GLFWcursor *cursor)
void _glfwPlatformGetWindowSize(_GLFWwindow *window, int *width, int *height)
void _glfwPlatformGetWindowFrameSize(_GLFWwindow *window, int *left, int *top, int *right, int *bottom)
void _glfwPlatformSetWindowIcon(_GLFWwindow *window, int count, const GLFWimage *images)
EGLNativeWindowType _glfwPlatformGetEGLNativeWindow(_GLFWwindow *window)
const char * _glfwPlatformGetScancodeName(int scancode)
void _glfwPlatformSetWindowDecorated(_GLFWwindow *window, GLFWbool enabled)
void _glfwPlatformGetWindowPos(_GLFWwindow *window, int *xpos, int *ypos)
void _glfwPlatformSetWindowOpacity(_GLFWwindow *window, float opacity)
void _glfwPlatformSetCursorPos(_GLFWwindow *window, double xpos, double ypos)
float _glfwPlatformGetWindowOpacity(_GLFWwindow *window)
void _glfwPlatformDestroyCursor(_GLFWcursor *cursor)
GLFWAPI HWND glfwGetWin32Window(GLFWwindow *handle)
void _glfwPlatformRestoreWindow(_GLFWwindow *window)
void _glfwUnregisterWindowClassWin32(void)
GLFWbool _glfwPlatformRawMouseMotionSupported(void)
void _glfwPlatformSetCursorMode(_GLFWwindow *window, int mode)
int _glfwPlatformWindowHovered(_GLFWwindow *window)
void _glfwPlatformDestroyWindow(_GLFWwindow *window)
void _glfwPlatformWaitEventsTimeout(double timeout)
void _glfwPlatformHideWindow(_GLFWwindow *window)
int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily)
int _glfwPlatformWindowMaximized(_GLFWwindow *window)
void _glfwPlatformSetClipboardString(const char *string)
void _glfwPlatformShowWindow(_GLFWwindow *window)
void _glfwPlatformSetRawMouseMotion(_GLFWwindow *window, GLFWbool enabled)
int _glfwPlatformWindowFocused(_GLFWwindow *window)
void _glfwPlatformPostEmptyEvent(void)
int _glfwPlatformGetKeyScancode(int key)
int _glfwPlatformCreateStandardCursor(_GLFWcursor *cursor, int shape)
int _glfwPlatformCreateWindow(_GLFWwindow *window, const _GLFWwndconfig *wndconfig, const _GLFWctxconfig *ctxconfig, const _GLFWfbconfig *fbconfig)
void _glfwPlatformSetWindowAspectRatio(_GLFWwindow *window, int numer, int denom)
const char * _glfwPlatformGetClipboardString(void)
void _glfwPlatformGetCursorPos(_GLFWwindow *window, double *xpos, double *ypos)
void _glfwPlatformRequestWindowAttention(_GLFWwindow *window)
EGLNativeDisplayType _glfwPlatformGetEGLNativeDisplay(void)
void _glfwPlatformSetWindowTitle(_GLFWwindow *window, const char *title)
void _glfwPlatformFocusWindow(_GLFWwindow *window)
void _glfwPlatformSetWindowMousePassthrough(_GLFWwindow *window, GLFWbool enabled)
void _glfwPlatformSetWindowFloating(_GLFWwindow *window, GLFWbool enabled)