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);
481 WIN_SetWindowPositionInternal(
_this, window, SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOSIZE);
488 HWND hwnd = data->
hwnd;
490 ShowWindow(hwnd, SW_MAXIMIZE);
498 ShowWindow(hwnd, SW_MINIMIZE);
505 HWND hwnd = data->
hwnd;
506 DWORD style = GetWindowLong(hwnd, GWL_STYLE);
509 style &= ~STYLE_BORDERLESS;
510 style |= STYLE_NORMAL;
512 style &= ~STYLE_NORMAL;
513 style |= STYLE_BORDERLESS;
517 SetWindowLong(hwnd, GWL_STYLE, style);
518 WIN_SetWindowPositionInternal(
_this, window, SWP_NOCOPYBITS | SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOACTIVATE);
526 HWND hwnd = data->
hwnd;
528 ShowWindow(hwnd, SW_RESTORE);
536 HWND hwnd = data->
hwnd;
548 top = HWND_NOTOPMOST;
551 style = GetWindowLong(hwnd, GWL_STYLE);
552 style &= ~STYLE_MASK;
553 style |= GetWindowStyle(window);
566 if (style & WS_MAXIMIZE) {
568 style &= ~WS_MAXIMIZE;
578 style |= WS_MAXIMIZE;
585 menu = (style & WS_CHILDWINDOW) ?
FALSE : (GetMenu(hwnd) !=
NULL);
586 AdjustWindowRectEx(&rect, style, menu, 0);
587 w = (rect.right - rect.left);
588 h = (rect.bottom - rect.top);
592 SetWindowLong(hwnd, GWL_STYLE, style);
594 SetWindowPos(hwnd,
top, x, y, w, h, SWP_NOCOPYBITS | SWP_NOACTIVATE);
604 BOOL succeeded =
FALSE;
608 succeeded = SetDeviceGammaRamp(hdc, (LPVOID)ramp);
614 return succeeded ? 0 : -1;
623 BOOL succeeded =
FALSE;
627 succeeded = GetDeviceGammaRamp(hdc, (LPVOID)ramp);
633 return succeeded ? 0 : -1;
642 UINT flags = SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOSIZE;
645 flags |= SWP_NOACTIVATE;
647 WIN_SetWindowPositionInternal(
_this, window, flags);
657 ReleaseDC(data->
hwnd, data->
hdc);
658 RemoveProp(data->
hwnd, TEXT(
"SDL_WindowData"));
660 DestroyWindow(data->
hwnd);
665 SetWindowLongPtr(data->
hwnd, GWLP_WNDPROC,
668 SetWindowLong(data->
hwnd, GWL_WNDPROC,
685 info->
info.win.hdc = data->
hdc;
688 SDL_SetError(
"Application not compiled with SDL %d.%d\n",
699 SDL_HelperWindowCreate(
void)
701 HINSTANCE hInstance = GetModuleHandle(
NULL);
705 if (SDL_HelperWindow !=
NULL) {
711 wce.lpfnWndProc = DefWindowProc;
712 wce.lpszClassName = (LPCWSTR) SDL_HelperWindowClassName;
713 wce.hInstance = hInstance;
716 SDL_HelperWindowClass = RegisterClass(&wce);
717 if (SDL_HelperWindowClass == 0 && GetLastError() != ERROR_CLASS_ALREADY_EXISTS) {
718 return WIN_SetError(
"Unable to create Helper Window Class");
722 SDL_HelperWindow = CreateWindowEx(0, SDL_HelperWindowClassName,
723 SDL_HelperWindowName,
724 WS_OVERLAPPED, CW_USEDEFAULT,
725 CW_USEDEFAULT, CW_USEDEFAULT,
726 CW_USEDEFAULT, HWND_MESSAGE,
NULL,
728 if (SDL_HelperWindow ==
NULL) {
729 UnregisterClass(SDL_HelperWindowClassName, hInstance);
741 SDL_HelperWindowDestroy(
void)
743 HINSTANCE hInstance = GetModuleHandle(
NULL);
746 if (SDL_HelperWindow !=
NULL) {
747 if (DestroyWindow(SDL_HelperWindow) == 0) {
751 SDL_HelperWindow =
NULL;
755 if (SDL_HelperWindowClass != 0) {
756 if ((UnregisterClass(SDL_HelperWindowClassName, hInstance)) == 0) {
760 SDL_HelperWindowClass = 0;
768 TRACKMOUSEEVENT trackMouseEvent;
770 if (!data || !data->
hwnd) {
775 trackMouseEvent.cbSize =
sizeof(TRACKMOUSEEVENT);
776 trackMouseEvent.dwFlags = TME_LEAVE;
777 trackMouseEvent.hwndTrack = data->
hwnd;
779 TrackMouseEvent(&trackMouseEvent);
795 if (mouse->relative_mode && !mouse->relative_mode_warp) {
798 GetWindowRect(data->
hwnd, &rect);
800 cx = (rect.left + rect.right) / 2;
801 cy = (rect.top + rect.bottom) / 2;
807 rect.bottom = cy + 1;
812 if (GetClientRect(data->
hwnd, &rect) && !IsRectEmpty(&rect)) {
813 ClientToScreen(data->
hwnd, (LPPOINT) & rect);
814 ClientToScreen(data->
hwnd, (LPPOINT) & rect + 1);
#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)
#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)
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)
GLint GLint GLint GLint GLint x
void WIN_OnWindowEnter(_THIS, SDL_Window *window)
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)
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)
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
struct SDL_VideoDevice::@27 gl_config
#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)
GLint GLint GLint GLint GLint GLint y
SDL_VideoDisplay * SDL_GetDisplayForWindow(SDL_Window *window)
void WIN_SetWindowGrab(_THIS, SDL_Window *window, SDL_bool grabbed)
The type used to identify a window.
SDL_bool focus_click_pending
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)
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
GLdouble GLdouble GLdouble GLdouble top
A rectangle, with the origin at the upper left.