21 #include "../../SDL_internal.h" 23 #if SDL_VIDEO_DRIVER_WINDOWS 25 #include "../../core/windows/SDL_windows.h" 28 #include "../SDL_sysvideo.h" 29 #include "../SDL_pixels_c.h" 30 #include "../../events/SDL_keyboard_c.h" 31 #include "../../events/SDL_mouse_c.h" 44 #ifndef SWP_NOCOPYBITS 45 #define SWP_NOCOPYBITS 0 49 HWND SDL_HelperWindow =
NULL;
50 static WCHAR *SDL_HelperWindowClassName = TEXT(
"SDLHelperWindowInputCatcher");
51 static WCHAR *SDL_HelperWindowName = TEXT(
"SDLHelperWindowInputMsgWindow");
52 static ATOM SDL_HelperWindowClass = 0;
61 #define STYLE_BASIC (WS_CLIPSIBLINGS | WS_CLIPCHILDREN) 62 #define STYLE_FULLSCREEN (WS_POPUP) 63 #define STYLE_BORDERLESS (WS_POPUP) 64 #define STYLE_BORDERLESS_WINDOWED (WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX) 65 #define STYLE_NORMAL (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX) 66 #define STYLE_RESIZABLE (WS_THICKFRAME | WS_MAXIMIZEBOX) 67 #define STYLE_MASK (STYLE_FULLSCREEN | STYLE_BORDERLESS | STYLE_NORMAL | STYLE_RESIZABLE) 75 style |= STYLE_FULLSCREEN;
88 style |= STYLE_BORDERLESS_WINDOWED;
90 style |= STYLE_BORDERLESS;
93 style |= STYLE_NORMAL;
98 style |= STYLE_RESIZABLE;
103 style |= WS_MINIMIZE;
116 rect.right = (use_current ? window->
w : window->
windowed.
w);
117 rect.bottom = (use_current ? window->
h : window->
windowed.
h);
123 AdjustWindowRectEx(&rect, style, menu, 0);
125 *x = (use_current ? window->
x : window->
windowed.
x) + rect.left;
126 *y = (use_current ? window->
y : window->
windowed.
y) + rect.top;
127 *width = (rect.right - rect.left);
128 *height = (rect.bottom - rect.top);
132 WIN_AdjustWindowRect(
SDL_Window *window,
int *x,
int *y,
int *width,
int *height,
SDL_bool use_current)
135 HWND hwnd = data->
hwnd;
139 style = GetWindowLong(hwnd, GWL_STYLE);
140 menu = (style & WS_CHILDWINDOW) ?
FALSE : (GetMenu(hwnd) !=
NULL);
141 WIN_AdjustWindowRectWithStyle(window, style, menu, x, y, width, height, use_current);
148 HWND hwnd = data->
hwnd;
157 top = HWND_NOTOPMOST;
160 WIN_AdjustWindowRect(window, &x, &y, &w, &
h,
SDL_TRUE);
163 SetWindowPos(hwnd,
top, x, y, w,
h, flags);
181 data->
hdc = GetDC(hwnd);
182 data->
hinstance = (HINSTANCE) GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
191 if (!SetProp(hwnd, TEXT(
"SDL_WindowData"), data)) {
192 ReleaseDC(hwnd, data->
hdc);
199 data->
wndproc = (WNDPROC) GetWindowLongPtr(hwnd, GWLP_WNDPROC);
206 data->
wndproc = (WNDPROC) GetWindowLong(hwnd, GWL_WNDPROC);
217 if (GetClientRect(hwnd, &rect)) {
224 WIN_AdjustWindowRect(window, &x, &y, &w, &h,
SDL_FALSE);
225 SetWindowPos(hwnd, HWND_NOTOPMOST, x, y, w, h, SWP_NOCOPYBITS | SWP_NOZORDER | SWP_NOACTIVATE);
236 if (ClientToScreen(hwnd, &point)) {
242 DWORD style = GetWindowLong(hwnd, GWL_STYLE);
243 if (style & WS_VISIBLE) {
248 if (style & WS_POPUP) {
253 if (style & WS_THICKFRAME) {
259 if (style & WS_MAXIMIZE) {
267 if (style & WS_MINIMIZE) {
275 if (GetFocus() == hwnd) {
281 GetClientRect(hwnd, &rect);
282 ClientToScreen(hwnd, (LPPOINT) & rect);
283 ClientToScreen(hwnd, (LPPOINT) & rect + 1);
289 if (videodata->RegisterTouchWindow) {
304 HWND hwnd, parent =
NULL;
305 DWORD style = STYLE_BASIC;
310 parent = CreateWindow(
SDL_Appname, TEXT(
""), STYLE_BASIC, 0, 0, 32, 32,
NULL,
NULL,
SDL_Instance,
NULL);
313 style |= GetWindowStyle(window);
316 WIN_AdjustWindowRectWithStyle(window, style,
FALSE, &x, &y, &w, &h,
SDL_FALSE);
327 if (SetupWindowData(
_this, window, hwnd, parent,
SDL_TRUE) < 0) {
330 DestroyWindow(parent);
336 SetWindowPos(hwnd,
NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
339 ShowWindow(hwnd, SW_SHOWMINNOACTIVE);
347 #if SDL_VIDEO_OPENGL_ES2 353 #if SDL_VIDEO_OPENGL_EGL 354 if (WIN_GLES_SetupWindow(
_this, window) < 0) {
360 return SDL_SetError(
"Could not create GLES window surface (EGL support not configured)");
365 #if SDL_VIDEO_OPENGL_WGL 366 if (WIN_GL_SetupWindow(
_this, window) < 0) {
371 return SDL_SetError(
"Could not create GL window (WGL support not configured)");
380 HWND hwnd = (HWND) data;
385 titleLen = GetWindowTextLength(hwnd);
388 titleLen = GetWindowText(hwnd, title, titleLen);
399 if (SetupWindowData(
_this, window, hwnd, GetParent(hwnd),
SDL_FALSE) < 0) {
403 #if SDL_VIDEO_OPENGL_WGL 418 if (!WIN_GL_SetPixelFormatFrom(
_this, otherWindow, window)) {
434 SetWindowText(hwnd, title);
444 int icon_len, mask_len,
y;
448 mask_len = (icon->
h * (icon->
w + 7)/8);
449 icon_len = 40 + icon->
h * icon->
w *
sizeof(
Uint32) + mask_len;
479 SDL_memset(icon_bmp + icon_len - mask_len, 0xFF, mask_len);
481 hicon = CreateIconFromResource(icon_bmp, icon_len,
TRUE, 0x00030000);
487 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);
490 SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
496 WIN_SetWindowPositionInternal(
_this, window, SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOACTIVATE);
502 WIN_SetWindowPositionInternal(
_this, window, SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOACTIVATE);
509 RECT rcClient, rcWindow;
514 GetClientRect(hwnd, &rcClient);
515 GetWindowRect(hwnd, &rcWindow);
519 ptDiff.y = rcWindow.top;
520 ptDiff.x = rcWindow.left;
522 ScreenToClient(hwnd, &ptDiff);
524 rcWindow.top = ptDiff.y;
525 rcWindow.left = ptDiff.x;
529 ptDiff.y = rcWindow.bottom;
530 ptDiff.x = rcWindow.right;
532 ScreenToClient(hwnd, &ptDiff);
534 rcWindow.bottom = ptDiff.y;
535 rcWindow.right = ptDiff.x;
540 *top = rcClient.top - rcWindow.top;
541 *left = rcClient.left - rcWindow.left;
542 *bottom = rcWindow.bottom - rcClient.bottom;
543 *right = rcWindow.right - rcClient.right;
557 style = GetWindowLong(hwnd, GWL_EXSTYLE);
558 if (style & WS_EX_NOACTIVATE) {
559 nCmdShow = SW_SHOWNOACTIVATE;
561 ShowWindow(hwnd, nCmdShow);
568 ShowWindow(hwnd, SW_HIDE);
575 SetForegroundWindow(hwnd);
582 HWND hwnd = data->
hwnd;
584 ShowWindow(hwnd, SW_MAXIMIZE);
592 ShowWindow(hwnd, SW_MINIMIZE);
599 HWND hwnd = data->
hwnd;
602 style = GetWindowLong(hwnd, GWL_STYLE);
603 style &= ~STYLE_MASK;
604 style |= GetWindowStyle(window);
607 SetWindowLong(hwnd, GWL_STYLE, style);
608 WIN_SetWindowPositionInternal(
_this, window, SWP_NOCOPYBITS | SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOACTIVATE);
616 HWND hwnd = data->
hwnd;
619 style = GetWindowLong(hwnd, GWL_STYLE);
620 style &= ~STYLE_MASK;
621 style |= GetWindowStyle(window);
623 SetWindowLong(hwnd, GWL_STYLE, style);
630 HWND hwnd = data->
hwnd;
632 ShowWindow(hwnd, SW_RESTORE);
640 HWND hwnd = data->
hwnd;
650 top = HWND_NOTOPMOST;
653 style = GetWindowLong(hwnd, GWL_STYLE);
654 style &= ~STYLE_MASK;
655 style |= GetWindowStyle(window);
668 if (style & WS_MAXIMIZE) {
670 style &= ~WS_MAXIMIZE;
682 style |= WS_MAXIMIZE;
686 menu = (style & WS_CHILDWINDOW) ?
FALSE : (GetMenu(hwnd) !=
NULL);
687 WIN_AdjustWindowRectWithStyle(window, style, menu, &x, &y, &w, &h,
SDL_FALSE);
689 SetWindowLong(hwnd, GWL_STYLE, style);
691 SetWindowPos(hwnd,
top, x, y, w, h, SWP_NOCOPYBITS | SWP_NOACTIVATE);
701 BOOL succeeded =
FALSE;
705 succeeded = SetDeviceGammaRamp(hdc, (LPVOID)ramp);
711 return succeeded ? 0 : -1;
720 BOOL succeeded =
FALSE;
724 succeeded = GetDeviceGammaRamp(hdc, (LPVOID)ramp);
730 return succeeded ? 0 : -1;
739 UINT flags = SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOSIZE;
742 flags |= SWP_NOACTIVATE;
744 WIN_SetWindowPositionInternal(
_this, window, flags);
754 ReleaseDC(data->
hwnd, data->
hdc);
755 RemoveProp(data->
hwnd, TEXT(
"SDL_WindowData"));
757 DestroyWindow(data->
hwnd);
759 DestroyWindow(data->
parent);
765 SetWindowLongPtr(data->
hwnd, GWLP_WNDPROC,
768 SetWindowLong(data->
hwnd, GWL_WNDPROC,
789 info->
info.win.hdc = data->
hdc;
809 SDL_HelperWindowCreate(
void)
811 HINSTANCE hInstance = GetModuleHandle(
NULL);
815 if (SDL_HelperWindow !=
NULL) {
821 wce.lpfnWndProc = DefWindowProc;
822 wce.lpszClassName = (LPCWSTR) SDL_HelperWindowClassName;
823 wce.hInstance = hInstance;
826 SDL_HelperWindowClass = RegisterClass(&wce);
827 if (SDL_HelperWindowClass == 0 && GetLastError() != ERROR_CLASS_ALREADY_EXISTS) {
828 return WIN_SetError(
"Unable to create Helper Window Class");
832 SDL_HelperWindow = CreateWindowEx(0, SDL_HelperWindowClassName,
833 SDL_HelperWindowName,
834 WS_OVERLAPPED, CW_USEDEFAULT,
835 CW_USEDEFAULT, CW_USEDEFAULT,
836 CW_USEDEFAULT, HWND_MESSAGE,
NULL,
838 if (SDL_HelperWindow ==
NULL) {
839 UnregisterClass(SDL_HelperWindowClassName, hInstance);
851 SDL_HelperWindowDestroy(
void)
853 HINSTANCE hInstance = GetModuleHandle(
NULL);
856 if (SDL_HelperWindow !=
NULL) {
857 if (DestroyWindow(SDL_HelperWindow) == 0) {
861 SDL_HelperWindow =
NULL;
865 if (SDL_HelperWindowClass != 0) {
866 if ((UnregisterClass(SDL_HelperWindowClassName, hInstance)) == 0) {
870 SDL_HelperWindowClass = 0;
878 if (!data || !data->
hwnd) {
884 WIN_SetWindowPositionInternal(
_this, window, SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOACTIVATE);
889 TRACKMOUSEEVENT trackMouseEvent;
891 trackMouseEvent.cbSize =
sizeof(TRACKMOUSEEVENT);
892 trackMouseEvent.dwFlags = TME_LEAVE;
893 trackMouseEvent.hwndTrack = data->
hwnd;
895 TrackMouseEvent(&trackMouseEvent);
917 if (mouse->relative_mode && !mouse->relative_mode_warp) {
919 GetWindowRect(data->
hwnd, &rect);
921 cx = (rect.left + rect.right) / 2;
922 cy = (rect.top + rect.bottom) / 2;
928 rect.bottom = cy + 1;
930 if (ClipCursor(&rect)) {
934 if (GetClientRect(data->
hwnd, &rect) && !IsRectEmpty(&rect)) {
935 ClientToScreen(data->
hwnd, (LPPOINT) & rect);
936 ClientToScreen(data->
hwnd, (LPPOINT) & rect + 1);
937 if (ClipCursor(&rect)) {
958 const HWND hwnd = data->
hwnd;
959 const LONG style = GetWindowLong(hwnd, GWL_EXSTYLE);
963 if (opacity == 1.0
f) {
965 if (style & WS_EX_LAYERED) {
966 if (SetWindowLong(hwnd, GWL_EXSTYLE, style & ~WS_EX_LAYERED) == 0) {
971 const BYTE
alpha = (BYTE) ((
int) (opacity * 255.0f));
973 if ((style & WS_EX_LAYERED) == 0) {
974 if (SetWindowLong(hwnd, GWL_EXSTYLE, style | WS_EX_LAYERED) == 0) {
979 if (SetLayeredWindowAttributes(hwnd, 0, alpha, LWA_ALPHA) == 0) {
#define SDL_MINOR_VERSION
#define WIN_UTF8ToString(S)
SDL_Mouse * SDL_GetMouse(void)
void WIN_SetWindowSize(_THIS, SDL_Window *window)
void SDL_SetKeyboardFocus(SDL_Window *window)
GLint GLint GLint GLint GLint x
#define SDL_RWwrite(ctx, ptr, size, n)
#define SDL_MAJOR_VERSION
void WIN_RaiseWindow(_THIS, SDL_Window *window)
int WIN_GetWindowGammaRamp(_THIS, SDL_Window *window, Uint16 *ramp)
LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
void WIN_DestroyWindow(_THIS, SDL_Window *window)
GLfloat GLfloat GLfloat GLfloat h
SDL_bool WIN_GetWindowWMInfo(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info)
A collection of pixels used in software blitting.
void WIN_MaximizeWindow(_THIS, SDL_Window *window)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLdouble GLdouble GLdouble GLdouble top
void WIN_OnWindowEnter(_THIS, SDL_Window *window)
GLfloat GLfloat GLfloat alpha
GLint GLint GLsizei width
struct SDL_GLDriverData * gl_data
void WIN_SetWindowPosition(_THIS, SDL_Window *window)
int WIN_SetWindowHitTest(SDL_Window *window, SDL_bool enabled)
#define SDL_GetHintBoolean
int WIN_CreateWindow(_THIS, SDL_Window *window)
void WIN_AcceptDragAndDrop(SDL_Window *window, SDL_bool accept)
static SDL_VideoDevice * _this
SDL_bool windowed_mode_was_maximized
SDL_bool in_border_change
int WIN_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect)
void WIN_SetWindowResizable(_THIS, SDL_Window *window, SDL_bool resizable)
void WIN_MinimizeWindow(_THIS, SDL_Window *window)
struct SDL_VideoData * videodata
#define SDL_stack_alloc(type, count)
#define SDL_VERSIONNUM(X, Y, Z)
int WIN_SetWindowOpacity(_THIS, SDL_Window *window, float opacity)
void WIN_SetWindowIcon(_THIS, SDL_Window *window, SDL_Surface *icon)
void WIN_ShowWindow(_THIS, SDL_Window *window)
GLubyte GLubyte GLubyte GLubyte w
void WIN_UpdateClipCursor(SDL_Window *window)
#define WIN_StringToUTF8(S)
#define SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT
A variable that is the address of another SDL_Window* (as a hex string formatted with "%p")...
GLint GLint GLint GLint GLint GLint y
#define SDL_VIDEO_OPENGL_WGL
void WIN_RestoreWindow(_THIS, SDL_Window *window)
SDL_bool skip_update_clipcursor
struct SDL_VideoDevice::@36 gl_config
GLenum GLenum GLsizei const GLuint GLboolean enabled
#define SDL_assert(condition)
int WIN_SetWindowGammaRamp(_THIS, SDL_Window *window, const Uint16 *ramp)
SDL_bool SDL_ShouldAllowTopmost(void)
#define SDL_OutOfMemory()
int WIN_SetError(const char *prefix)
void WIN_SetWindowTitle(_THIS, SDL_Window *window)
GLint GLint GLsizei GLsizei height
void WIN_PumpEvents(_THIS)
SDL_VideoDisplay * SDL_GetDisplayForWindow(SDL_Window *window)
EGLSurface EGLNativeWindowType * window
void WIN_SetWindowGrab(_THIS, SDL_Window *window, SDL_bool grabbed)
The type used to identify a window.
void WIN_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen)
SDL_bool in_window_deactivation
union SDL_SysWMinfo::@18 info
void WIN_SetWindowBordered(_THIS, SDL_Window *window, SDL_bool bordered)
int WIN_GetWindowBordersSize(_THIS, SDL_Window *window, int *top, int *left, int *bottom, int *right)
int WIN_CreateWindowFrom(_THIS, SDL_Window *window, const void *data)
#define SDL_stack_free(data)
void WIN_HideWindow(_THIS, SDL_Window *window)
WPARAM mouse_button_flags
A rectangle, with the origin at the upper left.
Uint8 focus_click_pending