test/testnativew32.c
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Sat, 21 Mar 2015 08:01:43 +0100
changeset 9417 86483b23f44a
parent 8149 681eb46b8ac4
child 9619 b94b6d0bff0f
permissions -rw-r--r--
Fixed confusing audio and touch events because of shared enumeration values.
     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 
    17 static void *CreateWindowNative(int w, int h);
    18 static void DestroyWindowNative(void *window);
    19 
    20 NativeWindowFactory WindowsWindowFactory = {
    21     "windows",
    22     CreateWindowNative,
    23     DestroyWindowNative
    24 };
    25 
    26 LRESULT CALLBACK
    27 WndProc(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 
    42 static void *
    43 CreateWindowNative(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 
    80 static void
    81 DestroyWindowNative(void *window)
    82 {
    83     DestroyWindow((HWND) window);
    84 }
    85 
    86 #endif