test/testnativew32.c
author Ryan C. Gordon <icculus@icculus.org>
Fri, 12 Aug 2016 19:59:00 -0400
changeset 10266 c09f06c4e8c8
parent 9998 f67cf37e9cd4
permissions -rw-r--r--
emscripten: send fake mouse events for touches, like other targets do. (This really should be handled at the higher level and not in the individual targets, but this fixes the immediate bug.)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
     1
/*
9998
f67cf37e9cd4 Updated copyright to 2016
Sam Lantinga <slouken@libsdl.org>
parents: 9619
diff changeset
     2
  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
     3
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
     4
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
     5
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
     6
  arising from the use of this software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
     7
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
     8
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
     9
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
    10
  freely.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
    11
*/
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    13
#include "testnative.h"
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    14
5062
e8916fe9cfc8 Fixed bug #925
Sam Lantinga <slouken@libsdl.org>
parents: 3071
diff changeset
    15
#ifdef TEST_NATIVE_WINDOWS
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    16
5062
e8916fe9cfc8 Fixed bug #925
Sam Lantinga <slouken@libsdl.org>
parents: 3071
diff changeset
    17
static void *CreateWindowNative(int w, int h);
e8916fe9cfc8 Fixed bug #925
Sam Lantinga <slouken@libsdl.org>
parents: 3071
diff changeset
    18
static void DestroyWindowNative(void *window);
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    19
5062
e8916fe9cfc8 Fixed bug #925
Sam Lantinga <slouken@libsdl.org>
parents: 3071
diff changeset
    20
NativeWindowFactory WindowsWindowFactory = {
e8916fe9cfc8 Fixed bug #925
Sam Lantinga <slouken@libsdl.org>
parents: 3071
diff changeset
    21
    "windows",
e8916fe9cfc8 Fixed bug #925
Sam Lantinga <slouken@libsdl.org>
parents: 3071
diff changeset
    22
    CreateWindowNative,
e8916fe9cfc8 Fixed bug #925
Sam Lantinga <slouken@libsdl.org>
parents: 3071
diff changeset
    23
    DestroyWindowNative
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
};
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
3071
Sam Lantinga <slouken@libsdl.org>
parents: 3060
diff changeset
    26
LRESULT CALLBACK
Sam Lantinga <slouken@libsdl.org>
parents: 3060
diff changeset
    27
WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
3060
4cf533f434d8 Implemented Win32 version of the native window test
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    28
{
3071
Sam Lantinga <slouken@libsdl.org>
parents: 3060
diff changeset
    29
    switch (msg) {
Sam Lantinga <slouken@libsdl.org>
parents: 3060
diff changeset
    30
    case WM_CLOSE:
Sam Lantinga <slouken@libsdl.org>
parents: 3060
diff changeset
    31
        DestroyWindow(hwnd);
3060
4cf533f434d8 Implemented Win32 version of the native window test
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    32
        break;
3071
Sam Lantinga <slouken@libsdl.org>
parents: 3060
diff changeset
    33
    case WM_DESTROY:
Sam Lantinga <slouken@libsdl.org>
parents: 3060
diff changeset
    34
        PostQuitMessage(0);
3060
4cf533f434d8 Implemented Win32 version of the native window test
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    35
        break;
3071
Sam Lantinga <slouken@libsdl.org>
parents: 3060
diff changeset
    36
    default:
Sam Lantinga <slouken@libsdl.org>
parents: 3060
diff changeset
    37
        return DefWindowProc(hwnd, msg, wParam, lParam);
3060
4cf533f434d8 Implemented Win32 version of the native window test
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    38
    }
4cf533f434d8 Implemented Win32 version of the native window test
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    39
    return 0;
4cf533f434d8 Implemented Win32 version of the native window test
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    40
}
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    41
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    42
static void *
5062
e8916fe9cfc8 Fixed bug #925
Sam Lantinga <slouken@libsdl.org>
parents: 3071
diff changeset
    43
