testnativew32.c (2073B)
1/* 2 Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org> 3 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 8 Permission is granted to anyone to use this software for any purpose, 9 including commercial applications, and to alter it and redistribute it 10 freely. 11*/ 12 13#include "testnative.h" 14 15#ifdef TEST_NATIVE_WINDOWS 16 17static void *CreateWindowNative(int w, int h); 18static void DestroyWindowNative(void *window); 19 20NativeWindowFactory WindowsWindowFactory = { 21 "windows", 22 CreateWindowNative, 23 DestroyWindowNative 24}; 25 26LRESULT CALLBACK 27WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) 28{ 29 switch (msg) { 30 case WM_CLOSE: 31 DestroyWindow(hwnd); 32 break; 33 case WM_DESTROY: 34 PostQuitMessage(0); 35 break; 36 default: 37 return DefWindowProc(hwnd, msg, wParam, lParam); 38 } 39 return 0; 40} 41 42static void * 43CreateWindowNative(int w, int h) 44{ 45 HWND hwnd; 46 WNDCLASS wc; 47 48 wc.style = 0; 49 wc.lpfnWndProc = WndProc; 50 wc.cbClsExtra = 0; 51 wc.cbWndExtra = 0; 52 wc.hInstance = GetModuleHandle(NULL); 53 wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); 54 wc.hCursor = LoadCursor(NULL, IDC_ARROW); 55 wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1); 56 wc.lpszMenuName = NULL; 57 wc.lpszClassName = "SDL Test"; 58 59 if (!RegisterClass(&wc)) { 60 MessageBox(NULL, "Window Registration Failed!", "Error!", 61 MB_ICONEXCLAMATION | MB_OK); 62 return 0; 63 } 64 65 hwnd = 66 CreateWindow("SDL Test", "", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 67 CW_USEDEFAULT, w, h, NULL, NULL, GetModuleHandle(NULL), 68 NULL); 69 if (hwnd == NULL) { 70 MessageBox(NULL, "Window Creation Failed!", "Error!", 71 MB_ICONEXCLAMATION | MB_OK); 72 return 0; 73 } 74 75 ShowWindow(hwnd, SW_SHOW); 76 77 return hwnd; 78} 79 80static void 81DestroyWindowNative(void *window) 82{ 83 DestroyWindow((HWND) window); 84} 85 86#endif