testnativew32.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
  3. This software is provided 'as-is', without any express or implied
  4. warranty. In no event will the authors be held liable for any damages
  5. arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose,
  7. including commercial applications, and to alter it and redistribute it
  8. freely.
  9. */
  10. #include "testnative.h"
  11. #ifdef TEST_NATIVE_WINDOWS
  12. static void *CreateWindowNative(int w, int h);
  13. static void DestroyWindowNative(void *window);
  14. NativeWindowFactory WindowsWindowFactory = {
  15. "windows",
  16. CreateWindowNative,
  17. DestroyWindowNative
  18. };
  19. LRESULT CALLBACK
  20. WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  21. {
  22. switch (msg) {
  23. case WM_CLOSE:
  24. DestroyWindow(hwnd);
  25. break;
  26. case WM_DESTROY:
  27. PostQuitMessage(0);
  28. break;
  29. default:
  30. return DefWindowProc(hwnd, msg, wParam, lParam);
  31. }
  32. return 0;
  33. }
  34. static void *
  35. CreateWindowNative(int w, int h)
  36. {
  37. HWND hwnd;
  38. WNDCLASS wc;
  39. wc.style = 0;
  40. wc.lpfnWndProc = WndProc;
  41. wc.cbClsExtra = 0;
  42. wc.cbWndExtra = 0;
  43. wc.hInstance = GetModuleHandle(NULL);
  44. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  45. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  46. wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
  47. wc.lpszMenuName = NULL;
  48. wc.lpszClassName = "SDL Test";
  49. if (!RegisterClass(&wc)) {
  50. MessageBox(NULL, "Window Registration Failed!", "Error!",
  51. MB_ICONEXCLAMATION | MB_OK);
  52. return 0;
  53. }
  54. hwnd =
  55. CreateWindow("SDL Test", "", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,
  56. CW_USEDEFAULT, w, h, NULL, NULL, GetModuleHandle(NULL),
  57. NULL);
  58. if (hwnd == NULL) {
  59. MessageBox(NULL, "Window Creation Failed!", "Error!",
  60. MB_ICONEXCLAMATION | MB_OK);
  61. return 0;
  62. }
  63. ShowWindow(hwnd, SW_SHOW);
  64. return hwnd;
  65. }
  66. static void
  67. DestroyWindowNative(void *window)
  68. {
  69. DestroyWindow((HWND) window);
  70. }
  71. #endif