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;
54 #define STYLE_BASIC (WS_CLIPSIBLINGS | WS_CLIPCHILDREN) 55 #define STYLE_FULLSCREEN (WS_POPUP) 56 #define STYLE_BORDERLESS (WS_POPUP) 57 #define STYLE_NORMAL (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX) 58 #define STYLE_RESIZABLE (WS_THICKFRAME | WS_MAXIMIZEBOX) 59 #define STYLE_MASK (STYLE_FULLSCREEN | STYLE_BORDERLESS | STYLE_NORMAL | STYLE_RESIZABLE) 67 style |= STYLE_FULLSCREEN;
70 style |= STYLE_BORDERLESS;
72 style |= STYLE_NORMAL;
77 style |= STYLE_RESIZABLE;
90 rect.right = (use_current ? window->
w : window->
windowed.
w);
91 rect.bottom = (use_current ? window->
h : window->
windowed.
h);
92 AdjustWindowRectEx(&rect, style, menu, 0);
94 *x = (use_current ? window->
x : window->
windowed.
x) + rect.left;
95 *y = (use_current ? window->
y : window->
windowed.
y) + rect.top;
96 *width = (rect.right - rect.left);
97 *height = (rect.bottom - rect.top);
104 HWND hwnd = data->
hwnd;
108 style = GetWindowLong(hwnd, GWL_STYLE);
109 menu = (style & WS_CHILDWINDOW) ?
FALSE : (GetMenu(hwnd) !=
NULL);
110 WIN_AdjustWindowRectWithStyle(window, style, menu, x, y, width, height, use_current);
117 HWND hwnd = data->
hwnd;
126 top = HWND_NOTOPMOST;
129 WIN_AdjustWindowRect(window, &x, &y, &w, &
h,
SDL_TRUE);
132 SetWindowPos(hwnd,
top, x, y, w,
h, flags);
150 data->
hdc = GetDC(hwnd);
151 data->
hinstance = (HINSTANCE) GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
160 if (!SetProp(hwnd, TEXT(
"SDL_WindowData"), data)) {
161 ReleaseDC(hwnd, data->
hdc);
168 data->
wndproc = (WNDPROC) GetWindowLongPtr(hwnd, GWLP_WNDPROC);
175 data->
wndproc = (WNDPROC) GetWindowLong(hwnd, GWL_WNDPROC);
186 if (GetClientRect(hwnd, &rect)) {
189 if ((window->
w && window->
w != w) || (window->
h && window->
h != h)) {
195 WIN_AdjustWindowRect(window, &x, &y, &w, &h,
SDL_TRUE);
196 SetWindowPos(hwnd, HWND_NOTOPMOST, x, y, w, h, SWP_NOCOPYBITS | SWP_NOZORDER | SWP_NOACTIVATE);
207 if (ClientToScreen(hwnd, &point)) {
213 DWORD style = GetWindowLong(hwnd, GWL_STYLE);
214 if (style & WS_VISIBLE) {
219 if (style & (WS_BORDER | WS_THICKFRAME)) {
224 if (style & WS_THICKFRAME) {
230 if (style & WS_MAXIMIZE) {
238 if (style & WS_MINIMIZE) {
246 if (GetFocus() == hwnd) {
252 GetClientRect(hwnd, &rect);
253 ClientToScreen(hwnd, (LPPOINT) & rect);
254 ClientToScreen(hwnd, (LPPOINT) & rect + 1);
260 if (videodata->RegisterTouchWindow) {
265 DragAcceptFiles(hwnd,
TRUE);
278 HWND hwnd, parent =
NULL;
279 DWORD style = STYLE_BASIC;
284 parent = CreateWindow(
SDL_Appname, TEXT(
""), STYLE_BASIC, 0, 0, 32, 32,
NULL,
NULL,
SDL_Instance,
NULL);
287 style |= GetWindowStyle(window);
290 WIN_AdjustWindowRectWithStyle(window, style,
FALSE, &x, &y, &w, &h,
SDL_TRUE);
301 if (SetupWindowData(
_this, window, hwnd, parent,
SDL_TRUE) < 0) {
304 DestroyWindow(parent);
314 #if SDL_VIDEO_OPENGL_ES2 320 #if SDL_VIDEO_OPENGL_EGL 321 if (WIN_GLES_SetupWindow(
_this, window) < 0) {
327 return SDL_SetError(
"Could not create GLES window surface (EGL support not configured)");
332 #if SDL_VIDEO_OPENGL_WGL 333 if (WIN_GL_SetupWindow(
_this, window) < 0) {
338 return SDL_SetError(
"Could not create GL window (WGL support not configured)");
347 HWND hwnd = (HWND) data;
352 titleLen = GetWindowTextLength(hwnd);
355 titleLen = GetWindowText(hwnd, title, titleLen);
366 if (SetupWindowData(
_this, window, hwnd, GetParent(hwnd),
SDL_FALSE) < 0) {
370 #if SDL_VIDEO_OPENGL_WGL 387 if(!WIN_GL_SetPixelFormatFrom(
_this, otherWindow, window)) {
403 SetWindowText(hwnd, title);
417 icon_len = 40 + icon->
h * icon->
w *
sizeof(
Uint32);
446 hicon = CreateIconFromResource(icon_bmp, icon_len,
TRUE, 0x00030000);
452 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);
455 SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
461 WIN_SetWindowPositionInternal(
_this, window, SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOACTIVATE);
467 WIN_SetWindowPositionInternal(
_this, window, SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOACTIVATE);
474 ShowWindow(hwnd, SW_SHOW);
481 ShowWindow(hwnd, SW_HIDE);
488 SetForegroundWindow(hwnd);
495 HWND hwnd = data->
hwnd;
497 ShowWindow(hwnd, SW_MAXIMIZE);
505 ShowWindow(hwnd, SW_MINIMIZE);
512 HWND hwnd = data->
hwnd;
515 style = GetWindowLong(hwnd, GWL_STYLE);
516 style &= ~STYLE_MASK;
517 style |= GetWindowStyle(window);
520 SetWindowLong(hwnd, GWL_STYLE, style);
521 WIN_SetWindowPositionInternal(
_this, window, SWP_NOCOPYBITS | SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOACTIVATE);
529 HWND hwnd = data->
hwnd;
532 style = GetWindowLong(hwnd, GWL_STYLE);
533 style &= ~STYLE_MASK;
534 style |= GetWindowStyle(window);
536 SetWindowLong(hwnd, GWL_STYLE, style);
543 HWND hwnd = data->
hwnd;
545 ShowWindow(hwnd, SW_RESTORE);
553 HWND hwnd = data->
hwnd;
563 top = HWND_NOTOPMOST;
566 style = GetWindowLong(hwnd, GWL_STYLE);
567 style &= ~STYLE_MASK;
568 style |= GetWindowStyle(window);
581 if (style & WS_MAXIMIZE) {
583 style &= ~WS_MAXIMIZE;
593 style |= WS_MAXIMIZE;
597 WIN_AdjustWindowRect(window, &x, &y, &w, &h,
SDL_FALSE);
599 SetWindowLong(hwnd, GWL_STYLE, style);
601 SetWindowPos(hwnd,
top, x, y, w, h, SWP_NOCOPYBITS | SWP_NOACTIVATE);
611 BOOL succeeded =
FALSE;
615 succeeded = SetDeviceGammaRamp(hdc, (LPVOID)ramp);
621 return succeeded ? 0 : -1;
630 BOOL succeeded =
FALSE;
634 succeeded = GetDeviceGammaRamp(hdc, (LPVOID)ramp);
640 return succeeded ? 0 : -1;
649 UINT flags = SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOSIZE;
652 flags |= SWP_NOACTIVATE;
654 WIN_SetWindowPositionInternal(
_this, window, flags);
664 ReleaseDC(data->
hwnd, data->
hdc);
665 RemoveProp(data->
hwnd, TEXT(
"SDL_WindowData"));
667 DestroyWindow(data->
hwnd);
669 DestroyWindow(data->
parent);
675 SetWindowLongPtr(data->
hwnd, GWLP_WNDPROC,
678 SetWindowLong(data->
hwnd, GWL_WNDPROC,
699 info->
info.win.hdc = data->
hdc;
719 SDL_HelperWindowCreate(
void)
721 HINSTANCE hInstance = GetModuleHandle(
NULL);
725 if (SDL_HelperWindow !=
NULL) {
731 wce.lpfnWndProc = DefWindowProc;
732 wce.lpszClassName = (LPCWSTR) SDL_HelperWindowClassName;
733 wce.hInstance = hInstance;
736 SDL_HelperWindowClass = RegisterClass(&wce);
737 if (SDL_HelperWindowClass == 0 && GetLastError() != ERROR_CLASS_ALREADY_EXISTS) {
738 return WIN_SetError(
"Unable to create Helper Window Class");
742 SDL_HelperWindow = CreateWindowEx(0, SDL_HelperWindowClassName,
743 SDL_HelperWindowName,
744 WS_OVERLAPPED, CW_USEDEFAULT,
745 CW_USEDEFAULT, CW_USEDEFAULT,
746 CW_USEDEFAULT, HWND_MESSAGE,
NULL,
748 if (SDL_HelperWindow ==
NULL) {
749 UnregisterClass(SDL_HelperWindowClassName, hInstance);
761 SDL_HelperWindowDestroy(
void)
763 HINSTANCE hInstance = GetModuleHandle(
NULL);
766 if (SDL_HelperWindow !=
NULL) {
767 if (DestroyWindow(SDL_HelperWindow) == 0) {
771 SDL_HelperWindow =
NULL;
775 if (SDL_HelperWindowClass != 0) {
776 if ((UnregisterClass(SDL_HelperWindowClassName, hInstance)) == 0) {
780 SDL_HelperWindowClass = 0;
788 if (!data || !data->
hwnd) {
794 WIN_SetWindowPositionInternal(
_this, window, SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOACTIVATE);
799 TRACKMOUSEEVENT trackMouseEvent;
801 trackMouseEvent.cbSize =
sizeof(TRACKMOUSEEVENT);
802 trackMouseEvent.dwFlags = TME_LEAVE;
803 trackMouseEvent.hwndTrack = data->
hwnd;
805 TrackMouseEvent(&trackMouseEvent);
822 if (mouse->relative_mode && !mouse->relative_mode_warp) {
825 GetWindowRect(data->
hwnd, &rect);
827 cx = (rect.left + rect.right) / 2;
828 cy = (rect.top + rect.bottom) / 2;
834 rect.bottom = cy + 1;
839 if (GetClientRect(data->
hwnd, &rect) && !IsRectEmpty(&rect)) {
840 ClientToScreen(data->
hwnd, (LPPOINT) & rect);
841 ClientToScreen(data->
hwnd, (LPPOINT) & rect + 1);
860 const HWND hwnd = data->
hwnd;
861 const LONG style = GetWindowLong(hwnd, GWL_EXSTYLE);
865 if (opacity == 1.0
f) {
867 if (style & WS_EX_LAYERED) {
868 if (SetWindowLong(hwnd, GWL_EXSTYLE, style & ~WS_EX_LAYERED) == 0) {
873 const BYTE
alpha = (BYTE) ((
int) (opacity * 255.0f));
875 if ((style & WS_EX_LAYERED) == 0) {
876 if (SetWindowLong(hwnd, GWL_EXSTYLE, style | WS_EX_LAYERED) == 0) {
881 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
uint32_t Uint32
An unsigned 32-bit integer type.
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)
int WIN_CreateWindow(_THIS, SDL_Window *window)
struct SDL_VideoDevice::@33 gl_config
static SDL_VideoDevice * _this
SDL_bool windowed_mode_was_maximized
SDL_bool in_border_change
void * SDL_calloc(size_t nmemb, size_t size)
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
uint8_t Uint8
An unsigned 8-bit integer type.
#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)
uint16_t Uint16
An unsigned 16-bit integer type.
SDL_bool in_window_deactivation
union SDL_SysWMinfo::@18 info
void WIN_SetWindowBordered(_THIS, SDL_Window *window, SDL_bool bordered)
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