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;
111 rect.right = (use_current ? window->
w : window->
windowed.
w);
112 rect.bottom = (use_current ? window->
h : window->
windowed.
h);
118 AdjustWindowRectEx(&rect, style, menu, 0);
120 *x = (use_current ? window->
x : window->
windowed.
x) + rect.left;
121 *y = (use_current ? window->
y : window->
windowed.
y) + rect.top;
122 *width = (rect.right - rect.left);
123 *height = (rect.bottom - rect.top);
127 WIN_AdjustWindowRect(
SDL_Window *window,
int *x,
int *y,
int *width,
int *height,
SDL_bool use_current)
130 HWND hwnd = data->
hwnd;
134 style = GetWindowLong(hwnd, GWL_STYLE);
135 menu = (style & WS_CHILDWINDOW) ?
FALSE : (GetMenu(hwnd) !=
NULL);
136 WIN_AdjustWindowRectWithStyle(window, style, menu, x, y, width, height, use_current);
143 HWND hwnd = data->
hwnd;
152 top = HWND_NOTOPMOST;
155 WIN_AdjustWindowRect(window, &x, &y, &w, &
h,
SDL_TRUE);
158 SetWindowPos(hwnd,
top, x, y, w,
h, flags);
176 data->
hdc = GetDC(hwnd);
177 data->
hinstance = (HINSTANCE) GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
186 if (!SetProp(hwnd, TEXT(
"SDL_WindowData"), data)) {
187 ReleaseDC(hwnd, data->
hdc);
194 data->
wndproc = (WNDPROC) GetWindowLongPtr(hwnd, GWLP_WNDPROC);
201 data->
wndproc = (WNDPROC) GetWindowLong(hwnd, GWL_WNDPROC);
212 if (GetClientRect(hwnd, &rect)) {
221 WIN_AdjustWindowRect(window, &x, &y, &w, &h,
SDL_FALSE);
222 SetWindowPos(hwnd, HWND_NOTOPMOST, x, y, w, h, SWP_NOCOPYBITS | SWP_NOZORDER | SWP_NOACTIVATE);
233 if (ClientToScreen(hwnd, &point)) {
239 DWORD style = GetWindowLong(hwnd, GWL_STYLE);
240 if (style & WS_VISIBLE) {
245 if (style & WS_POPUP) {
250 if (style & WS_THICKFRAME) {
256 if (style & WS_MAXIMIZE) {
264 if (style & WS_MINIMIZE) {
272 if (GetFocus() == hwnd) {
278 GetClientRect(hwnd, &rect);
279 ClientToScreen(hwnd, (LPPOINT) & rect);
280 ClientToScreen(hwnd, (LPPOINT) & rect + 1);
286 if (videodata->RegisterTouchWindow) {
291 DragAcceptFiles(hwnd,
TRUE);
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);
343 #if SDL_VIDEO_OPENGL_ES2 349 #if SDL_VIDEO_OPENGL_EGL 350 if (WIN_GLES_SetupWindow(
_this, window) < 0) {
356 return SDL_SetError(
"Could not create GLES window surface (EGL support not configured)");
361 #if SDL_VIDEO_OPENGL_WGL 362 if (WIN_GL_SetupWindow(
_this, window) < 0) {
367 return SDL_SetError(
"Could not create GL window (WGL support not configured)");
376 HWND hwnd = (HWND) data;
381 titleLen = GetWindowTextLength(hwnd);
384 titleLen = GetWindowText(hwnd, title, titleLen);
395 if (SetupWindowData(
_this, window, hwnd, GetParent(hwnd),
SDL_FALSE) < 0) {
399 #if SDL_VIDEO_OPENGL_WGL 416 if(!WIN_GL_SetPixelFormatFrom(
_this, otherWindow, window)) {
432 SetWindowText(hwnd, title);
442 int icon_len, mask_len,
y;
446 mask_len = (icon->
h * (icon->
w + 7)/8);
447 icon_len = 40 + icon->
h * icon->
w *
sizeof(
Uint32) + mask_len;
477 SDL_memset(icon_bmp + icon_len - mask_len, 0xFF, mask_len);
479 hicon = CreateIconFromResource(icon_bmp, icon_len,
TRUE, 0x00030000);
485 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);
488 SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
494 WIN_SetWindowPositionInternal(
_this, window, SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOACTIVATE);
500 WIN_SetWindowPositionInternal(
_this, window, SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOACTIVATE);
507 RECT rcClient, rcWindow;
512 GetClientRect(hwnd, &rcClient);
513 GetWindowRect(hwnd, &rcWindow);
517 ptDiff.y = rcWindow.top;
518 ptDiff.x = rcWindow.left;
520 ScreenToClient(hwnd, &ptDiff);
522 rcWindow.top = ptDiff.y;
523 rcWindow.left = ptDiff.x;
527 ptDiff.y = rcWindow.bottom;
528 ptDiff.x = rcWindow.right;
530 ScreenToClient(hwnd, &ptDiff);
532 rcWindow.bottom = ptDiff.y;
533 rcWindow.right = ptDiff.x;
538 *top = rcClient.top - rcWindow.top;
539 *left = rcClient.left - rcWindow.left;
540 *bottom = rcWindow.bottom - rcClient.bottom;
541 *right = rcWindow.right - rcClient.right;
550 ShowWindow(hwnd, SW_SHOW);
557 ShowWindow(hwnd, SW_HIDE);
564 SetForegroundWindow(hwnd);
571 HWND hwnd = data->
hwnd;
573 ShowWindow(hwnd, SW_MAXIMIZE);
581 ShowWindow(hwnd, SW_MINIMIZE);
588 HWND hwnd = data->
hwnd;
591 style = GetWindowLong(hwnd, GWL_STYLE);
592 style &= ~STYLE_MASK;
593 style |= GetWindowStyle(window);
596 SetWindowLong(hwnd, GWL_STYLE, style);
597 WIN_SetWindowPositionInternal(
_this, window, SWP_NOCOPYBITS | SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOACTIVATE);
605 HWND hwnd = data->
hwnd;
608 style = GetWindowLong(hwnd, GWL_STYLE);
609 style &= ~STYLE_MASK;
610 style |= GetWindowStyle(window);
612 SetWindowLong(hwnd, GWL_STYLE, style);
619 HWND hwnd = data->
hwnd;
621 ShowWindow(hwnd, SW_RESTORE);
629 HWND hwnd = data->
hwnd;
639 top = HWND_NOTOPMOST;
642 style = GetWindowLong(hwnd, GWL_STYLE);
643 style &= ~STYLE_MASK;
644 style |= GetWindowStyle(window);
657 if (style & WS_MAXIMIZE) {
659 style &= ~WS_MAXIMIZE;
671 style |= WS_MAXIMIZE;
675 menu = (style & WS_CHILDWINDOW) ?
FALSE : (GetMenu(hwnd) !=
NULL);
676 WIN_AdjustWindowRectWithStyle(window, style, menu, &x, &y, &w, &h,
SDL_FALSE);
678 SetWindowLong(hwnd, GWL_STYLE, style);
680 SetWindowPos(hwnd,
top, x, y, w, h, SWP_NOCOPYBITS | SWP_NOACTIVATE);
690 BOOL succeeded =
FALSE;
694 succeeded = SetDeviceGammaRamp(hdc, (LPVOID)ramp);
700 return succeeded ? 0 : -1;
709 BOOL succeeded =
FALSE;
713 succeeded = GetDeviceGammaRamp(hdc, (LPVOID)ramp);
719 return succeeded ? 0 : -1;
728 UINT flags = SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOSIZE;
731 flags |= SWP_NOACTIVATE;
733 WIN_SetWindowPositionInternal(
_this, window, flags);
743 ReleaseDC(data->
hwnd, data->
hdc);
744 RemoveProp(data->
hwnd, TEXT(
"SDL_WindowData"));
746 DestroyWindow(data->
hwnd);
748 DestroyWindow(data->
parent);
754 SetWindowLongPtr(data->
hwnd, GWLP_WNDPROC,
757 SetWindowLong(data->
hwnd, GWL_WNDPROC,
778 info->
info.win.hdc = data->
hdc;
798 SDL_HelperWindowCreate(
void)
800 HINSTANCE hInstance = GetModuleHandle(
NULL);
804 if (SDL_HelperWindow !=
NULL) {
810 wce.lpfnWndProc = DefWindowProc;
811 wce.lpszClassName = (LPCWSTR) SDL_HelperWindowClassName;
812 wce.hInstance = hInstance;
815 SDL_HelperWindowClass = RegisterClass(&wce);
816 if (SDL_HelperWindowClass == 0 && GetLastError() != ERROR_CLASS_ALREADY_EXISTS) {
817 return WIN_SetError(
"Unable to create Helper Window Class");
821 SDL_HelperWindow = CreateWindowEx(0, SDL_HelperWindowClassName,
822 SDL_HelperWindowName,
823 WS_OVERLAPPED, CW_USEDEFAULT,
824 CW_USEDEFAULT, CW_USEDEFAULT,
825 CW_USEDEFAULT, HWND_MESSAGE,
NULL,
827 if (SDL_HelperWindow ==
NULL) {
828 UnregisterClass(SDL_HelperWindowClassName, hInstance);
840 SDL_HelperWindowDestroy(
void)
842 HINSTANCE hInstance = GetModuleHandle(
NULL);
845 if (SDL_HelperWindow !=
NULL) {
846 if (DestroyWindow(SDL_HelperWindow) == 0) {
850 SDL_HelperWindow =
NULL;
854 if (SDL_HelperWindowClass != 0) {
855 if ((UnregisterClass(SDL_HelperWindowClassName, hInstance)) == 0) {
859 SDL_HelperWindowClass = 0;
867 if (!data || !data->
hwnd) {
873 WIN_SetWindowPositionInternal(
_this, window, SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOACTIVATE);
878 TRACKMOUSEEVENT trackMouseEvent;
880 trackMouseEvent.cbSize =
sizeof(TRACKMOUSEEVENT);
881 trackMouseEvent.dwFlags = TME_LEAVE;
882 trackMouseEvent.hwndTrack = data->
hwnd;
884 TrackMouseEvent(&trackMouseEvent);
901 if (mouse->relative_mode && !mouse->relative_mode_warp) {
904 GetWindowRect(data->
hwnd, &rect);
906 cx = (rect.left + rect.right) / 2;
907 cy = (rect.top + rect.bottom) / 2;
913 rect.bottom = cy + 1;
918 if (GetClientRect(data->
hwnd, &rect) && !IsRectEmpty(&rect)) {
919 ClientToScreen(data->
hwnd, (LPPOINT) & rect);
920 ClientToScreen(data->
hwnd, (LPPOINT) & rect + 1);
939 const HWND hwnd = data->
hwnd;
940 const LONG style = GetWindowLong(hwnd, GWL_EXSTYLE);
944 if (opacity == 1.0
f) {
946 if (style & WS_EX_LAYERED) {
947 if (SetWindowLong(hwnd, GWL_EXSTYLE, style & ~WS_EX_LAYERED) == 0) {
952 const BYTE
alpha = (BYTE) ((
int) (opacity * 255.0f));
954 if ((style & WS_EX_LAYERED) == 0) {
955 if (SetWindowLong(hwnd, GWL_EXSTYLE, style | WS_EX_LAYERED) == 0) {
960 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)
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)
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)
struct SDL_VideoDevice::@34 gl_config
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