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;
103 style |= WS_MINIMIZE;
123 AdjustWindowRectEx(&
rect, style, menu, 0);
139 style = GetWindowLong(hwnd, GWL_STYLE);
140 menu = (style & WS_CHILDWINDOW) ?
FALSE : (GetMenu(hwnd) !=
NULL);
157 top = HWND_NOTOPMOST;
180 data->parent = parent;
181 data->hdc = GetDC(hwnd);
182 data->hinstance = (HINSTANCE) GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
183 data->created = created;
184 data->mouse_button_flags = 0;
185 data->videodata = videodata;
191 if (!SetProp(hwnd, TEXT(
"SDL_WindowData"),
data)) {
192 ReleaseDC(hwnd,
data->hdc);
199 data->wndproc = (WNDPROC) GetWindowLongPtr(hwnd, GWLP_WNDPROC);
206 data->wndproc = (WNDPROC) GetWindowLong(hwnd, GWL_WNDPROC);
217 if (GetClientRect(hwnd, &
rect)) {
225 SetWindowPos(hwnd, HWND_NOTOPMOST,
x,
y,
w,
h, SWP_NOCOPYBITS | SWP_NOZORDER | SWP_NOACTIVATE);
236 if (ClientToScreen(hwnd, &point)) {
242 DWORD style = GetWindowLong(hwnd, GWL_STYLE);
243 if (style & WS_VISIBLE) {
248 if (style & WS_POPUP) {
253 if (style & WS_THICKFRAME) {
259 if (style & WS_MAXIMIZE) {
267 if (style & WS_MINIMIZE) {
275 if (GetFocus() == hwnd) {
281 GetClientRect(hwnd, &
rect);
282 ClientToScreen(hwnd, (LPPOINT) &
rect);
283 ClientToScreen(hwnd, (LPPOINT) &
rect + 1);
289 if (videodata->RegisterTouchWindow) {
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);
330 DestroyWindow(parent);
336 SetWindowPos(hwnd,
NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
339 ShowWindow(hwnd, SW_SHOWMINNOACTIVE);
347 #if SDL_VIDEO_OPENGL_ES2
353 #if SDL_VIDEO_OPENGL_EGL
360 return SDL_SetError(
"Could not create GLES window surface (EGL support not configured)");
365 #if SDL_VIDEO_OPENGL_WGL
371 return SDL_SetError(
"Could not create GL window (WGL support not configured)");
380 HWND hwnd = (HWND)
data;
385 titleLen = GetWindowTextLength(hwnd);
388 titleLen = GetWindowText(hwnd, title, titleLen);
403 #if SDL_VIDEO_OPENGL_WGL
418 if (!WIN_GL_SetPixelFormatFrom(
_this, otherWindow,
window)) {
434 SetWindowText(hwnd, title);
444 int icon_len, mask_len,
y;
448 mask_len = (icon->
h * (icon->
w + 7)/8);
449 icon_len = 40 + icon->
h * icon->
w *
sizeof(
Uint32) + mask_len;
479 SDL_memset(icon_bmp + icon_len - mask_len, 0xFF, mask_len);
481 hicon = CreateIconFromResource(icon_bmp, icon_len,
TRUE, 0x00030000);
487 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);
490 SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
496 WIN_SetWindowPositionInternal(
_this,
window, SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOACTIVATE);
502 WIN_SetWindowPositionInternal(
_this,
window, SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOACTIVATE);
509 RECT rcClient, rcWindow;
514 GetClientRect(hwnd, &rcClient);
515 GetWindowRect(hwnd, &rcWindow);
519 ptDiff.y = rcWindow.top;
520 ptDiff.x = rcWindow.left;
522 ScreenToClient(hwnd, &ptDiff);
524 rcWindow.top = ptDiff.y;
525 rcWindow.left = ptDiff.x;
529 ptDiff.y = rcWindow.bottom;
530 ptDiff.x = rcWindow.right;
532 ScreenToClient(hwnd, &ptDiff);
534 rcWindow.bottom = ptDiff.y;
535 rcWindow.right = ptDiff.x;
540 *
top = rcClient.top - rcWindow.top;
541 *
left = rcClient.left - rcWindow.left;
542 *
bottom = rcWindow.bottom - rcClient.bottom;
543 *
right = rcWindow.right - rcClient.right;
557 style = GetWindowLong(hwnd, GWL_EXSTYLE);
558 if (style & WS_EX_NOACTIVATE) {
559 nCmdShow = SW_SHOWNOACTIVATE;
561 ShowWindow(hwnd, nCmdShow);
568 ShowWindow(hwnd, SW_HIDE);
575 SetForegroundWindow(hwnd);
584 ShowWindow(hwnd, SW_MAXIMIZE);
592 ShowWindow(hwnd, SW_MINIMIZE);
602 style = GetWindowLong(hwnd, GWL_STYLE);
603 style &= ~STYLE_MASK;
604 style |= GetWindowStyle(
window);
607 SetWindowLong(hwnd, GWL_STYLE, style);
608 WIN_SetWindowPositionInternal(
_this,
window, SWP_NOCOPYBITS | SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOACTIVATE);
619 style = GetWindowLong(hwnd, GWL_STYLE);
620 style &= ~STYLE_MASK;
621 style |= GetWindowStyle(
window);
623 SetWindowLong(hwnd, GWL_STYLE, style);
632 ShowWindow(hwnd, SW_RESTORE);
650 top = HWND_NOTOPMOST;
653 style = GetWindowLong(hwnd, GWL_STYLE);
654 style &= ~STYLE_MASK;
655 style |= GetWindowStyle(
window);
668 if (style & WS_MAXIMIZE) {
670 style &= ~WS_MAXIMIZE;
681 if (
data->windowed_mode_was_maximized && !
data->in_window_deactivation) {
682 style |= WS_MAXIMIZE;
686 menu = (style & WS_CHILDWINDOW) ?
FALSE : (GetMenu(hwnd) !=
NULL);
689 SetWindowLong(hwnd, GWL_STYLE, style);
691 SetWindowPos(hwnd,
top,
x,
y,
w,
h, SWP_NOCOPYBITS | SWP_NOACTIVATE);
701 BOOL succeeded =
FALSE;
705 succeeded = SetDeviceGammaRamp(hdc, (LPVOID)ramp);
711 return succeeded ? 0 : -1;
720 BOOL succeeded =
FALSE;
724 succeeded = GetDeviceGammaRamp(hdc, (LPVOID)ramp);
730 return succeeded ? 0 : -1;
739 UINT
flags = SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOSIZE;
742 flags |= SWP_NOACTIVATE;
755 RemoveProp(
data->hwnd, TEXT(
"SDL_WindowData"));
757 DestroyWindow(
data->hwnd);
759 DestroyWindow(
data->parent);
765 SetWindowLongPtr(
data->hwnd, GWLP_WNDPROC,
766 (LONG_PTR)
data->wndproc);
768 SetWindowLong(
data->hwnd, GWL_WNDPROC,
769 (LONG_PTR)
data->wndproc);
793 info->
info.win.hinstance =
data->hinstance;
809 SDL_HelperWindowCreate(
void)
811 HINSTANCE hInstance = GetModuleHandle(
NULL);
815 if (SDL_HelperWindow !=
NULL) {
821 wce.lpfnWndProc = DefWindowProc;
822 wce.lpszClassName = (LPCWSTR) SDL_HelperWindowClassName;
823 wce.hInstance = hInstance;
826 SDL_HelperWindowClass = RegisterClass(&wce);
827 if (SDL_HelperWindowClass == 0 && GetLastError() != ERROR_CLASS_ALREADY_EXISTS) {
828 return WIN_SetError(
"Unable to create Helper Window Class");
832 SDL_HelperWindow = CreateWindowEx(0, SDL_HelperWindowClassName,
833 SDL_HelperWindowName,
834 WS_OVERLAPPED, CW_USEDEFAULT,
835 CW_USEDEFAULT, CW_USEDEFAULT,
836 CW_USEDEFAULT, HWND_MESSAGE,
NULL,
838 if (SDL_HelperWindow ==
NULL) {
839 UnregisterClass(SDL_HelperWindowClassName, hInstance);
851 SDL_HelperWindowDestroy(
void)
853 HINSTANCE hInstance = GetModuleHandle(
NULL);
856 if (SDL_HelperWindow !=
NULL) {
857 if (DestroyWindow(SDL_HelperWindow) == 0) {
861 SDL_HelperWindow =
NULL;
865 if (SDL_HelperWindowClass != 0) {
866 if ((UnregisterClass(SDL_HelperWindowClassName, hInstance)) == 0) {
870 SDL_HelperWindowClass = 0;
884 WIN_SetWindowPositionInternal(
_this,
window, SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOACTIVATE);
889 TRACKMOUSEEVENT trackMouseEvent;
891 trackMouseEvent.cbSize =
sizeof(TRACKMOUSEEVENT);
892 trackMouseEvent.dwFlags = TME_LEAVE;
893 trackMouseEvent.hwndTrack =
data->hwnd;
895 TrackMouseEvent(&trackMouseEvent);
907 if (
data->in_title_click ||
data->focus_click_pending) {
910 if (
data->skip_update_clipcursor) {
917 if (mouse->relative_mode && !mouse->relative_mode_warp) {
928 rect.bottom = cy + 1;
930 if (ClipCursor(&
rect)) {
934 if (GetClientRect(
data->hwnd, &
rect) && !IsRectEmpty(&
rect)) {
935 ClientToScreen(
data->hwnd, (LPPOINT) &
rect);
936 ClientToScreen(
data->hwnd, (LPPOINT) &
rect + 1);
937 if (ClipCursor(&
rect)) {
959 const LONG style = GetWindowLong(hwnd, GWL_EXSTYLE);
963 if (opacity == 1.0
f) {
965 if (style & WS_EX_LAYERED) {
966 if (SetWindowLong(hwnd, GWL_EXSTYLE, style & ~WS_EX_LAYERED) == 0) {
971 const BYTE
alpha = (BYTE) ((
int) (opacity * 255.0f));
973 if ((style & WS_EX_LAYERED) == 0) {
974 if (SetWindowLong(hwnd, GWL_EXSTYLE, style | WS_EX_LAYERED) == 0) {
979 if (SetLayeredWindowAttributes(hwnd, 0,
alpha, LWA_ALPHA) == 0) {