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;
75 style |= STYLE_RESIZABLE;
85 HWND hwnd = data->
hwnd;
99 style = GetWindowLong(hwnd, GWL_STYLE);
102 rect.right = window->
w;
103 rect.bottom = window->
h;
104 menu = (style & WS_CHILDWINDOW) ?
FALSE : (GetMenu(hwnd) !=
NULL);
105 AdjustWindowRectEx(&
rect, style, menu, 0);
108 x = window->
x +
rect.left;
112 SetWindowPos(hwnd,
top, x,
y, w,
h, flags);
129 data->
hdc = GetDC(hwnd);
138 if (!SetProp(hwnd, TEXT(
"SDL_WindowData"), data)) {
139 ReleaseDC(hwnd, data->
hdc);
146 data->
wndproc = (WNDPROC) GetWindowLongPtr(hwnd, GWLP_WNDPROC);
153 data->
wndproc = (WNDPROC) GetWindowLong(hwnd, GWL_WNDPROC);
164 if (GetClientRect(hwnd, &rect)) {
167 if ((window->
w && window->
w != w) || (window->
h && window->
h != h)) {
176 style = GetWindowLong(hwnd, GWL_STYLE);
179 rect.right = window->
w;
180 rect.bottom = window->
h;
181 menu = (style & WS_CHILDWINDOW) ?
FALSE : (GetMenu(hwnd) !=
NULL);
182 AdjustWindowRectEx(&rect, style, menu, 0);
183 w = (rect.right - rect.left);
184 h = (rect.bottom - rect.top);
185 x = window->
x + rect.left;
186 y = window->
y + rect.top;
188 SetWindowPos(hwnd, HWND_NOTOPMOST, x, y, w, h, SWP_NOCOPYBITS | SWP_NOZORDER | SWP_NOACTIVATE);
199 if (ClientToScreen(hwnd, &point)) {
205 DWORD style = GetWindowLong(hwnd, GWL_STYLE);
206 if (style & WS_VISIBLE) {
211 if (style & (WS_BORDER | WS_THICKFRAME)) {
216 if (style & WS_THICKFRAME) {
222 if (style & WS_MAXIMIZE) {
230 if (style & WS_MINIMIZE) {
238 if (GetFocus() == hwnd) {
244 GetClientRect(hwnd, &rect);
245 ClientToScreen(hwnd, (LPPOINT) & rect);
246 ClientToScreen(hwnd, (LPPOINT) & rect + 1);
252 if (videodata->RegisterTouchWindow) {
257 DragAcceptFiles(hwnd,
TRUE);
270 DWORD style = STYLE_BASIC;
274 style |= GetWindowStyle(window);
277 rect.left = window->
x;
278 rect.top = window->
y;
279 rect.right = window->
x + window->
w;
280 rect.bottom = window->
y + window->
h;
281 AdjustWindowRectEx(&rect, style,
FALSE, 0);
284 w = (rect.right - rect.left);
285 h = (rect.bottom - rect.top);
301 #if SDL_VIDEO_OPENGL_WGL 304 WIN_GL_InitExtensions(
_this);
308 #if SDL_VIDEO_OPENGL_ES2 315 #if SDL_VIDEO_OPENGL_EGL 316 if (WIN_GLES_SetupWindow(
_this, window) < 0) {
321 return SDL_SetError(
"Could not create GLES window surface (no EGL support available)");
326 #if SDL_VIDEO_OPENGL_WGL 328 if (WIN_GL_SetupWindow(
_this, window) < 0) {
341 HWND hwnd = (HWND) data;
346 titleLen = GetWindowTextLength(hwnd);
349 titleLen = GetWindowText(hwnd, title, titleLen);
364 #if SDL_VIDEO_OPENGL_WGL 381 if(!WIN_GL_SetPixelFormatFrom(
_this, otherWindow, window)) {
397 SetWindowText(hwnd, title);
411 icon_len = 40 + icon->
h * icon->
w * 4;
440 hicon = CreateIconFromResource(icon_bmp, icon_len,
TRUE, 0x00030000);
446 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);
449 SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
455 WIN_SetWindowPositionInternal(
_this, window, SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOACTIVATE);
461 WIN_SetWindowPositionInternal(
_this, window, SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOACTIVATE);
468 ShowWindow(hwnd, SW_SHOW);
475 ShowWindow(hwnd, SW_HIDE);
482 SetForegroundWindow(hwnd);
489 HWND hwnd = data->
hwnd;
491 ShowWindow(hwnd, SW_MAXIMIZE);
499 ShowWindow(hwnd, SW_MINIMIZE);
506 HWND hwnd = data->
hwnd;
507 DWORD style = GetWindowLong(hwnd, GWL_STYLE);
510 style &= ~STYLE_BORDERLESS;
511 style |= STYLE_NORMAL;
513 style &= ~STYLE_NORMAL;
514 style |= STYLE_BORDERLESS;
518 SetWindowLong(hwnd, GWL_STYLE, style);
519 WIN_SetWindowPositionInternal(
_this, window, SWP_NOCOPYBITS | SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOACTIVATE);
527 HWND hwnd = data->
hwnd;
528 DWORD style = GetWindowLong(hwnd, GWL_STYLE);
531 style |= STYLE_RESIZABLE;
533 style &= ~STYLE_RESIZABLE;
536 SetWindowLong(hwnd, GWL_STYLE, style);
543 HWND hwnd = data->
hwnd;
545 ShowWindow(hwnd, SW_RESTORE);
553 HWND hwnd = data->
hwnd;
565 top = HWND_NOTOPMOST;
568 style = GetWindowLong(hwnd, GWL_STYLE);
569 style &= ~STYLE_MASK;
570 style |= GetWindowStyle(window);
583 if (style & WS_MAXIMIZE) {
585 style &= ~WS_MAXIMIZE;
595 style |= WS_MAXIMIZE;
602 menu = (style & WS_CHILDWINDOW) ?
FALSE : (GetMenu(hwnd) !=
NULL);
603 AdjustWindowRectEx(&rect, style, menu, 0);
604 w = (rect.right - rect.left);
605 h = (rect.bottom - rect.top);
609 SetWindowLong(hwnd, GWL_STYLE, style);
611 SetWindowPos(hwnd,
top, x, y, w, h, SWP_NOCOPYBITS | SWP_NOACTIVATE);
621 BOOL succeeded =
FALSE;
625 succeeded = SetDeviceGammaRamp(hdc, (LPVOID)ramp);
631 return succeeded ? 0 : -1;
640 BOOL succeeded =
FALSE;
644 succeeded = GetDeviceGammaRamp(hdc, (LPVOID)ramp);
650 return succeeded ? 0 : -1;
659 UINT flags = SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOSIZE;
662 flags |= SWP_NOACTIVATE;
664 WIN_SetWindowPositionInternal(
_this, window, flags);
674 ReleaseDC(data->
hwnd, data->
hdc);
675 RemoveProp(data->
hwnd, TEXT(
"SDL_WindowData"));
677 DestroyWindow(data->
hwnd);
682 SetWindowLongPtr(data->
hwnd, GWLP_WNDPROC,
685 SetWindowLong(data->
hwnd, GWL_WNDPROC,
702 info->
info.win.hdc = data->
hdc;
705 SDL_SetError(
"Application not compiled with SDL %d.%d\n",
716 SDL_HelperWindowCreate(
void)
718 HINSTANCE hInstance = GetModuleHandle(
NULL);
722 if (SDL_HelperWindow !=
NULL) {
728 wce.lpfnWndProc = DefWindowProc;
729 wce.lpszClassName = (LPCWSTR) SDL_HelperWindowClassName;
730 wce.hInstance = hInstance;
733 SDL_HelperWindowClass = RegisterClass(&wce);
734 if (SDL_HelperWindowClass == 0 && GetLastError() != ERROR_CLASS_ALREADY_EXISTS) {
735 return WIN_SetError(
"Unable to create Helper Window Class");
739 SDL_HelperWindow = CreateWindowEx(0, SDL_HelperWindowClassName,
740 SDL_HelperWindowName,
741 WS_OVERLAPPED, CW_USEDEFAULT,
742 CW_USEDEFAULT, CW_USEDEFAULT,
743 CW_USEDEFAULT, HWND_MESSAGE,
NULL,
745 if (SDL_HelperWindow ==
NULL) {
746 UnregisterClass(SDL_HelperWindowClassName, hInstance);
758 SDL_HelperWindowDestroy(
void)
760 HINSTANCE hInstance = GetModuleHandle(
NULL);
763 if (SDL_HelperWindow !=
NULL) {
764 if (DestroyWindow(SDL_HelperWindow) == 0) {
768 SDL_HelperWindow =
NULL;
772 if (SDL_HelperWindowClass != 0) {
773 if ((UnregisterClass(SDL_HelperWindowClassName, hInstance)) == 0) {
777 SDL_HelperWindowClass = 0;
785 TRACKMOUSEEVENT trackMouseEvent;
787 if (!data || !data->
hwnd) {
792 trackMouseEvent.cbSize =
sizeof(TRACKMOUSEEVENT);
793 trackMouseEvent.dwFlags = TME_LEAVE;
794 trackMouseEvent.hwndTrack = data->
hwnd;
796 TrackMouseEvent(&trackMouseEvent);
812 if (mouse->relative_mode && !mouse->relative_mode_warp) {
815 GetWindowRect(data->
hwnd, &rect);
817 cx = (rect.left + rect.right) / 2;
818 cy = (rect.top + rect.bottom) / 2;
824 rect.bottom = cy + 1;
829 if (GetClientRect(data->
hwnd, &rect) && !IsRectEmpty(&rect)) {
830 ClientToScreen(data->
hwnd, (LPPOINT) & rect);
831 ClientToScreen(data->
hwnd, (LPPOINT) & rect + 1);
850 const HWND hwnd = data->
hwnd;
851 const LONG style = GetWindowLong(hwnd, GWL_EXSTYLE);
855 if (opacity == 1.0
f) {
857 if (style & WS_EX_LAYERED) {
858 if (SetWindowLong(hwnd, GWL_EXSTYLE, style & ~WS_EX_LAYERED) == 0) {
863 const BYTE
alpha = (BYTE) ((
int) (opacity * 255.0f));
865 if ((style & WS_EX_LAYERED) == 0) {
866 if (SetWindowLong(hwnd, GWL_EXSTYLE, style | WS_EX_LAYERED) == 0) {
871 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)
#define SDL_RWwrite(ctx, ptr, size, n)
GLint GLint GLint GLint GLint x
#define SDL_MAJOR_VERSION
void WIN_RaiseWindow(_THIS, SDL_Window *window)
static 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)
SDL_bool WIN_GetWindowWMInfo(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info)
A collection of pixels used in software blitting.
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
void WIN_MaximizeWindow(_THIS, SDL_Window *window)
GLdouble GLdouble GLdouble GLdouble top
void WIN_OnWindowEnter(_THIS, SDL_Window *window)
GLfloat GLfloat GLfloat alpha
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
void * SDL_calloc(size_t nmemb, size_t size)
int WIN_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect)
GLint GLint GLint GLint GLint GLint y
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)
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)
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")...
#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)
void WIN_PumpEvents(_THIS)
SDL_VideoDisplay * SDL_GetDisplayForWindow(SDL_Window *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)
struct SDL_VideoDevice::@28 gl_config
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)
GLubyte GLubyte GLubyte GLubyte w
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
GLfloat GLfloat GLfloat GLfloat h
A rectangle, with the origin at the upper left.
Uint8 focus_click_pending