CreateWindowNative(int w, int h)
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    44
{
3060
4cf533f434d8 Implemented Win32 version of the native window test
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    45
    HWND hwnd;
4cf533f434d8 Implemented Win32 version of the native window test
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    46
    WNDCLASS wc;
4cf533f434d8 Implemented Win32 version of the native window test
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    47
3071
Sam Lantinga <slouken@libsdl.org>
parents: 3060
diff changeset
    48
    wc.style = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3060
diff changeset
    49
    wc.lpfnWndProc = WndProc;
Sam Lantinga <slouken@libsdl.org>
parents: 3060
diff changeset
    50
    wc.cbClsExtra = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3060
diff changeset
    51
    wc.cbWndExtra = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3060
diff changeset
    52
    wc.hInstance = GetModuleHandle(NULL);
Sam Lantinga <slouken@libsdl.org>
parents: 3060
diff changeset
    53
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
Sam Lantinga <slouken@libsdl.org>
parents: 3060
diff changeset
    54
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
Sam Lantinga <slouken@libsdl.org>
parents: 3060
diff changeset
    55
    wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
Sam Lantinga <slouken@libsdl.org>
parents: 3060
diff changeset
    56
    wc.lpszMenuName = NULL;
3060
4cf533f434d8 Implemented Win32 version of the native window test
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    57
    wc.lpszClassName = "SDL Test";
4cf533f434d8 Implemented Win32 version of the native window test
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    58
3071
Sam Lantinga <slouken@libsdl.org>
parents: 3060
diff changeset
    59
    if (!RegisterClass(&wc)) {
3060
4cf533f434d8 Implemented Win32 version of the native window test
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    60
        MessageBox(NULL, "Window Registration Failed!", "Error!",
3071
Sam Lantinga <slouken@libsdl.org>
parents: 3060
diff changeset
    61
                   MB_ICONEXCLAMATION | MB_OK);
3060
4cf533f434d8 Implemented Win32 version of the native window test
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    62
        return 0;
4cf533f434d8 Implemented Win32 version of the native window test
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    63
    }
4cf533f434d8 Implemented Win32 version of the native window test
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    64
3071
Sam Lantinga <slouken@libsdl.org>
parents: 3060
diff changeset
    65
    hwnd =
Sam Lantinga <slouken@libsdl.org>
parents: 3060
diff changeset
    66
        CreateWindow("SDL Test", "", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,
Sam Lantinga <slouken@libsdl.org>
parents: 3060
diff changeset
    67
                     CW_USEDEFAULT, w, h, NULL, NULL, GetModuleHandle(NULL),
Sam Lantinga <slouken@libsdl.org>
parents: 3060
diff changeset
    68
                     NULL);
Sam Lantinga <slouken@libsdl.org>
parents: 3060
diff changeset
    69
    if (hwnd == NULL) {
3060
4cf533f434d8 Implemented Win32 version of the native window test
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    70
        MessageBox(NULL, "Window Creation Failed!", "Error!",
3071
Sam Lantinga <slouken@libsdl.org>
parents: 3060
diff changeset
    71
                   MB_ICONEXCLAMATION | MB_OK);
3060
4cf533f434d8 Implemented Win32 version of the native window test
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    72
        return 0;
4cf533f434d8 Implemented Win32 version of the native window test
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    73
    }
4cf533f434d8 Implemented Win32 version of the native window test
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    74
4cf533f434d8 Implemented Win32 version of the native window test
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    75
    ShowWindow(hwnd, SW_SHOW);
4cf533f434d8 Implemented Win32 version of the native window test
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    76
4cf533f434d8 Implemented Win32 version of the native window test
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    77
    return hwnd;
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    78
}
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    79
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    80
static void
5062
e8916fe9cfc8 Fixed bug #925
Sam Lantinga <slouken@libsdl.org>
parents: 3071
diff changeset
    81
DestroyWindowNative(void *window)
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    82
{
3071
Sam Lantinga <slouken@libsdl.org>
parents: 3060
diff changeset
    83
    DestroyWindow((HWND) window);
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    84
}
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    85
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    86
#endif