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;
59 #define STYLE_BASIC (WS_CLIPSIBLINGS | WS_CLIPCHILDREN) 60 #define STYLE_FULLSCREEN (WS_POPUP) 61 #define STYLE_BORDERLESS (WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX) 62 #define STYLE_NORMAL (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX) 63 #define STYLE_RESIZABLE (WS_THICKFRAME | WS_MAXIMIZEBOX) 64 #define STYLE_MASK (STYLE_FULLSCREEN | STYLE_BORDERLESS | STYLE_NORMAL | STYLE_RESIZABLE) 72 style |= STYLE_FULLSCREEN;
75 style |= STYLE_BORDERLESS;
77 style |= STYLE_NORMAL;
82 style |= STYLE_RESIZABLE;
95 rect.right = (use_current ? window->
w : window->
windowed.
w);
96 rect.bottom = (use_current ? window->
h : window->
windowed.
h);
101 AdjustWindowRectEx(&rect, style, menu, 0);
103 *x = (use_current ? window->
x : window->
windowed.
x) + rect.left;
104 *y = (use_current ? window->
y : window->
windowed.
y) + rect.top;
105 *width = (rect.right - rect.left);
106 *height = (rect.bottom - rect.top);
110 WIN_AdjustWindowRect(
SDL_Window *window,
int *x,
int *y,
int *width,
int *height,
SDL_bool use_current)
113 HWND hwnd = data->
hwnd;
117 style = GetWindowLong(hwnd, GWL_STYLE);
118 menu = (style & WS_CHILDWINDOW) ?
FALSE : (GetMenu(hwnd) !=
NULL);
119 WIN_AdjustWindowRectWithStyle(window, style, menu, x, y, width, height, use_current);
126 HWND hwnd = data->
hwnd;
135 top = HWND_NOTOPMOST;
138 WIN_AdjustWindowRect(window, &x, &y, &w, &
h,
SDL_TRUE);
141 SetWindowPos(hwnd,
top, x, y, w,
h, flags);
159 data->
hdc = GetDC(hwnd);
160 data->
hinstance = (HINSTANCE) GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
169 if (!SetProp(hwnd, TEXT(
"SDL_WindowData"), data)) {
170 ReleaseDC(hwnd, data->
hdc);
177 data->
wndproc = (WNDPROC) GetWindowLongPtr(hwnd, GWLP_WNDPROC);
184 data->
wndproc = (WNDPROC) GetWindowLong(hwnd, GWL_WNDPROC);
195 if (GetClientRect(hwnd, &rect)) {
198 if ((window->
w && window->
w != w) || (window->
h && window->
h != h)) {
204 WIN_AdjustWindowRect(window, &x, &y, &w, &h,
SDL_TRUE);
205 SetWindowPos(hwnd, HWND_NOTOPMOST, x, y, w, h, SWP_NOCOPYBITS | SWP_NOZORDER | SWP_NOACTIVATE);
216 if (ClientToScreen(hwnd, &point)) {
222 DWORD style = GetWindowLong(hwnd, GWL_STYLE);
223 if (style & WS_VISIBLE) {
228 if (style & WS_POPUP) {
233 if (style & WS_THICKFRAME) {
239 if (style & WS_MAXIMIZE) {
247 if (style & WS_MINIMIZE) {
255 if (GetFocus() == hwnd) {
261 GetClientRect(hwnd, &rect);
262 ClientToScreen(hwnd, (LPPOINT) & rect);
263 ClientToScreen(hwnd, (LPPOINT) & rect + 1);
269 if (videodata->RegisterTouchWindow) {
274 DragAcceptFiles(hwnd,
TRUE);
287 HWND hwnd, parent =
NULL;
288 DWORD style = STYLE_BASIC;
293 parent = CreateWindow(
SDL_Appname, TEXT(
""), STYLE_BASIC, 0, 0, 32, 32,
NULL,
NULL,
SDL_Instance,
NULL);
296 style |= GetWindowStyle(window);
299 WIN_AdjustWindowRectWithStyle(window, style,
FALSE, &x, &y, &w, &h,
SDL_TRUE);
310 if (SetupWindowData(
_this, window, hwnd, parent,
SDL_TRUE) < 0) {
313 DestroyWindow(parent);
319 SetWindowPos(hwnd,
NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
326 #if SDL_VIDEO_OPENGL_ES2 332 #if SDL_VIDEO_OPENGL_EGL 333 if (WIN_GLES_SetupWindow(
_this, window) < 0) {
339 return SDL_SetError(
"Could not create GLES window surface (EGL support not configured)");
344 #if SDL_VIDEO_OPENGL_WGL 345 if (WIN_GL_SetupWindow(
_this, window) < 0) {
350 return SDL_SetError(
"Could not create GL window (WGL support not configured)");
359 HWND hwnd = (HWND) data;
364 titleLen = GetWindowTextLength(hwnd);
367 titleLen = GetWindowText(hwnd, title, titleLen);
378 if (SetupWindowData(
_this, window, hwnd, GetParent(hwnd),
SDL_FALSE) < 0) {
382 #if SDL_VIDEO_OPENGL_WGL 399 if(!WIN_GL_SetPixelFormatFrom(
_this, otherWindow, window)) {
415 SetWindowText(hwnd, title);
429 icon_len = 40 + icon->
h * icon->
w *
sizeof(
Uint32);
458 hicon = CreateIconFromResource(icon_bmp, icon_len,
TRUE, 0x00030000);
464 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);
467 SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
473 WIN_SetWindowPositionInternal(
_this, window, SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOACTIVATE);
479 WIN_SetWindowPositionInternal(
_this, window, SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOACTIVATE);
486 ShowWindow(hwnd, SW_SHOW);
493 ShowWindow(hwnd, SW_HIDE);
500 SetForegroundWindow(hwnd);
507 HWND hwnd = data->
hwnd;
509 ShowWindow(hwnd, SW_MAXIMIZE);
517 ShowWindow(hwnd, SW_MINIMIZE);
524 HWND hwnd = data->
hwnd;
527 style = GetWindowLong(hwnd, GWL_STYLE);
528 style &= ~STYLE_MASK;
529 style |= GetWindowStyle(window);
532 SetWindowLong(hwnd, GWL_STYLE, style);
533 WIN_SetWindowPositionInternal(
_this, window, SWP_NOCOPYBITS | SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOACTIVATE);
541 HWND hwnd = data->
hwnd;
544 style = GetWindowLong(hwnd, GWL_STYLE);
545 style &= ~STYLE_MASK;
546 style |= GetWindowStyle(window);
548 SetWindowLong(hwnd, GWL_STYLE, style);
555 HWND hwnd = data->
hwnd;
557 ShowWindow(hwnd, SW_RESTORE);
565 HWND hwnd = data->
hwnd;
575 top = HWND_NOTOPMOST;
578 style = GetWindowLong(hwnd, GWL_STYLE);
579 style &= ~STYLE_MASK;
580 style |= GetWindowStyle(window);
593 if (style & WS_MAXIMIZE) {
595 style &= ~WS_MAXIMIZE;
607 style |= WS_MAXIMIZE;
611 menu = (style & WS_CHILDWINDOW) ?
FALSE : (GetMenu(hwnd) !=
NULL);
612 WIN_AdjustWindowRectWithStyle(window, style, menu, &x, &y, &w, &h,
SDL_FALSE);
614 SetWindowLong(hwnd, GWL_STYLE, style);
616 SetWindowPos(hwnd,
top, x, y, w, h, SWP_NOCOPYBITS | SWP_NOACTIVATE);
626 BOOL succeeded =
FALSE;
630 succeeded = SetDeviceGammaRamp(hdc, (LPVOID)ramp);
636 return succeeded ? 0 : -1;
645 BOOL succeeded =
FALSE;
649 succeeded = GetDeviceGammaRamp(hdc, (LPVOID)ramp);
655 return succeeded ? 0 : -1;
664 UINT flags = SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOSIZE;
667 flags |= SWP_NOACTIVATE;
669 WIN_SetWindowPositionInternal(
_this, window, flags);
679 ReleaseDC(data->
hwnd, data->
hdc);
680 RemoveProp(data->
hwnd, TEXT(
"SDL_WindowData"));
682 DestroyWindow(data->
hwnd);
684 DestroyWindow(data->
parent);
690 SetWindowLongPtr(data->
hwnd, GWLP_WNDPROC,
693 SetWindowLong(data->
hwnd, GWL_WNDPROC,
714 info->
info.win.hdc = data->
hdc;
734 SDL_HelperWindowCreate(
void)
736 HINSTANCE hInstance = GetModuleHandle(
NULL);
740 if (SDL_HelperWindow !=
NULL) {
746 wce.lpfnWndProc = DefWindowProc;
747 wce.lpszClassName = (LPCWSTR) SDL_HelperWindowClassName;
748 wce.hInstance = hInstance;
751 SDL_HelperWindowClass = RegisterClass(&wce);
752 if (SDL_HelperWindowClass == 0 && GetLastError() != ERROR_CLASS_ALREADY_EXISTS) {
753 return WIN_SetError(
"Unable to create Helper Window Class");
757 SDL_HelperWindow = CreateWindowEx(0, SDL_HelperWindowClassName,
758 SDL_HelperWindowName,
759 WS_OVERLAPPED, CW_USEDEFAULT,
760 CW_USEDEFAULT, CW_USEDEFAULT,
761 CW_USEDEFAULT, HWND_MESSAGE,
NULL,
763 if (SDL_HelperWindow ==
NULL) {
764 UnregisterClass(SDL_HelperWindowClassName, hInstance);
776 SDL_HelperWindowDestroy(
void)
778 HINSTANCE hInstance = GetModuleHandle(
NULL);
781 if (SDL_HelperWindow !=
NULL) {
782 if (DestroyWindow(SDL_HelperWindow) == 0) {
786 SDL_HelperWindow =
NULL;
790 if (SDL_HelperWindowClass != 0) {
791 if ((UnregisterClass(SDL_HelperWindowClassName, hInstance)) == 0) {
795 SDL_HelperWindowClass = 0;
803 if (!data || !data->
hwnd) {
809 WIN_SetWindowPositionInternal(
_this, window, SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOACTIVATE);
814 TRACKMOUSEEVENT trackMouseEvent;
816 trackMouseEvent.cbSize =
sizeof(TRACKMOUSEEVENT);
817 trackMouseEvent.dwFlags = TME_LEAVE;
818 trackMouseEvent.hwndTrack = data->
hwnd;
820 TrackMouseEvent(&trackMouseEvent);
837 if (mouse->relative_mode && !mouse->relative_mode_warp) {
840 GetWindowRect(data->
hwnd, &rect);
842 cx = (rect.left + rect.right) / 2;
843 cy = (rect.top + rect.bottom) / 2;
849 rect.bottom = cy + 1;
854 if (GetClientRect(data->
hwnd, &rect) && !IsRectEmpty(&rect)) {
855 ClientToScreen(data->
hwnd, (LPPOINT) & rect);
856 ClientToScreen(data->
hwnd, (LPPOINT) & rect + 1);
875 const HWND hwnd = data->
hwnd;
876 const LONG style = GetWindowLong(hwnd, GWL_EXSTYLE);
880 if (opacity == 1.0
f) {
882 if (style & WS_EX_LAYERED) {
883 if (SetWindowLong(hwnd, GWL_EXSTYLE, style & ~WS_EX_LAYERED) == 0) {
888 const BYTE
alpha = (BYTE) ((
int) (opacity * 255.0f));
890 if ((style & WS_EX_LAYERED) == 0) {
891 if (SetWindowLong(hwnd, GWL_EXSTYLE, style | WS_EX_LAYERED) == 0) {
896 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)
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_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