testnativew32.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. Copyright (C) 1997-2014 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