Advertisement
asarium

Untitled

Dec 1st, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.95 KB | None | 0 0
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
  4.  
  5. This software is provided 'as-is', without any express or implied
  6. warranty. In no event will the authors be held liable for any damages
  7. arising from the use of this software.
  8.  
  9. Permission is granted to anyone to use this software for any purpose,
  10. including commercial applications, and to alter it and redistribute it
  11. freely, subject to the following restrictions:
  12.  
  13. 1. The origin of this software must not be misrepresented; you must not
  14. claim that you wrote the original software. If you use this software
  15. in a product, an acknowledgment in the product documentation would be
  16. appreciated but is not required.
  17. 2. Altered source versions must be plainly marked as such, and must not be
  18. misrepresented as being the original software.
  19. 3. This notice may not be removed or altered from any source distribution.
  20. */
  21. #include "SDL_config.h"
  22.  
  23. #if SDL_VIDEO_DRIVER_WINDOWS
  24.  
  25. #include "../../core/windows/SDL_windows.h"
  26.  
  27. #include "SDL_assert.h"
  28. #include "../SDL_sysvideo.h"
  29. #include "../SDL_pixels_c.h"
  30. #include "../../events/SDL_keyboard_c.h"
  31.  
  32. #include "SDL_windowsvideo.h"
  33. #include "SDL_windowswindow.h"
  34.  
  35. /* Dropfile support */
  36. #include <shellapi.h>
  37.  
  38. /* This is included after SDL_windowsvideo.h, which includes windows.h */
  39. #include "SDL_syswm.h"
  40.  
  41. /* Windows CE compatibility */
  42. #ifndef SWP_NOCOPYBITS
  43. #define SWP_NOCOPYBITS 0
  44. #endif
  45.  
  46. /* Fake window to help with DirectInput events. */
  47. HWND SDL_HelperWindow = NULL;
  48. static WCHAR *SDL_HelperWindowClassName = TEXT("SDLHelperWindowInputCatcher");
  49. static WCHAR *SDL_HelperWindowName = TEXT("SDLHelperWindowInputMsgWindow");
  50. static ATOM SDL_HelperWindowClass = 0;
  51.  
  52. #define STYLE_BASIC (WS_CLIPSIBLINGS | WS_CLIPCHILDREN)
  53. #define STYLE_FULLSCREEN (WS_POPUP)
  54. #define STYLE_BORDERLESS (WS_POPUP)
  55. #define STYLE_NORMAL (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX)
  56. #define STYLE_RESIZABLE (WS_THICKFRAME | WS_MAXIMIZEBOX)
  57. #define STYLE_MASK (STYLE_FULLSCREEN | STYLE_BORDERLESS | STYLE_NORMAL | STYLE_RESIZABLE)
  58.  
  59. static DWORD
  60. GetWindowStyle(SDL_Window * window)
  61. {
  62. DWORD style = 0;
  63.  
  64. if (window->flags & SDL_WINDOW_FULLSCREEN) {
  65. style |= STYLE_FULLSCREEN;
  66. } else {
  67. if (window->flags & SDL_WINDOW_BORDERLESS) {
  68. style |= STYLE_BORDERLESS;
  69. } else {
  70. style |= STYLE_NORMAL;
  71. }
  72. if (window->flags & SDL_WINDOW_RESIZABLE) {
  73. style |= STYLE_RESIZABLE;
  74. }
  75. }
  76. return style;
  77. }
  78.  
  79. static void
  80. WIN_SetWindowPositionInternal(_THIS, SDL_Window * window, UINT flags)
  81. {
  82. HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
  83. RECT rect;
  84. DWORD style;
  85. HWND top;
  86. BOOL menu;
  87. int x, y;
  88. int w, h;
  89.  
  90. /* Figure out what the window area will be */
  91. if (SDL_ShouldAllowTopmost() && (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS)) == (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS)) {
  92. top = HWND_TOPMOST;
  93. } else {
  94. top = HWND_NOTOPMOST;
  95. }
  96. style = GetWindowLong(hwnd, GWL_STYLE);
  97. rect.left = 0;
  98. rect.top = 0;
  99. rect.right = window->w;
  100. rect.bottom = window->h;
  101. menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
  102. AdjustWindowRectEx(&rect, style, menu, 0);
  103. w = (rect.right - rect.left);
  104. h = (rect.bottom - rect.top);
  105. x = window->x + rect.left;
  106. y = window->y + rect.top;
  107.  
  108. SetWindowPos(hwnd, top, x, y, w, h, flags);
  109. }
  110.  
  111. static int
  112. SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created)
  113. {
  114. SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
  115. SDL_WindowData *data;
  116.  
  117. /* Allocate the window data */
  118. data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
  119. if (!data) {
  120. return SDL_OutOfMemory();
  121. }
  122. data->window = window;
  123. data->hwnd = hwnd;
  124. data->hdc = GetDC(hwnd);
  125. data->created = created;
  126. data->mouse_button_flags = 0;
  127. data->videodata = videodata;
  128.  
  129. window->driverdata = data;
  130.  
  131. /* Associate the data with the window */
  132. if (!SetProp(hwnd, TEXT("SDL_WindowData"), data)) {
  133. ReleaseDC(hwnd, data->hdc);
  134. SDL_free(data);
  135. return WIN_SetError("SetProp() failed");
  136. }
  137.  
  138. /* Set up the window proc function */
  139. #ifdef GWLP_WNDPROC
  140. data->wndproc = (WNDPROC) GetWindowLongPtr(hwnd, GWLP_WNDPROC);
  141. if (data->wndproc == WIN_WindowProc) {
  142. data->wndproc = NULL;
  143. } else {
  144. SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR) WIN_WindowProc);
  145. }
  146. #else
  147. data->wndproc = (WNDPROC) GetWindowLong(hwnd, GWL_WNDPROC);
  148. if (data->wndproc == WIN_WindowProc) {
  149. data->wndproc = NULL;
  150. } else {
  151. SetWindowLong(hwnd, GWL_WNDPROC, (LONG_PTR) WIN_WindowProc);
  152. }
  153. #endif
  154.  
  155. /* Fill in the SDL window with the window data */
  156. {
  157. RECT rect;
  158. if (GetClientRect(hwnd, &rect)) {
  159. int w = rect.right;
  160. int h = rect.bottom;
  161. if ((window->w && window->w != w) || (window->h && window->h != h)) {
  162. /* We tried to create a window larger than the desktop and Windows didn't allow it. Override! */
  163. WIN_SetWindowPositionInternal(_this, window, SWP_NOCOPYBITS | SWP_NOZORDER | SWP_NOACTIVATE);
  164. } else {
  165. window->w = w;
  166. window->h = h;
  167. }
  168. }
  169. }
  170. {
  171. POINT point;
  172. point.x = 0;
  173. point.y = 0;
  174. if (ClientToScreen(hwnd, &point)) {
  175. window->x = point.x;
  176. window->y = point.y;
  177. }
  178. }
  179. {
  180. DWORD style = GetWindowLong(hwnd, GWL_STYLE);
  181. if (style & WS_VISIBLE) {
  182. window->flags |= SDL_WINDOW_SHOWN;
  183. } else {
  184. window->flags &= ~SDL_WINDOW_SHOWN;
  185. }
  186. if (style & (WS_BORDER | WS_THICKFRAME)) {
  187. window->flags &= ~SDL_WINDOW_BORDERLESS;
  188. } else {
  189. window->flags |= SDL_WINDOW_BORDERLESS;
  190. }
  191. if (style & WS_THICKFRAME) {
  192. window->flags |= SDL_WINDOW_RESIZABLE;
  193. } else {
  194. window->flags &= ~SDL_WINDOW_RESIZABLE;
  195. }
  196. #ifdef WS_MAXIMIZE
  197. if (style & WS_MAXIMIZE) {
  198. window->flags |= SDL_WINDOW_MAXIMIZED;
  199. } else
  200. #endif
  201. {
  202. window->flags &= ~SDL_WINDOW_MAXIMIZED;
  203. }
  204. #ifdef WS_MINIMIZE
  205. if (style & WS_MINIMIZE) {
  206. window->flags |= SDL_WINDOW_MINIMIZED;
  207. } else
  208. #endif
  209. {
  210. window->flags &= ~SDL_WINDOW_MINIMIZED;
  211. }
  212. }
  213. if (GetFocus() == hwnd) {
  214. window->flags |= SDL_WINDOW_INPUT_FOCUS;
  215. SDL_SetKeyboardFocus(data->window);
  216.  
  217. if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
  218. RECT rect;
  219. GetClientRect(hwnd, &rect);
  220. ClientToScreen(hwnd, (LPPOINT) & rect);
  221. ClientToScreen(hwnd, (LPPOINT) & rect + 1);
  222. ClipCursor(&rect);
  223. }
  224. }
  225.  
  226. /* Enable multi-touch */
  227. if (videodata->RegisterTouchWindow) {
  228. videodata->RegisterTouchWindow(hwnd, (TWF_FINETOUCH|TWF_WANTPALM));
  229. }
  230.  
  231. /* Enable dropping files */
  232. DragAcceptFiles(hwnd, TRUE);
  233.  
  234. /* All done! */
  235. return 0;
  236. }
  237.  
  238. int
  239. WIN_CreateWindow(_THIS, SDL_Window * window)
  240. {
  241. HWND hwnd;
  242. RECT rect;
  243. DWORD style = STYLE_BASIC;
  244. int x, y;
  245. int w, h;
  246.  
  247. style |= GetWindowStyle(window);
  248.  
  249. /* Figure out what the window area will be */
  250. rect.left = window->x;
  251. rect.top = window->y;
  252. rect.right = window->x + window->w;
  253. rect.bottom = window->y + window->h;
  254. AdjustWindowRectEx(&rect, style, FALSE, 0);
  255. x = rect.left;
  256. y = rect.top;
  257. w = (rect.right - rect.left);
  258. h = (rect.bottom - rect.top);
  259.  
  260. hwnd =
  261. CreateWindow(SDL_Appname, TEXT(""), style, x, y, w, h, NULL, NULL,
  262. SDL_Instance, NULL);
  263. if (!hwnd) {
  264. return WIN_SetError("Couldn't create window");
  265. }
  266.  
  267. WIN_PumpEvents(_this);
  268.  
  269. if (SetupWindowData(_this, window, hwnd, SDL_TRUE) < 0) {
  270. DestroyWindow(hwnd);
  271. return -1;
  272. }
  273. #if SDL_VIDEO_OPENGL_WGL
  274. if (window->flags & SDL_WINDOW_OPENGL) {
  275. if (WIN_GL_SetupWindow(_this, window) < 0) {
  276. WIN_DestroyWindow(_this, window);
  277. return -1;
  278. }
  279. }
  280. #endif
  281. return 0;
  282. }
  283.  
  284. int
  285. WIN_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
  286. {
  287. HWND hwnd = (HWND) data;
  288. LPTSTR title;
  289. int titleLen;
  290.  
  291. window->flags |= SDL_WINDOW_OPENGL;
  292.  
  293. /* Query the title from the existing window */
  294. titleLen = GetWindowTextLength(hwnd);
  295. title = SDL_stack_alloc(TCHAR, titleLen + 1);
  296. if (title) {
  297. titleLen = GetWindowText(hwnd, title, titleLen);
  298. } else {
  299. titleLen = 0;
  300. }
  301. if (titleLen > 0) {
  302. window->title = WIN_StringToUTF8(title);
  303. }
  304. if (title) {
  305. SDL_stack_free(title);
  306. }
  307.  
  308. if (SetupWindowData(_this, window, hwnd, SDL_FALSE) < 0) {
  309. return -1;
  310. }
  311.  
  312. #if SDL_VIDEO_OPENGL_WGL
  313. if (window->flags & SDL_WINDOW_OPENGL) {
  314. if (WIN_GL_SetupWindow(_this, window) < 0) {
  315. WIN_DestroyWindow(_this, window);
  316. return -1;
  317. }
  318. }
  319. #endif
  320.  
  321. return 0;
  322. }
  323.  
  324. void
  325. WIN_SetWindowTitle(_THIS, SDL_Window * window)
  326. {
  327. HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
  328. LPTSTR title;
  329.  
  330. if (window->title) {
  331. title = WIN_UTF8ToString(window->title);
  332. } else {
  333. title = NULL;
  334. }
  335. SetWindowText(hwnd, title ? title : TEXT(""));
  336. SDL_free(title);
  337. }
  338.  
  339. void
  340. WIN_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
  341. {
  342. HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
  343. HICON hicon = NULL;
  344. BYTE *icon_bmp;
  345. int icon_len, y;
  346. SDL_RWops *dst;
  347.  
  348. /* Create temporary bitmap buffer */
  349. icon_len = 40 + icon->h * icon->w * 4;
  350. icon_bmp = SDL_stack_alloc(BYTE, icon_len);
  351. dst = SDL_RWFromMem(icon_bmp, icon_len);
  352. if (!dst) {
  353. SDL_stack_free(icon_bmp);
  354. return;
  355. }
  356.  
  357. /* Write the BITMAPINFO header */
  358. SDL_WriteLE32(dst, 40);
  359. SDL_WriteLE32(dst, icon->w);
  360. SDL_WriteLE32(dst, icon->h * 2);
  361. SDL_WriteLE16(dst, 1);
  362. SDL_WriteLE16(dst, 32);
  363. SDL_WriteLE32(dst, BI_RGB);
  364. SDL_WriteLE32(dst, icon->h * icon->w * 4);
  365. SDL_WriteLE32(dst, 0);
  366. SDL_WriteLE32(dst, 0);
  367. SDL_WriteLE32(dst, 0);
  368. SDL_WriteLE32(dst, 0);
  369.  
  370. /* Write the pixels upside down into the bitmap buffer */
  371. SDL_assert(icon->format->format == SDL_PIXELFORMAT_ARGB8888);
  372. y = icon->h;
  373. while (y--) {
  374. Uint8 *src = (Uint8 *) icon->pixels + y * icon->pitch;
  375. SDL_RWwrite(dst, src, icon->pitch, 1);
  376. }
  377.  
  378. hicon = CreateIconFromResource(icon_bmp, icon_len, TRUE, 0x00030000);
  379.  
  380. SDL_RWclose(dst);
  381. SDL_stack_free(icon_bmp);
  382.  
  383. /* Set the icon for the window */
  384. SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);
  385.  
  386. /* Set the icon in the task manager (should we do this?) */
  387. SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
  388. }
  389.  
  390. void
  391. WIN_SetWindowPosition(_THIS, SDL_Window * window)
  392. {
  393. WIN_SetWindowPositionInternal(_this, window, SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOACTIVATE);
  394. }
  395.  
  396. void
  397. WIN_SetWindowSize(_THIS, SDL_Window * window)
  398. {
  399. WIN_SetWindowPositionInternal(_this, window, SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOACTIVATE);
  400. }
  401.  
  402. void
  403. WIN_ShowWindow(_THIS, SDL_Window * window)
  404. {
  405. HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
  406. ShowWindow(hwnd, SW_SHOW);
  407. }
  408.  
  409. void
  410. WIN_HideWindow(_THIS, SDL_Window * window)
  411. {
  412. HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
  413. ShowWindow(hwnd, SW_HIDE);
  414. }
  415.  
  416. void
  417. WIN_RaiseWindow(_THIS, SDL_Window * window)
  418. {
  419. WIN_SetWindowPositionInternal(_this, window, SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOSIZE);
  420.  
  421. /* Raising the window while alt-tabbed can cause it to be minimized for some reason? */
  422. WIN_RestoreWindow(_this, window);
  423. }
  424.  
  425. void
  426. WIN_MaximizeWindow(_THIS, SDL_Window * window)
  427. {
  428. HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
  429. ShowWindow(hwnd, SW_MAXIMIZE);
  430. }
  431.  
  432. void
  433. WIN_MinimizeWindow(_THIS, SDL_Window * window)
  434. {
  435. HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
  436. ShowWindow(hwnd, SW_MINIMIZE);
  437. }
  438.  
  439. void
  440. WIN_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
  441. {
  442. HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
  443. DWORD style = GetWindowLong(hwnd, GWL_STYLE);
  444.  
  445. if (bordered) {
  446. style &= ~STYLE_BORDERLESS;
  447. style |= STYLE_NORMAL;
  448. } else {
  449. style &= ~STYLE_NORMAL;
  450. style |= STYLE_BORDERLESS;
  451. }
  452.  
  453. SetWindowLong(hwnd, GWL_STYLE, style);
  454. WIN_SetWindowPositionInternal(_this, window, SWP_NOCOPYBITS | SWP_FRAMECHANGED | SWP_NOREPOSITION | SWP_NOZORDER |SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  455. }
  456.  
  457. void
  458. WIN_RestoreWindow(_THIS, SDL_Window * window)
  459. {
  460. HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
  461.  
  462. ShowWindow(hwnd, SW_RESTORE);
  463. }
  464.  
  465. void
  466. WIN_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
  467. {
  468. SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
  469. HWND hwnd = data->hwnd;
  470. RECT rect;
  471. SDL_Rect bounds;
  472. DWORD style;
  473. HWND top;
  474. BOOL menu;
  475. int x, y;
  476. int w, h;
  477.  
  478. if (SDL_ShouldAllowTopmost() && (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS)) == (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS)) {
  479. top = HWND_TOPMOST;
  480. } else {
  481. top = HWND_NOTOPMOST;
  482. }
  483.  
  484. style = GetWindowLong(hwnd, GWL_STYLE);
  485. style &= ~STYLE_MASK;
  486. style |= GetWindowStyle(window);
  487.  
  488. WIN_GetDisplayBounds(_this, display, &bounds);
  489.  
  490. if (fullscreen) {
  491. x = bounds.x;
  492. y = bounds.y;
  493. w = bounds.w;
  494. h = bounds.h;
  495. } else {
  496. rect.left = 0;
  497. rect.top = 0;
  498. rect.right = window->windowed.w;
  499. rect.bottom = window->windowed.h;
  500. menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
  501. AdjustWindowRectEx(&rect, style, menu, 0);
  502. w = (rect.right - rect.left);
  503. h = (rect.bottom - rect.top);
  504. x = window->windowed.x + rect.left;
  505. y = window->windowed.y + rect.top;
  506. }
  507. SetWindowLong(hwnd, GWL_STYLE, style);
  508. SetWindowPos(hwnd, top, x, y, w, h, SWP_NOCOPYBITS);
  509. }
  510.  
  511. int
  512. WIN_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp)
  513. {
  514. SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
  515. SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
  516. HDC hdc;
  517. BOOL succeeded = FALSE;
  518.  
  519. hdc = CreateDC(data->DeviceName, NULL, NULL, NULL);
  520. if (hdc) {
  521. succeeded = SetDeviceGammaRamp(hdc, (LPVOID)ramp);
  522. if (!succeeded) {
  523. WIN_SetError("SetDeviceGammaRamp()");
  524. }
  525. DeleteDC(hdc);
  526. }
  527. return succeeded ? 0 : -1;
  528. }
  529.  
  530. int
  531. WIN_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp)
  532. {
  533. SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
  534. SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
  535. HDC hdc;
  536. BOOL succeeded = FALSE;
  537.  
  538. hdc = CreateDC(data->DeviceName, NULL, NULL, NULL);
  539. if (hdc) {
  540. succeeded = GetDeviceGammaRamp(hdc, (LPVOID)ramp);
  541. if (!succeeded) {
  542. WIN_SetError("GetDeviceGammaRamp()");
  543. }
  544. DeleteDC(hdc);
  545. }
  546. return succeeded ? 0 : -1;
  547. }
  548.  
  549. void
  550. WIN_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
  551. {
  552. HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
  553.  
  554. if (grabbed) {
  555. RECT rect;
  556. GetClientRect(hwnd, &rect);
  557. ClientToScreen(hwnd, (LPPOINT) & rect);
  558. ClientToScreen(hwnd, (LPPOINT) & rect + 1);
  559. ClipCursor(&rect);
  560. } else {
  561. ClipCursor(NULL);
  562. }
  563.  
  564. if (window->flags & SDL_WINDOW_FULLSCREEN) {
  565. UINT flags = SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOSIZE;
  566.  
  567. if (!(window->flags & SDL_WINDOW_SHOWN)) {
  568. flags |= SWP_NOACTIVATE;
  569. }
  570. WIN_SetWindowPositionInternal(_this, window, flags);
  571. }
  572. }
  573.  
  574. void
  575. WIN_DestroyWindow(_THIS, SDL_Window * window)
  576. {
  577. SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
  578.  
  579. if (data) {
  580. ReleaseDC(data->hwnd, data->hdc);
  581. if (data->created) {
  582. DestroyWindow(data->hwnd);
  583. } else {
  584. /* Restore any original event handler... */
  585. if (data->wndproc != NULL) {
  586. #ifdef GWLP_WNDPROC
  587. SetWindowLongPtr(data->hwnd, GWLP_WNDPROC,
  588. (LONG_PTR) data->wndproc);
  589. #else
  590. SetWindowLong(data->hwnd, GWL_WNDPROC,
  591. (LONG_PTR) data->wndproc);
  592. #endif
  593. }
  594. }
  595. SDL_free(data);
  596. }
  597. }
  598.  
  599. SDL_bool
  600. WIN_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
  601. {
  602. HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
  603. if (info->version.major <= SDL_MAJOR_VERSION) {
  604. info->subsystem = SDL_SYSWM_WINDOWS;
  605. info->info.win.window = hwnd;
  606. return SDL_TRUE;
  607. } else {
  608. SDL_SetError("Application not compiled with SDL %d.%d\n",
  609. SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
  610. return SDL_FALSE;
  611. }
  612. }
  613.  
  614.  
  615. /*
  616. * Creates a HelperWindow used for DirectInput events.
  617. */
  618. int
  619. SDL_HelperWindowCreate(void)
  620. {
  621. HINSTANCE hInstance = GetModuleHandle(NULL);
  622. WNDCLASS wce;
  623.  
  624. /* Make sure window isn't created twice. */
  625. if (SDL_HelperWindow != NULL) {
  626. return 0;
  627. }
  628.  
  629. /* Create the class. */
  630. SDL_zero(wce);
  631. wce.lpfnWndProc = DefWindowProc;
  632. wce.lpszClassName = (LPCWSTR) SDL_HelperWindowClassName;
  633. wce.hInstance = hInstance;
  634.  
  635. /* Register the class. */
  636. SDL_HelperWindowClass = RegisterClass(&wce);
  637. if (SDL_HelperWindowClass == 0) {
  638. return WIN_SetError("Unable to create Helper Window Class");
  639. }
  640.  
  641. /* Create the window. */
  642. SDL_HelperWindow = CreateWindowEx(0, SDL_HelperWindowClassName,
  643. SDL_HelperWindowName,
  644. WS_OVERLAPPED, CW_USEDEFAULT,
  645. CW_USEDEFAULT, CW_USEDEFAULT,
  646. CW_USEDEFAULT, HWND_MESSAGE, NULL,
  647. hInstance, NULL);
  648. if (SDL_HelperWindow == NULL) {
  649. UnregisterClass(SDL_HelperWindowClassName, hInstance);
  650. return WIN_SetError("Unable to create Helper Window");
  651. }
  652.  
  653. return 0;
  654. }
  655.  
  656.  
  657. /*
  658. * Destroys the HelperWindow previously created with SDL_HelperWindowCreate.
  659. */
  660. void
  661. SDL_HelperWindowDestroy(void)
  662. {
  663. HINSTANCE hInstance = GetModuleHandle(NULL);
  664.  
  665. /* Destroy the window. */
  666. if (SDL_HelperWindow != NULL) {
  667. if (DestroyWindow(SDL_HelperWindow) == 0) {
  668. WIN_SetError("Unable to destroy Helper Window");
  669. return;
  670. }
  671. SDL_HelperWindow = NULL;
  672. }
  673.  
  674. /* Unregister the class. */
  675. if (SDL_HelperWindowClass != 0) {
  676. if ((UnregisterClass(SDL_HelperWindowClassName, hInstance)) == 0) {
  677. WIN_SetError("Unable to destroy Helper Window Class");
  678. return;
  679. }
  680. SDL_HelperWindowClass = 0;
  681. }
  682. }
  683.  
  684. void WIN_OnWindowEnter(_THIS, SDL_Window * window)
  685. {
  686. #ifdef WM_MOUSELEAVE
  687. SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
  688. TRACKMOUSEEVENT trackMouseEvent;
  689.  
  690. if (!data || !data->hwnd) {
  691. /* The window wasn't fully initialized */
  692. return;
  693. }
  694.  
  695. trackMouseEvent.cbSize = sizeof(TRACKMOUSEEVENT);
  696. trackMouseEvent.dwFlags = TME_LEAVE;
  697. trackMouseEvent.hwndTrack = data->hwnd;
  698.  
  699. TrackMouseEvent(&trackMouseEvent);
  700. #endif /* WM_MOUSELEAVE */
  701. }
  702.  
  703. #endif /* SDL_VIDEO_DRIVER_WINDOWS */
  704.  
  705. /* vi: set ts=4 sw=4 expandtab: */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement