SDL_windowswindow.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #include "../../SDL_internal.h"
  19. #if SDL_VIDEO_DRIVER_WINDOWS
  20. #include "../../core/windows/SDL_windows.h"
  21. #include "../SDL_sysvideo.h"
  22. #include "../SDL_pixels_c.h"
  23. #include "../../events/SDL_keyboard_c.h"
  24. #include "../../events/SDL_mouse_c.h"
  25. #include "SDL_windowsvideo.h"
  26. #include "SDL_windowswindow.h"
  27. #include "SDL_hints.h"
  28. #include "SDL_timer.h"
  29. /* Dropfile support */
  30. #include <shellapi.h>
  31. /* This is included after SDL_windowsvideo.h, which includes windows.h */
  32. #include "SDL_syswm.h"
  33. /* Windows CE compatibility */
  34. #ifndef SWP_NOCOPYBITS
  35. #define SWP_NOCOPYBITS 0
  36. #endif
  37. /* Fake window to help with DirectInput events. */
  38. HWND SDL_HelperWindow = NULL;
  39. static const TCHAR *SDL_HelperWindowClassName = TEXT("SDLHelperWindowInputCatcher");
  40. static const TCHAR *SDL_HelperWindowName = TEXT("SDLHelperWindowInputMsgWindow");
  41. static ATOM SDL_HelperWindowClass = 0;
  42. /* For borderless Windows, still want the following flags:
  43. - WS_CAPTION: this seems to enable the Windows minimize animation
  44. - WS_SYSMENU: enables system context menu on task bar
  45. - WS_MINIMIZEBOX: window will respond to Windows minimize commands sent to all windows, such as windows key + m, shaking title bar, etc.
  46. This will also cause the task bar to overlap the window and other windowed behaviors, so only use this for windows that shouldn't appear to be fullscreen
  47. */
  48. #define STYLE_BASIC (WS_CLIPSIBLINGS | WS_CLIPCHILDREN)
  49. #define STYLE_FULLSCREEN (WS_POPUP)
  50. #define STYLE_BORDERLESS (WS_POPUP)
  51. #define STYLE_BORDERLESS_WINDOWED (WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX)
  52. #define STYLE_NORMAL (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX)
  53. #define STYLE_RESIZABLE (WS_THICKFRAME | WS_MAXIMIZEBOX)
  54. #define STYLE_MASK (STYLE_FULLSCREEN | STYLE_BORDERLESS | STYLE_NORMAL | STYLE_RESIZABLE)
  55. static DWORD
  56. GetWindowStyle(SDL_Window * window)
  57. {
  58. DWORD style = 0;
  59. if (window->flags & SDL_WINDOW_FULLSCREEN) {
  60. style |= STYLE_FULLSCREEN;
  61. } else {
  62. if (window->flags & SDL_WINDOW_BORDERLESS) {
  63. /* SDL 2.1:
  64. This behavior more closely matches other platform where the window is borderless
  65. but still interacts with the window manager (e.g. task bar shows above it, it can
  66. be resized to fit within usable desktop area, etc.) so this should be the behavior
  67. for a future SDL release.
  68. If you want a borderless window the size of the desktop that looks like a fullscreen
  69. window, then you should use the SDL_WINDOW_FULLSCREEN_DESKTOP flag.
  70. */
  71. if (SDL_GetHintBoolean("SDL_BORDERLESS_WINDOWED_STYLE", SDL_FALSE)) {
  72. style |= STYLE_BORDERLESS_WINDOWED;
  73. } else {
  74. style |= STYLE_BORDERLESS;
  75. }
  76. } else {
  77. style |= STYLE_NORMAL;
  78. }
  79. if (window->flags & SDL_WINDOW_RESIZABLE) {
  80. /* You can have a borderless resizable window, but Windows doesn't always draw it correctly,
  81. see https://bugzilla.libsdl.org/show_bug.cgi?id=4466
  82. */
  83. if (!(window->flags & SDL_WINDOW_BORDERLESS) ||
  84. SDL_GetHintBoolean("SDL_BORDERLESS_RESIZABLE_STYLE", SDL_FALSE)) {
  85. style |= STYLE_RESIZABLE;
  86. }
  87. }
  88. /* Need to set initialize minimize style, or when we call ShowWindow with WS_MINIMIZE it will activate a random window */
  89. if (window->flags & SDL_WINDOW_MINIMIZED) {
  90. style |= WS_MINIMIZE;
  91. }
  92. }
  93. return style;
  94. }
  95. static void
  96. WIN_AdjustWindowRectWithStyle(SDL_Window *window, DWORD style, BOOL menu, int *x, int *y, int *width, int *height, SDL_bool use_current)
  97. {
  98. RECT rect;
  99. rect.left = 0;
  100. rect.top = 0;
  101. rect.right = (use_current ? window->w : window->windowed.w);
  102. rect.bottom = (use_current ? window->h : window->windowed.h);
  103. /* borderless windows will have WM_NCCALCSIZE return 0 for the non-client area. When this happens, it looks like windows will send a resize message
  104. expanding the window client area to the previous window + chrome size, so shouldn't need to adjust the window size for the set styles.
  105. */
  106. if (!(window->flags & SDL_WINDOW_BORDERLESS))
  107. AdjustWindowRectEx(&rect, style, menu, 0);
  108. *x = (use_current ? window->x : window->windowed.x) + rect.left;
  109. *y = (use_current ? window->y : window->windowed.y) + rect.top;
  110. *width = (rect.right - rect.left);
  111. *height = (rect.bottom - rect.top);
  112. }
  113. static void
  114. WIN_AdjustWindowRect(SDL_Window *window, int *x, int *y, int *width, int *height, SDL_bool use_current)
  115. {
  116. SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
  117. HWND hwnd = data->hwnd;
  118. DWORD style;
  119. BOOL menu;
  120. style = GetWindowLong(hwnd, GWL_STYLE);
  121. menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
  122. WIN_AdjustWindowRectWithStyle(window, style, menu, x, y, width, height, use_current);
  123. }
  124. static void
  125. WIN_SetWindowPositionInternal(_THIS, SDL_Window * window, UINT flags)
  126. {
  127. SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
  128. HWND hwnd = data->hwnd;
  129. HWND top;
  130. int x, y;
  131. int w, h;
  132. /* Figure out what the window area will be */
  133. if (SDL_ShouldAllowTopmost() && ((window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS)) == (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS) || (window->flags & SDL_WINDOW_ALWAYS_ON_TOP))) {
  134. top = HWND_TOPMOST;
  135. } else {
  136. top = HWND_NOTOPMOST;
  137. }
  138. WIN_AdjustWindowRect(window, &x, &y, &w, &h, SDL_TRUE);
  139. data->expected_resize = SDL_TRUE;
  140. SetWindowPos(hwnd, top, x, y, w, h, flags);
  141. data->expected_resize = SDL_FALSE;
  142. }
  143. static int
  144. SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, HWND parent, SDL_bool created)
  145. {
  146. SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
  147. SDL_WindowData *data;
  148. /* Allocate the window data */
  149. data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
  150. if (!data) {
  151. return SDL_OutOfMemory();
  152. }
  153. data->window = window;
  154. data->hwnd = hwnd;
  155. data->parent = parent;
  156. data->hdc = GetDC(hwnd);
  157. data->hinstance = (HINSTANCE) GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
  158. data->created = created;
  159. data->high_surrogate = 0;
  160. data->mouse_button_flags = 0;
  161. data->last_pointer_update = (LPARAM)-1;
  162. data->videodata = videodata;
  163. data->initializing = SDL_TRUE;
  164. window->driverdata = data;
  165. /* Associate the data with the window */
  166. if (!SetProp(hwnd, TEXT("SDL_WindowData"), data)) {
  167. ReleaseDC(hwnd, data->hdc);
  168. SDL_free(data);
  169. return WIN_SetError("SetProp() failed");
  170. }
  171. /* Set up the window proc function */
  172. #ifdef GWLP_WNDPROC
  173. data->wndproc = (WNDPROC) GetWindowLongPtr(hwnd, GWLP_WNDPROC);
  174. if (data->wndproc == WIN_WindowProc) {
  175. data->wndproc = NULL;
  176. } else {
  177. SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR) WIN_WindowProc);
  178. }
  179. #else
  180. data->wndproc = (WNDPROC) GetWindowLong(hwnd, GWL_WNDPROC);
  181. if (data->wndproc == WIN_WindowProc) {
  182. data->wndproc = NULL;
  183. } else {
  184. SetWindowLong(hwnd, GWL_WNDPROC, (LONG_PTR) WIN_WindowProc);
  185. }
  186. #endif
  187. /* Fill in the SDL window with the window data */
  188. {
  189. RECT rect;
  190. if (GetClientRect(hwnd, &rect)) {
  191. int w = rect.right;
  192. int h = rect.bottom;
  193. if ((window->windowed.w && window->windowed.w != w) || (window->windowed.h && window->windowed.h != h)) {
  194. /* We tried to create a window larger than the desktop and Windows didn't allow it. Override! */
  195. int x, y;
  196. /* Figure out what the window area will be */
  197. WIN_AdjustWindowRect(window, &x, &y, &w, &h, SDL_FALSE);
  198. SetWindowPos(hwnd, HWND_NOTOPMOST, x, y, w, h, SWP_NOCOPYBITS | SWP_NOZORDER | SWP_NOACTIVATE);
  199. } else {
  200. window->w = w;
  201. window->h = h;
  202. }
  203. }
  204. }
  205. {
  206. POINT point;
  207. point.x = 0;
  208. point.y = 0;
  209. if (ClientToScreen(hwnd, &point)) {
  210. window->x = point.x;
  211. window->y = point.y;
  212. }
  213. }
  214. {
  215. DWORD style = GetWindowLong(hwnd, GWL_STYLE);
  216. if (style & WS_VISIBLE) {
  217. window->flags |= SDL_WINDOW_SHOWN;
  218. } else {
  219. window->flags &= ~SDL_WINDOW_SHOWN;
  220. }
  221. if (style & WS_POPUP) {
  222. window->flags |= SDL_WINDOW_BORDERLESS;
  223. } else {
  224. window->flags &= ~SDL_WINDOW_BORDERLESS;
  225. }
  226. if (style & WS_THICKFRAME) {
  227. window->flags |= SDL_WINDOW_RESIZABLE;
  228. } else {
  229. window->flags &= ~SDL_WINDOW_RESIZABLE;
  230. }
  231. #ifdef WS_MAXIMIZE
  232. if (style & WS_MAXIMIZE) {
  233. window->flags |= SDL_WINDOW_MAXIMIZED;
  234. } else
  235. #endif
  236. {
  237. window->flags &= ~SDL_WINDOW_MAXIMIZED;
  238. }
  239. #ifdef WS_MINIMIZE
  240. if (style & WS_MINIMIZE) {
  241. window->flags |= SDL_WINDOW_MINIMIZED;
  242. } else
  243. #endif
  244. {
  245. window->flags &= ~SDL_WINDOW_MINIMIZED;
  246. }
  247. }
  248. if (GetFocus() == hwnd) {
  249. window->flags |= SDL_WINDOW_INPUT_FOCUS;
  250. SDL_SetKeyboardFocus(window);
  251. WIN_UpdateClipCursor(window);
  252. }
  253. /* Enable multi-touch */
  254. if (videodata->RegisterTouchWindow) {
  255. videodata->RegisterTouchWindow(hwnd, (TWF_FINETOUCH|TWF_WANTPALM));
  256. }
  257. data->initializing = SDL_FALSE;
  258. /* All done! */
  259. return 0;
  260. }
  261. int
  262. WIN_CreateWindow(_THIS, SDL_Window * window)
  263. {
  264. HWND hwnd, parent = NULL;
  265. DWORD style = STYLE_BASIC;
  266. int x, y;
  267. int w, h;
  268. if (window->flags & SDL_WINDOW_SKIP_TASKBAR) {
  269. parent = CreateWindow(SDL_Appname, TEXT(""), STYLE_BASIC, 0, 0, 32, 32, NULL, NULL, SDL_Instance, NULL);
  270. }
  271. style |= GetWindowStyle(window);
  272. /* Figure out what the window area will be */
  273. WIN_AdjustWindowRectWithStyle(window, style, FALSE, &x, &y, &w, &h, SDL_FALSE);
  274. hwnd =
  275. CreateWindow(SDL_Appname, TEXT(""), style, x, y, w, h, parent, NULL,
  276. SDL_Instance, NULL);
  277. if (!hwnd) {
  278. return WIN_SetError("Couldn't create window");
  279. }
  280. WIN_PumpEvents(_this);
  281. if (SetupWindowData(_this, window, hwnd, parent, SDL_TRUE) < 0) {
  282. DestroyWindow(hwnd);
  283. if (parent) {
  284. DestroyWindow(parent);
  285. }
  286. return -1;
  287. }
  288. /* Inform Windows of the frame change so we can respond to WM_NCCALCSIZE */
  289. SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
  290. if (window->flags & SDL_WINDOW_MINIMIZED) {
  291. ShowWindow(hwnd, SW_SHOWMINNOACTIVE);
  292. }
  293. if (!(window->flags & SDL_WINDOW_OPENGL)) {
  294. return 0;
  295. }
  296. /* The rest of this macro mess is for OpenGL or OpenGL ES windows */
  297. #if SDL_VIDEO_OPENGL_ES2
  298. if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES
  299. #if SDL_VIDEO_OPENGL_WGL
  300. && (!_this->gl_data || WIN_GL_UseEGL(_this))
  301. #endif /* SDL_VIDEO_OPENGL_WGL */
  302. ) {
  303. #if SDL_VIDEO_OPENGL_EGL
  304. if (WIN_GLES_SetupWindow(_this, window) < 0) {
  305. WIN_DestroyWindow(_this, window);
  306. return -1;
  307. }
  308. return 0;
  309. #else
  310. return SDL_SetError("Could not create GLES window surface (EGL support not configured)");
  311. #endif /* SDL_VIDEO_OPENGL_EGL */
  312. }
  313. #endif /* SDL_VIDEO_OPENGL_ES2 */
  314. #if SDL_VIDEO_OPENGL_WGL
  315. if (WIN_GL_SetupWindow(_this, window) < 0) {
  316. WIN_DestroyWindow(_this, window);
  317. return -1;
  318. }
  319. #else
  320. return SDL_SetError("Could not create GL window (WGL support not configured)");
  321. #endif
  322. return 0;
  323. }
  324. int
  325. WIN_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
  326. {
  327. HWND hwnd = (HWND) data;
  328. LPTSTR title;
  329. int titleLen;
  330. SDL_bool isstack;
  331. /* Query the title from the existing window */
  332. titleLen = GetWindowTextLength(hwnd);
  333. title = SDL_small_alloc(TCHAR, titleLen + 1, &isstack);
  334. if (title) {
  335. titleLen = GetWindowText(hwnd, title, titleLen + 1);
  336. } else {
  337. titleLen = 0;
  338. }
  339. if (titleLen > 0) {
  340. window->title = WIN_StringToUTF8(title);
  341. }
  342. if (title) {
  343. SDL_small_free(title, isstack);
  344. }
  345. if (SetupWindowData(_this, window, hwnd, GetParent(hwnd), SDL_FALSE) < 0) {
  346. return -1;
  347. }
  348. #if SDL_VIDEO_OPENGL_WGL
  349. {
  350. const char *hint = SDL_GetHint(SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT);
  351. if (hint) {
  352. /* This hint is a pointer (in string form) of the address of
  353. the window to share a pixel format with
  354. */
  355. SDL_Window *otherWindow = NULL;
  356. SDL_sscanf(hint, "%p", (void**)&otherWindow);
  357. /* Do some error checking on the pointer */
  358. if (otherWindow != NULL && otherWindow->magic == &_this->window_magic) {
  359. /* If the otherWindow has SDL_WINDOW_OPENGL set, set it for the new window as well */
  360. if (otherWindow->flags & SDL_WINDOW_OPENGL) {
  361. window->flags |= SDL_WINDOW_OPENGL;
  362. if (!WIN_GL_SetPixelFormatFrom(_this, otherWindow, window)) {
  363. return -1;
  364. }
  365. }
  366. }
  367. }
  368. }
  369. #endif
  370. return 0;
  371. }
  372. void
  373. WIN_SetWindowTitle(_THIS, SDL_Window * window)
  374. {
  375. HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
  376. LPTSTR title = WIN_UTF8ToString(window->title);
  377. SetWindowText(hwnd, title);
  378. SDL_free(title);
  379. }
  380. void
  381. WIN_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
  382. {
  383. HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
  384. HICON hicon = NULL;
  385. BYTE *icon_bmp;
  386. int icon_len, mask_len, y;
  387. SDL_RWops *dst;
  388. SDL_bool isstack;
  389. /* Create temporary buffer for ICONIMAGE structure */
  390. mask_len = (icon->h * (icon->w + 7)/8);
  391. icon_len = 40 + icon->h * icon->w * sizeof(Uint32) + mask_len;
  392. icon_bmp = SDL_small_alloc(BYTE, icon_len, &isstack);
  393. dst = SDL_RWFromMem(icon_bmp, icon_len);
  394. if (!dst) {
  395. SDL_small_free(icon_bmp, isstack);
  396. return;
  397. }
  398. /* Write the BITMAPINFO header */
  399. SDL_WriteLE32(dst, 40);
  400. SDL_WriteLE32(dst, icon->w);
  401. SDL_WriteLE32(dst, icon->h * 2);
  402. SDL_WriteLE16(dst, 1);
  403. SDL_WriteLE16(dst, 32);
  404. SDL_WriteLE32(dst, BI_RGB);
  405. SDL_WriteLE32(dst, icon->h * icon->w * sizeof(Uint32));
  406. SDL_WriteLE32(dst, 0);
  407. SDL_WriteLE32(dst, 0);
  408. SDL_WriteLE32(dst, 0);
  409. SDL_WriteLE32(dst, 0);
  410. /* Write the pixels upside down into the bitmap buffer */
  411. SDL_assert(icon->format->format == SDL_PIXELFORMAT_ARGB8888);
  412. y = icon->h;
  413. while (y--) {
  414. Uint8 *src = (Uint8 *) icon->pixels + y * icon->pitch;
  415. SDL_RWwrite(dst, src, icon->w * sizeof(Uint32), 1);
  416. }
  417. /* Write the mask */
  418. SDL_memset(icon_bmp + icon_len - mask_len, 0xFF, mask_len);
  419. hicon = CreateIconFromResource(icon_bmp, icon_len, TRUE, 0x00030000);
  420. SDL_RWclose(dst);
  421. SDL_small_free(icon_bmp, isstack);
  422. /* Set the icon for the window */
  423. SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);
  424. /* Set the icon in the task manager (should we do this?) */
  425. SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
  426. }
  427. void
  428. WIN_SetWindowPosition(_THIS, SDL_Window * window)
  429. {
  430. WIN_SetWindowPositionInternal(_this, window, SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOACTIVATE);
  431. }
  432. void
  433. WIN_SetWindowSize(_THIS, SDL_Window * window)
  434. {
  435. WIN_SetWindowPositionInternal(_this, window, SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOACTIVATE);
  436. }
  437. int
  438. WIN_GetWindowBordersSize(_THIS, SDL_Window * window, int *top, int *left, int *bottom, int *right)
  439. {
  440. HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
  441. RECT rcClient, rcWindow;
  442. POINT ptDiff;
  443. /* rcClient stores the size of the inner window, while rcWindow stores the outer size relative to the top-left
  444. * screen position; so the top/left values of rcClient are always {0,0} and bottom/right are {height,width} */
  445. GetClientRect(hwnd, &rcClient);
  446. GetWindowRect(hwnd, &rcWindow);
  447. /* convert the top/left values to make them relative to
  448. * the window; they will end up being slightly negative */
  449. ptDiff.y = rcWindow.top;
  450. ptDiff.x = rcWindow.left;
  451. ScreenToClient(hwnd, &ptDiff);
  452. rcWindow.top = ptDiff.y;
  453. rcWindow.left = ptDiff.x;
  454. /* convert the bottom/right values to make them relative to the window,
  455. * these will be slightly bigger than the inner width/height */
  456. ptDiff.y = rcWindow.bottom;
  457. ptDiff.x = rcWindow.right;
  458. ScreenToClient(hwnd, &ptDiff);
  459. rcWindow.bottom = ptDiff.y;
  460. rcWindow.right = ptDiff.x;
  461. /* Now that both the inner and outer rects use the same coordinate system we can substract them to get the border size.
  462. * Keep in mind that the top/left coordinates of rcWindow are negative because the border lies slightly before {0,0},
  463. * so switch them around because SDL2 wants them in positive. */
  464. *top = rcClient.top - rcWindow.top;
  465. *left = rcClient.left - rcWindow.left;
  466. *bottom = rcWindow.bottom - rcClient.bottom;
  467. *right = rcWindow.right - rcClient.right;
  468. return 0;
  469. }
  470. void
  471. WIN_ShowWindow(_THIS, SDL_Window * window)
  472. {
  473. DWORD style;
  474. HWND hwnd;
  475. int nCmdShow;
  476. hwnd = ((SDL_WindowData *)window->driverdata)->hwnd;
  477. nCmdShow = SDL_GetHintBoolean(SDL_HINT_WINDOW_NO_ACTIVATION_WHEN_SHOWN, SDL_FALSE) ? SW_SHOWNA : SW_SHOW;
  478. style = GetWindowLong(hwnd, GWL_EXSTYLE);
  479. if (style & WS_EX_NOACTIVATE) {
  480. nCmdShow = SW_SHOWNOACTIVATE;
  481. }
  482. ShowWindow(hwnd, nCmdShow);
  483. }
  484. void
  485. WIN_HideWindow(_THIS, SDL_Window * window)
  486. {
  487. HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
  488. ShowWindow(hwnd, SW_HIDE);
  489. }
  490. void
  491. WIN_RaiseWindow(_THIS, SDL_Window * window)
  492. {
  493. HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
  494. SetForegroundWindow(hwnd);
  495. }
  496. void
  497. WIN_MaximizeWindow(_THIS, SDL_Window * window)
  498. {
  499. SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
  500. HWND hwnd = data->hwnd;
  501. data->expected_resize = SDL_TRUE;
  502. ShowWindow(hwnd, SW_MAXIMIZE);
  503. data->expected_resize = SDL_FALSE;
  504. }
  505. void
  506. WIN_MinimizeWindow(_THIS, SDL_Window * window)
  507. {
  508. HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
  509. ShowWindow(hwnd, SW_MINIMIZE);
  510. }
  511. void
  512. WIN_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
  513. {
  514. SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
  515. HWND hwnd = data->hwnd;
  516. DWORD style;
  517. style = GetWindowLong(hwnd, GWL_STYLE);
  518. style &= ~STYLE_MASK;
  519. style |= GetWindowStyle(window);
  520. data->in_border_change = SDL_TRUE;
  521. SetWindowLong(hwnd, GWL_STYLE, style);
  522. WIN_SetWindowPositionInternal(_this, window, SWP_NOCOPYBITS | SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOACTIVATE);
  523. data->in_border_change = SDL_FALSE;
  524. }
  525. void
  526. WIN_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable)
  527. {
  528. SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
  529. HWND hwnd = data->hwnd;
  530. DWORD style;
  531. style = GetWindowLong(hwnd, GWL_STYLE);
  532. style &= ~STYLE_MASK;
  533. style |= GetWindowStyle(window);
  534. SetWindowLong(hwnd, GWL_STYLE, style);
  535. }
  536. void
  537. WIN_SetWindowAlwaysOnTop(_THIS, SDL_Window * window, SDL_bool on_top)
  538. {
  539. SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
  540. HWND hwnd = data->hwnd;
  541. if (on_top) {
  542. SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
  543. } else {
  544. SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
  545. }
  546. }
  547. void
  548. WIN_RestoreWindow(_THIS, SDL_Window * window)
  549. {
  550. SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
  551. HWND hwnd = data->hwnd;
  552. data->expected_resize = SDL_TRUE;
  553. ShowWindow(hwnd, SW_RESTORE);
  554. data->expected_resize = SDL_FALSE;
  555. }
  556. void
  557. WIN_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
  558. {
  559. SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
  560. HWND hwnd = data->hwnd;
  561. SDL_Rect bounds;
  562. DWORD style;
  563. HWND top;
  564. int x, y;
  565. int w, h;
  566. if (SDL_ShouldAllowTopmost() && ((window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS)) == (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS) || window->flags & SDL_WINDOW_ALWAYS_ON_TOP)) {
  567. top = HWND_TOPMOST;
  568. } else {
  569. top = HWND_NOTOPMOST;
  570. }
  571. style = GetWindowLong(hwnd, GWL_STYLE);
  572. style &= ~STYLE_MASK;
  573. style |= GetWindowStyle(window);
  574. WIN_GetDisplayBounds(_this, display, &bounds);
  575. if (fullscreen) {
  576. x = bounds.x;
  577. y = bounds.y;
  578. w = bounds.w;
  579. h = bounds.h;
  580. /* Unset the maximized flag. This fixes
  581. https://bugzilla.libsdl.org/show_bug.cgi?id=3215
  582. */
  583. if (style & WS_MAXIMIZE) {
  584. data->windowed_mode_was_maximized = SDL_TRUE;
  585. style &= ~WS_MAXIMIZE;
  586. }
  587. } else {
  588. BOOL menu;
  589. /* Restore window-maximization state, as applicable.
  590. Special care is taken to *not* do this if and when we're
  591. alt-tab'ing away (to some other window; as indicated by
  592. in_window_deactivation), otherwise
  593. https://bugzilla.libsdl.org/show_bug.cgi?id=3215 can reproduce!
  594. */
  595. if (data->windowed_mode_was_maximized && !data->in_window_deactivation) {
  596. style |= WS_MAXIMIZE;
  597. data->windowed_mode_was_maximized = SDL_FALSE;
  598. }
  599. menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
  600. WIN_AdjustWindowRectWithStyle(window, style, menu, &x, &y, &w, &h, SDL_FALSE);
  601. }
  602. SetWindowLong(hwnd, GWL_STYLE, style);
  603. data->expected_resize = SDL_TRUE;
  604. SetWindowPos(hwnd, top, x, y, w, h, SWP_NOCOPYBITS | SWP_NOACTIVATE);
  605. data->expected_resize = SDL_FALSE;
  606. }
  607. int
  608. WIN_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp)
  609. {
  610. SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
  611. SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
  612. HDC hdc;
  613. BOOL succeeded = FALSE;
  614. hdc = CreateDCW(data->DeviceName, NULL, NULL, NULL);
  615. if (hdc) {
  616. succeeded = SetDeviceGammaRamp(hdc, (LPVOID)ramp);
  617. if (!succeeded) {
  618. WIN_SetError("SetDeviceGammaRamp()");
  619. }
  620. DeleteDC(hdc);
  621. }
  622. return succeeded ? 0 : -1;
  623. }
  624. void*
  625. WIN_GetWindowICCProfile(_THIS, SDL_Window * window, size_t * size)
  626. {
  627. SDL_VideoDisplay* display = SDL_GetDisplayForWindow(window);
  628. SDL_DisplayData* data = (SDL_DisplayData*)display->driverdata;
  629. HDC hdc;
  630. BOOL succeeded = FALSE;
  631. WCHAR filename[MAX_PATH];
  632. DWORD fileNameSize = MAX_PATH;
  633. void* iccProfileData = NULL;
  634. hdc = CreateDCW(data->DeviceName, NULL, NULL, NULL);
  635. if (hdc) {
  636. succeeded = GetICMProfileW(hdc, &fileNameSize, filename);
  637. DeleteDC(hdc);
  638. }
  639. if (succeeded) {
  640. iccProfileData = SDL_LoadFile(WIN_StringToUTF8(filename), size);
  641. if (!iccProfileData)
  642. SDL_SetError("Could not open ICC profile");
  643. }
  644. return iccProfileData;
  645. }
  646. int
  647. WIN_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp)
  648. {
  649. SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
  650. SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
  651. HDC hdc;
  652. BOOL succeeded = FALSE;
  653. hdc = CreateDCW(data->DeviceName, NULL, NULL, NULL);
  654. if (hdc) {
  655. succeeded = GetDeviceGammaRamp(hdc, (LPVOID)ramp);
  656. if (!succeeded) {
  657. WIN_SetError("GetDeviceGammaRamp()");
  658. }
  659. DeleteDC(hdc);
  660. }
  661. return succeeded ? 0 : -1;
  662. }
  663. static void WIN_GrabKeyboard(SDL_Window *window)
  664. {
  665. SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
  666. HMODULE module;
  667. if (data->keyboard_hook) {
  668. return;
  669. }
  670. /* SetWindowsHookEx() needs to know which module contains the hook we
  671. want to install. This is complicated by the fact that SDL can be
  672. linked statically or dynamically. Fortunately XP and later provide
  673. this nice API that will go through the loaded modules and find the
  674. one containing our code.
  675. */
  676. if (!GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT | GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
  677. (LPTSTR)WIN_KeyboardHookProc,
  678. &module)) {
  679. return;
  680. }
  681. /* Capture a snapshot of the current keyboard state before the hook */
  682. if (!GetKeyboardState(data->videodata->pre_hook_key_state)) {
  683. return;
  684. }
  685. /* To grab the keyboard, we have to install a low-level keyboard hook to
  686. intercept keys that would normally be captured by the OS. Intercepting
  687. all key events on the system is rather invasive, but it's what Microsoft
  688. actually documents that you do to capture these.
  689. */
  690. data->keyboard_hook = SetWindowsHookEx(WH_KEYBOARD_LL, WIN_KeyboardHookProc, module, 0);
  691. }
  692. void WIN_UngrabKeyboard(SDL_Window *window)
  693. {
  694. SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
  695. if (data->keyboard_hook) {
  696. UnhookWindowsHookEx(data->keyboard_hook);
  697. data->keyboard_hook = NULL;
  698. }
  699. }
  700. void
  701. WIN_SetWindowMouseRect(_THIS, SDL_Window * window)
  702. {
  703. WIN_UpdateClipCursor(window);
  704. }
  705. void
  706. WIN_SetWindowMouseGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
  707. {
  708. WIN_UpdateClipCursor(window);
  709. if (window->flags & SDL_WINDOW_FULLSCREEN) {
  710. UINT flags = SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOSIZE;
  711. if (!(window->flags & SDL_WINDOW_SHOWN)) {
  712. flags |= SWP_NOACTIVATE;
  713. }
  714. WIN_SetWindowPositionInternal(_this, window, flags);
  715. }
  716. }
  717. void
  718. WIN_SetWindowKeyboardGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
  719. {
  720. if (grabbed) {
  721. WIN_GrabKeyboard(window);
  722. } else {
  723. WIN_UngrabKeyboard(window);
  724. }
  725. }
  726. void
  727. WIN_DestroyWindow(_THIS, SDL_Window * window)
  728. {
  729. SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
  730. if (data) {
  731. if (data->keyboard_hook) {
  732. UnhookWindowsHookEx(data->keyboard_hook);
  733. }
  734. ReleaseDC(data->hwnd, data->hdc);
  735. RemoveProp(data->hwnd, TEXT("SDL_WindowData"));
  736. if (data->created) {
  737. DestroyWindow(data->hwnd);
  738. if (data->parent) {
  739. DestroyWindow(data->parent);
  740. }
  741. } else {
  742. /* Restore any original event handler... */
  743. if (data->wndproc != NULL) {
  744. #ifdef GWLP_WNDPROC
  745. SetWindowLongPtr(data->hwnd, GWLP_WNDPROC,
  746. (LONG_PTR) data->wndproc);
  747. #else
  748. SetWindowLong(data->hwnd, GWL_WNDPROC,
  749. (LONG_PTR) data->wndproc);
  750. #endif
  751. }
  752. }
  753. SDL_free(data);
  754. }
  755. window->driverdata = NULL;
  756. }
  757. SDL_bool
  758. WIN_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
  759. {
  760. const SDL_WindowData *data = (const SDL_WindowData *) window->driverdata;
  761. if (info->version.major <= SDL_MAJOR_VERSION) {
  762. int versionnum = SDL_VERSIONNUM(info->version.major, info->version.minor, info->version.patch);
  763. info->subsystem = SDL_SYSWM_WINDOWS;
  764. info->info.win.window = data->hwnd;
  765. if (versionnum >= SDL_VERSIONNUM(2, 0, 4)) {
  766. info->info.win.hdc = data->hdc;
  767. }
  768. if (versionnum >= SDL_VERSIONNUM(2, 0, 5)) {
  769. info->info.win.hinstance = data->hinstance;
  770. }
  771. return SDL_TRUE;
  772. } else {
  773. SDL_SetError("Application not compiled with SDL %d.%d",
  774. SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
  775. return SDL_FALSE;
  776. }
  777. }
  778. /*
  779. * Creates a HelperWindow used for DirectInput.
  780. */
  781. int
  782. SDL_HelperWindowCreate(void)
  783. {
  784. HINSTANCE hInstance = GetModuleHandle(NULL);
  785. WNDCLASS wce;
  786. /* Make sure window isn't created twice. */
  787. if (SDL_HelperWindow != NULL) {
  788. return 0;
  789. }
  790. /* Create the class. */
  791. SDL_zero(wce);
  792. wce.lpfnWndProc = DefWindowProc;
  793. wce.lpszClassName = SDL_HelperWindowClassName;
  794. wce.hInstance = hInstance;
  795. /* Register the class. */
  796. SDL_HelperWindowClass = RegisterClass(&wce);
  797. if (SDL_HelperWindowClass == 0 && GetLastError() != ERROR_CLASS_ALREADY_EXISTS) {
  798. return WIN_SetError("Unable to create Helper Window Class");
  799. }
  800. /* Create the window. */
  801. SDL_HelperWindow = CreateWindowEx(0, SDL_HelperWindowClassName,
  802. SDL_HelperWindowName,
  803. WS_OVERLAPPED, CW_USEDEFAULT,
  804. CW_USEDEFAULT, CW_USEDEFAULT,
  805. CW_USEDEFAULT, HWND_MESSAGE, NULL,
  806. hInstance, NULL);
  807. if (SDL_HelperWindow == NULL) {
  808. UnregisterClass(SDL_HelperWindowClassName, hInstance);
  809. return WIN_SetError("Unable to create Helper Window");
  810. }
  811. return 0;
  812. }
  813. /*
  814. * Destroys the HelperWindow previously created with SDL_HelperWindowCreate.
  815. */
  816. void
  817. SDL_HelperWindowDestroy(void)
  818. {
  819. HINSTANCE hInstance = GetModuleHandle(NULL);
  820. /* Destroy the window. */
  821. if (SDL_HelperWindow != NULL) {
  822. if (DestroyWindow(SDL_HelperWindow) == 0) {
  823. WIN_SetError("Unable to destroy Helper Window");
  824. return;
  825. }
  826. SDL_HelperWindow = NULL;
  827. }
  828. /* Unregister the class. */
  829. if (SDL_HelperWindowClass != 0) {
  830. if ((UnregisterClass(SDL_HelperWindowClassName, hInstance)) == 0) {
  831. WIN_SetError("Unable to destroy Helper Window Class");
  832. return;
  833. }
  834. SDL_HelperWindowClass = 0;
  835. }
  836. }
  837. void WIN_OnWindowEnter(_THIS, SDL_Window * window)
  838. {
  839. SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
  840. if (!data || !data->hwnd) {
  841. /* The window wasn't fully initialized */
  842. return;
  843. }
  844. if (window->flags & SDL_WINDOW_ALWAYS_ON_TOP) {
  845. WIN_SetWindowPositionInternal(_this, window, SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOACTIVATE);
  846. }
  847. }
  848. void
  849. WIN_UpdateClipCursor(SDL_Window *window)
  850. {
  851. SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
  852. SDL_Mouse *mouse = SDL_GetMouse();
  853. RECT rect, clipped_rect;
  854. if (data->in_title_click || data->focus_click_pending) {
  855. return;
  856. }
  857. if (data->skip_update_clipcursor) {
  858. return;
  859. }
  860. if (!GetClipCursor(&clipped_rect)) {
  861. return;
  862. }
  863. if ((mouse->relative_mode || (window->flags & SDL_WINDOW_MOUSE_GRABBED) ||
  864. (window->mouse_rect.w > 0 && window->mouse_rect.h > 0)) &&
  865. (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
  866. if (mouse->relative_mode && !mouse->relative_mode_warp) {
  867. if (GetWindowRect(data->hwnd, &rect)) {
  868. LONG cx, cy;
  869. cx = (rect.left + rect.right) / 2;
  870. cy = (rect.top + rect.bottom) / 2;
  871. /* Make an absurdly small clip rect */
  872. rect.left = cx - 1;
  873. rect.right = cx + 1;
  874. rect.top = cy - 1;
  875. rect.bottom = cy + 1;
  876. if (SDL_memcmp(&rect, &clipped_rect, sizeof(rect)) != 0) {
  877. if (ClipCursor(&rect)) {
  878. data->cursor_clipped_rect = rect;
  879. }
  880. }
  881. }
  882. } else {
  883. if (GetClientRect(data->hwnd, &rect)) {
  884. ClientToScreen(data->hwnd, (LPPOINT) & rect);
  885. ClientToScreen(data->hwnd, (LPPOINT) & rect + 1);
  886. if (window->mouse_rect.w > 0 && window->mouse_rect.h > 0) {
  887. RECT mouse_rect, intersection;
  888. mouse_rect.left = rect.left + data->mouse_rect.x;
  889. mouse_rect.top = rect.top + data->mouse_rect.y;
  890. mouse_rect.right = mouse_rect.left + data->mouse_rect.w - 1;
  891. mouse_rect.bottom = mouse_rect.top + data->mouse_rect.h - 1;
  892. if (IntersectRect(&intersection, &rect, &mouse_rect)) {
  893. SDL_memcpy(&rect, &intersection, sizeof(rect));
  894. } else if ((window->flags & SDL_WINDOW_MOUSE_GRABBED) != 0) {
  895. /* Mouse rect was invalid, just do the normal grab */
  896. } else {
  897. SDL_zero(rect);
  898. }
  899. }
  900. if (SDL_memcmp(&rect, &clipped_rect, sizeof(rect)) != 0) {
  901. if (!IsRectEmpty(&rect)) {
  902. if (ClipCursor(&rect)) {
  903. data->cursor_clipped_rect = rect;
  904. }
  905. } else {
  906. ClipCursor(NULL);
  907. SDL_zero(data->cursor_clipped_rect);
  908. }
  909. }
  910. }
  911. }
  912. } else {
  913. POINT first, second;
  914. first.x = clipped_rect.left;
  915. first.y = clipped_rect.top;
  916. second.x = clipped_rect.right - 1;
  917. second.y = clipped_rect.bottom - 1;
  918. if (PtInRect(&data->cursor_clipped_rect, first) &&
  919. PtInRect(&data->cursor_clipped_rect, second)) {
  920. ClipCursor(NULL);
  921. SDL_zero(data->cursor_clipped_rect);
  922. }
  923. }
  924. data->last_updated_clipcursor = SDL_GetTicks();
  925. }
  926. int
  927. WIN_SetWindowHitTest(SDL_Window *window, SDL_bool enabled)
  928. {
  929. return 0; /* just succeed, the real work is done elsewhere. */
  930. }
  931. int
  932. WIN_SetWindowOpacity(_THIS, SDL_Window * window, float opacity)
  933. {
  934. const SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
  935. const HWND hwnd = data->hwnd;
  936. const LONG style = GetWindowLong(hwnd, GWL_EXSTYLE);
  937. SDL_assert(style != 0);
  938. if (opacity == 1.0f) {
  939. /* want it fully opaque, just mark it unlayered if necessary. */
  940. if (style & WS_EX_LAYERED) {
  941. if (SetWindowLong(hwnd, GWL_EXSTYLE, style & ~WS_EX_LAYERED) == 0) {
  942. return WIN_SetError("SetWindowLong()");
  943. }
  944. }
  945. } else {
  946. const BYTE alpha = (BYTE) ((int) (opacity * 255.0f));
  947. /* want it transparent, mark it layered if necessary. */
  948. if ((style & WS_EX_LAYERED) == 0) {
  949. if (SetWindowLong(hwnd, GWL_EXSTYLE, style | WS_EX_LAYERED) == 0) {
  950. return WIN_SetError("SetWindowLong()");
  951. }
  952. }
  953. if (SetLayeredWindowAttributes(hwnd, 0, alpha, LWA_ALPHA) == 0) {
  954. return WIN_SetError("SetLayeredWindowAttributes()");
  955. }
  956. }
  957. return 0;
  958. }
  959. void
  960. WIN_AcceptDragAndDrop(SDL_Window * window, SDL_bool accept)
  961. {
  962. const SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
  963. DragAcceptFiles(data->hwnd, accept ? TRUE : FALSE);
  964. }
  965. int
  966. WIN_FlashWindow(_THIS, SDL_Window * window, SDL_FlashOperation operation)
  967. {
  968. FLASHWINFO desc;
  969. SDL_zero(desc);
  970. desc.cbSize = sizeof(desc);
  971. desc.hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
  972. switch (operation) {
  973. case SDL_FLASH_CANCEL:
  974. desc.dwFlags = FLASHW_STOP;
  975. break;
  976. case SDL_FLASH_BRIEFLY:
  977. desc.dwFlags = FLASHW_TRAY;
  978. desc.uCount = 1;
  979. break;
  980. case SDL_FLASH_UNTIL_FOCUSED:
  981. desc.dwFlags = (FLASHW_TRAY | FLASHW_TIMERNOFG);
  982. break;
  983. default:
  984. return SDL_Unsupported();
  985. }
  986. FlashWindowEx(&desc);
  987. return 0;
  988. }
  989. #endif /* SDL_VIDEO_DRIVER_WINDOWS */
  990. /* vi: set ts=4 sw=4 expandtab: */