36 #define _GLFW_KEY_INVALID -2 38 #define _GLFW_WNDCLASSNAME L"GLFW30" 45 DWORD style = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
49 style |= WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
52 style |= WS_MAXIMIZEBOX | WS_SIZEBOX;
64 DWORD style = WS_EX_APPWINDOW;
67 style |= WS_EX_WINDOWEDGE;
77 GetClientRect(window->win32.handle, &clipRect);
78 ClientToScreen(window->win32.handle, (POINT*) &clipRect.left);
79 ClientToScreen(window->win32.handle, (POINT*) &clipRect.right);
80 ClipCursor(&clipRect);
91 if (GetCursorPos(&pos))
93 if (WindowFromPoint(pos) == window->win32.handle)
106 if (GetCursorPos(&pos))
108 if (WindowFromPoint(pos) == window->win32.handle)
121 if (GetCursorPos(&pos))
123 if (WindowFromPoint(pos) == window->win32.handle)
126 SetCursor(window->
cursor->win32.handle);
128 SetCursor(LoadCursorW(NULL, IDC_ARROW));
162 if (GetKeyState(VK_SHIFT) & (1 << 31))
164 if (GetKeyState(VK_CONTROL) & (1 << 31))
166 if (GetKeyState(VK_MENU) & (1 << 31))
168 if ((GetKeyState(VK_LWIN) | GetKeyState(VK_RWIN)) & (1 << 31))
180 if (GetAsyncKeyState(VK_SHIFT) & (1 << 31))
182 if (GetAsyncKeyState(VK_CONTROL) & (1 << 31))
184 if (GetAsyncKeyState(VK_MENU) & (1 << 31))
186 if ((GetAsyncKeyState(VK_LWIN) | GetAsyncKeyState(VK_RWIN)) & (1 << 31))
196 if (wParam == VK_CONTROL)
204 if (lParam & 0x01000000)
210 time = GetMessageTime();
212 if (PeekMessageW(&next, NULL, 0, 0, PM_NOREMOVE))
214 if (next.message == WM_KEYDOWN ||
215 next.message == WM_SYSKEYDOWN ||
216 next.message == WM_KEYUP ||
217 next.message == WM_SYSKEYUP)
219 if (next.wParam == VK_MENU &&
220 (next.lParam & 0x01000000) &&
233 return _glfw.win32.publicKeys[HIWORD(lParam) & 0x1FF];
249 SetWindowPos(window->win32.handle, HWND_TOPMOST,
250 xpos, ypos, mode.
width, mode.
height, SWP_NOCOPYBITS);
265 WPARAM wParam, LPARAM lParam)
273 CREATESTRUCTW* cs = (CREATESTRUCTW*) lParam;
274 SetWindowLongPtrW(hWnd, 0, (LONG_PTR) cs->lpCreateParams);
301 switch (wParam & 0xfff0)
304 case SC_MONITORPOWER:
332 const int scancode = (lParam >> 16) & 0x1ff;
372 const int scancode = (lParam >> 16) & 0x1ff;
377 if (wParam == VK_SHIFT)
384 else if (wParam == VK_SNAPSHOT)
405 if (uMsg == WM_LBUTTONDOWN)
407 else if (uMsg == WM_RBUTTONDOWN)
409 else if (uMsg == WM_MBUTTONDOWN)
413 if (HIWORD(wParam) == XBUTTON1)
415 else if (HIWORD(wParam) == XBUTTON2)
433 if (uMsg == WM_LBUTTONUP)
435 else if (uMsg == WM_RBUTTONUP)
437 else if (uMsg == WM_MBUTTONUP)
441 if (HIWORD(wParam) == XBUTTON1)
443 else if (HIWORD(wParam) == XBUTTON2)
454 const int x = GET_X_LPARAM(lParam);
455 const int y = GET_Y_LPARAM(lParam);
472 if (!window->win32.cursorTracked)
475 ZeroMemory(&tme,
sizeof(tme));
476 tme.cbSize =
sizeof(tme);
477 tme.dwFlags = TME_LEAVE;
478 tme.hwndTrack = window->win32.handle;
479 TrackMouseEvent(&tme);
481 window->win32.cursorTracked = GL_TRUE;
490 window->win32.cursorTracked = GL_FALSE;
497 _glfwInputScroll(window, 0.0, (SHORT) HIWORD(wParam) / (
double) WHEEL_DELTA);
505 _glfwInputScroll(window, -((SHORT) HIWORD(wParam) / (
double) WHEEL_DELTA), 0.0);
517 if (!window->win32.iconified && wParam == SIZE_MINIMIZED)
519 window->win32.iconified = GL_TRUE;
525 else if (window->win32.iconified &&
526 (wParam == SIZE_RESTORED || wParam == SIZE_MAXIMIZED))
528 window->win32.iconified = GL_FALSE;
551 GET_X_LPARAM(lParam),
552 GET_Y_LPARAM(lParam));
579 SetCursor(window->
cursor->win32.handle);
587 case WM_DEVICECHANGE:
589 if (DBT_DEVNODES_CHANGED == wParam)
599 HDROP drop = (HDROP) wParam;
603 const int count = DragQueryFileW(drop, 0xffffffff, NULL, 0);
604 char**
paths = calloc(count,
sizeof(
char*));
607 DragQueryPoint(drop, &pt);
610 for (i = 0; i <
count; i++)
612 const UINT length = DragQueryFileW(drop, i, NULL, 0);
613 WCHAR*
buffer = calloc(length + 1,
sizeof(WCHAR));
615 DragQueryFileW(drop, i, buffer, length + 1);
623 for (i = 0; i <
count; i++)
632 return DefWindowProc(hWnd, uMsg, wParam, lParam);
638 int clientWidth,
int clientHeight,
639 int* fullWidth,
int* fullHeight)
641 RECT
rect = { 0, 0, clientWidth, clientHeight };
644 *fullWidth = rect.right - rect.left;
645 *fullHeight = rect.bottom - rect.top;
655 int xpos, ypos, fullWidth, fullHeight;
667 fullWidth = mode.
width;
672 xpos = CW_USEDEFAULT;
673 ypos = CW_USEDEFAULT;
677 &fullWidth, &fullHeight);
684 "Win32: Failed to convert window title to UTF-16");
693 fullWidth, fullHeight,
696 GetModuleHandleW(NULL),
701 if (!window->win32.handle)
719 SetWindowPos(window->win32.handle,
722 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
725 DragAcceptFiles(window->win32.handle, TRUE);
739 if (window->win32.handle)
741 DestroyWindow(window->win32.handle);
742 window->win32.handle = NULL;
757 wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
760 wc.cbWndExtra =
sizeof(
void*) +
sizeof(
int);
761 wc.hInstance = GetModuleHandleW(NULL);
762 wc.hCursor = LoadCursorW(NULL, IDC_ARROW);
763 wc.hbrBackground = NULL;
764 wc.lpszMenuName = NULL;
768 wc.hIcon = LoadIconW(GetModuleHandleW(NULL), L
"GLFW_ICON");
772 wc.hIcon = LoadIconW(NULL, IDI_WINLOGO);
775 if (!RegisterClassW(&wc))
778 "Win32: Failed to register window class");
804 if (!
createWindow(window, wndconfig, ctxconfig, fbconfig))
839 if (!
createWindow(window, wndconfig, ctxconfig, fbconfig))
867 "Win32: Failed to convert window title to UTF-16");
871 SetWindowTextW(window->win32.handle, wideTitle);
877 POINT pos = { 0, 0 };
878 ClientToScreen(window->win32.handle, &pos);
888 RECT
rect = { xpos, ypos, xpos, ypos };
891 SetWindowPos(window->win32.handle, NULL, rect.left, rect.top, 0, 0,
892 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE);
898 GetClientRect(window->win32.handle, &area);
903 *height = area.bottom;
912 int fullWidth, fullHeight;
915 SetWindowPos(window->win32.handle, HWND_TOP,
916 0, 0, fullWidth, fullHeight,
917 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOZORDER);
934 SetRect(&rect, 0, 0, width, height);
943 *right = rect.right -
width;
945 *bottom = rect.bottom -
height;
950 ShowWindow(window->win32.handle, SW_MINIMIZE);
955 ShowWindow(window->win32.handle, SW_RESTORE);
960 ShowWindow(window->win32.handle, SW_SHOW);
961 BringWindowToTop(window->win32.handle);
962 SetForegroundWindow(window->win32.handle);
963 SetFocus(window->win32.handle);
968 ShowWindow(window->win32.handle, SW_SHOW);
973 ShowWindow(window->win32.handle, SW_HIDE);
978 return window->win32.handle == GetActiveWindow();
983 return IsIconic(window->win32.handle);
988 return IsWindowVisible(window->win32.handle);
995 while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE))
997 if (msg.message == WM_QUIT)
1007 window = window->
next;
1012 TranslateMessage(&msg);
1013 DispatchMessageW(&msg);
1028 const int lshiftDown = (GetAsyncKeyState(VK_LSHIFT) >> 15) & 1;
1029 const int rshiftDown = (GetAsyncKeyState(VK_RSHIFT) >> 15) & 1;
1066 PostMessage(window->win32.handle, WM_NULL, 0, 0);
1073 if (GetCursorPos(&pos))
1075 ScreenToClient(window->win32.handle, &pos);
1086 POINT pos = { (
int) xpos, (
int) ypos };
1092 ClientToScreen(window->win32.handle, &pos);
1093 SetCursorPos(pos.x, pos.y);
1124 ZeroMemory(&bi,
sizeof(bi));
1125 bi.bV5Size =
sizeof(BITMAPV5HEADER);
1126 bi.bV5Width = image->
width;
1127 bi.bV5Height = -image->
height;
1129 bi.bV5BitCount = 32;
1130 bi.bV5Compression = BI_BITFIELDS;
1131 bi.bV5RedMask = 0x00ff0000;
1132 bi.bV5GreenMask = 0x0000ff00;
1133 bi.bV5BlueMask = 0x000000ff;
1134 bi.bV5AlphaMask = 0xff000000;
1137 bitmap = CreateDIBSection(dc, (BITMAPINFO*) &bi, DIB_RGB_COLORS,
1138 (
void**) &target, NULL, (DWORD) 0);
1139 ReleaseDC(NULL, dc);
1144 mask = CreateBitmap(image->
width, image->
height, 1, 1, NULL);
1147 DeleteObject(bitmap);
1151 for (i = 0; i < image->
width * image->
height; i++, target++, source += 4)
1153 *target = (source[3] << 24) |
1159 ZeroMemory(&ii,
sizeof(ii));
1166 cursor->win32.handle = (HCURSOR) CreateIconIndirect(&ii);
1168 DeleteObject(bitmap);
1171 if (!cursor->win32.handle)
1179 cursor->win32.handle =
1181 if (!cursor->win32.handle)
1184 "Win32: Failed to create standard cursor");
1193 if (cursor->win32.handle)
1194 DestroyIcon((HICON) cursor->win32.handle);
1207 if (!GetCursorPos(&pos))
1210 if (WindowFromPoint(pos) != window->win32.handle)
1214 SetCursor(cursor->win32.handle);
1216 SetCursor(LoadCursorW(NULL, IDC_ARROW));
1229 "Win32: Failed to convert string to UTF-16");
1233 wideSize = (wcslen(wideString) + 1) *
sizeof(WCHAR);
1235 stringHandle = GlobalAlloc(GMEM_MOVEABLE, wideSize);
1241 "Win32: Failed to allocate global handle for clipboard");
1245 memcpy(GlobalLock(stringHandle), wideString, wideSize);
1246 GlobalUnlock(stringHandle);
1248 if (!OpenClipboard(window->win32.handle))
1250 GlobalFree(stringHandle);
1258 SetClipboardData(CF_UNICODETEXT, stringHandle);
1268 if (!OpenClipboard(window->win32.handle))
1274 stringHandle = GetClipboardData(CF_UNICODETEXT);
1280 "Win32: Failed to convert clipboard to string");
1284 free(
_glfw.win32.clipboardString);
1285 _glfw.win32.clipboardString =
1288 GlobalUnlock(stringHandle);
1291 if (!
_glfw.win32.clipboardString)
1294 "Win32: Failed to convert wide string to UTF-8");
1298 return _glfw.win32.clipboardString;
1310 return window->win32.handle;
void _glfwInputChar(_GLFWwindow *window, unsigned int codepoint, int mods, int plain)
Notifies shared code of a Unicode character input event.
static DWORD getWindowStyle(const _GLFWwindow *window)
#define GLFW_KEY_RIGHT_CONTROL
#define GLFW_MOD_CONTROL
If this bit is set one or more Control keys were held down.
static int translateKey(WPARAM wParam, LPARAM lParam)
int _glfwAnalyzeContext(const _GLFWwindow *window, const _GLFWctxconfig *ctxconfig, const _GLFWfbconfig *fbconfig)
GLsizei const GLuint * paths
void _glfwInputWindowIconify(_GLFWwindow *window, int iconified)
Notifies shared code of a window iconification event.
GLint GLint GLsizei GLsizei height
GLboolean _glfwSetVideoMode(_GLFWmonitor *monitor, const GLFWvidmode *desired)
static void updateClipRect(_GLFWwindow *window)
GLint GLint GLint GLint GLint GLint y
void _glfwInputWindowSize(_GLFWwindow *window, int width, int height)
Notifies shared code of a window resize event.
GLenum GLenum GLsizei void * image
typedef HANDLE(WINAPI *PFNWGLCREATEBUFFERREGIONARBPROC)(HDC hDC
#define GLFW_KEY_LEFT_SHIFT
#define GLFW_CROSSHAIR_CURSOR
The crosshair shape.
static GLboolean enterFullscreenMode(_GLFWwindow *window)
void _glfwInputWindowFocus(_GLFWwindow *window, GLboolean focused)
Notifies shared code of a window focus event.
#define GLFW_FORMAT_UNAVAILABLE
The requested format is not supported or available.
#define GLFW_ARROW_CURSOR
The regular arrow cursor shape.
static int getAsyncKeyMods(void)
_GLFWwindow * windowListHead
_GLFWlibrary _glfw
All global data protected by _glfwInitialized. This should only be touched after a call to glfwInit t...
void _glfwInputWindowDamage(_GLFWwindow *window)
Notifies shared code of a window damage event.
struct GLFWwindow GLFWwindow
Opaque window object.
void _glfwInputWindowCloseRequest(_GLFWwindow *window)
Notifies shared code of a window close request event.
void _glfwInputDrop(_GLFWwindow *window, int count, const char **paths)
Notifies dropped object over window.
#define GLFW_CURSOR_DISABLED
#define GLFW_VRESIZE_CURSOR
The vertical resize arrow shape.
void _glfwDestroyContext(_GLFWwindow *window)
#define _GLFW_REQUIRE_INIT_OR_RETURN(x)
char keys[GLFW_KEY_LAST+1]
_GLFWwindow * cursorWindow
typedef GLboolean(APIENTRYP PFNGLISQUERYPROC)(GLuint id)
#define GLFW_CURSOR_NORMAL
#define GLFW_PLATFORM_ERROR
A platform-specific error occurred that does not match any of the more specific categories.
GLuint GLuint GLsizei count
#define GLFW_MOD_SUPER
If this bit is set one or more Super keys were held down.
#define GLFW_HAND_CURSOR
The hand shape.
#define GLFW_MOD_SHIFT
If this bit is set one or more Shift keys were held down.
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
static void destroyWindow(_GLFWwindow *window)
void _glfwRestoreVideoMode(_GLFWmonitor *monitor)
#define _GLFW_WNDCLASSNAME
struct _GLFWwindow * next
void _glfwInputMouseClick(_GLFWwindow *window, int button, int action, int mods)
Notifies shared code of a mouse button click event.
typedef HDC(WINAPI *PFNWGLGETCURRENTREADDCARBPROC)(void)
void _glfwInputWindowPos(_GLFWwindow *window, int xpos, int ypos)
Notifies shared code of a window movement event.
#define GLFW_MOD_ALT
If this bit is set one or more Alt keys were held down.
int _glfwCreateContext(_GLFWwindow *window, const _GLFWctxconfig *ctxconfig, const _GLFWfbconfig *fbconfig)
static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
void _glfwInputScroll(_GLFWwindow *window, double xoffset, double yoffset)
Notifies shared code of a scroll event.
static DWORD getWindowExStyle(const _GLFWwindow *window)
void _glfwInputCursorEnter(_GLFWwindow *window, int entered)
Notifies shared code of a cursor enter/leave event.
static void hideCursor(_GLFWwindow *window)
#define GLFW_CURSOR_HIDDEN
void _glfwInputCursorMotion(_GLFWwindow *window, double x, double y)
Notifies shared code of a cursor motion event.
void _glfwInputMonitorChange(void)
static void restoreCursor(_GLFWwindow *window)
GLint GLint GLsizei width
#define GLFW_HRESIZE_CURSOR
The horizontal resize arrow shape.
GLsizei GLsizei GLchar * source
void _glfwInputKey(_GLFWwindow *window, int key, int scancode, int action, int mods)
Notifies shared code of a physical key event.
#define GLFW_IBEAM_CURSOR
The text input I-beam cursor shape.
#define GLFW_KEY_LEFT_CONTROL
GLuint GLsizei GLsizei * length
static void leaveFullscreenMode(_GLFWwindow *window)
GLboolean _glfwRegisterWindowClass(void)
void _glfwInputError(int error, const char *format,...)
Notifies shared code of an error.
void _glfwInputFramebufferSize(_GLFWwindow *window, int width, int height)
Notifies shared code of a framebuffer resize event.
GLsizei GLfixed GLfixed GLfixed GLfixed const GLubyte * bitmap
typedef UINT(WINAPI *PFNWGLGETGPUIDSAMDPROC)(UINT maxCount
static LPWSTR translateCursorShape(int shape)
#define _GLFW_KEY_INVALID
Window and context structure.
Framebuffer configuration.
#define GLFW_KEY_RIGHT_SHIFT
GLdouble GLdouble GLdouble GLdouble top
char * _glfwCreateUTF8FromWideString(const WCHAR *source)
static void getFullWindowSize(_GLFWwindow *window, int clientWidth, int clientHeight, int *fullWidth, int *fullHeight)
GLint GLint GLint GLint GLint x
static int getKeyMods(void)
void _glfwUnregisterWindowClass(void)
WCHAR * _glfwCreateWideStringFromUTF8(const char *source)
static int createWindow(_GLFWwindow *window, const _GLFWwndconfig *wndconfig, const _GLFWctxconfig *ctxconfig, const _GLFWfbconfig *fbconfig)
GLFWAPI HWND glfwGetWin32Window(GLFWwindow *handle)
static void disableCursor(_GLFWwindow *window)