test/testnativew32.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 17 Feb 2009 05:57:54 +0000
changeset 3071 6f3308d4b6cd
parent 3060 4cf533f434d8
child 5062 e8916fe9cfc8
permissions -rw-r--r--
indent
slouken@3057
     1
slouken@3057
     2
#include "testnative.h"
slouken@3057
     3
slouken@3057
     4
#ifdef TEST_NATIVE_WIN32
slouken@3057
     5
slouken@3057
     6
static void *CreateWindowWin32(int w, int h);
slouken@3057
     7
static void DestroyWindowWin32(void *window);
slouken@3057
     8
slouken@3057
     9
NativeWindowFactory Win32WindowFactory = {
slouken@3057
    10
    "win32",
slouken@3057
    11
    CreateWindowWin32,
slouken@3057
    12
    DestroyWindowWin32
slouken@3057
    13
};
slouken@3057
    14
slouken@3071
    15
LRESULT CALLBACK
slouken@3071
    16
WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
slouken@3060
    17
{
slouken@3071
    18
    switch (msg) {
slouken@3071
    19
    case WM_CLOSE:
slouken@3071
    20
        DestroyWindow(hwnd);
slouken@3060
    21
        break;
slouken@3071
    22
    case WM_DESTROY:
slouken@3071
    23
        PostQuitMessage(0);
slouken@3060
    24
        break;
slouken@3071
    25
    default:
slouken@3071
    26
        return DefWindowProc(hwnd, msg, wParam, lParam);
slouken@3060
    27
    }
slouken@3060
    28
    return 0;
slouken@3060
    29
}
slouken@3057
    30
slouken@3057
    31
static void *
slouken@3057
    32
CreateWindowWin32(int w, int h)
slouken@3057
    33
{
slouken@3060
    34
    HWND hwnd;
slouken@3060
    35
    WNDCLASS wc;
slouken@3060
    36
slouken@3071
    37
    wc.style = 0;
slouken@3071
    38
    wc.lpfnWndProc = WndProc;
slouken@3071
    39
    wc.cbClsExtra = 0;
slouken@3071
    40
    wc.cbWndExtra = 0;
slouken@3071
    41
    wc.hInstance = GetModuleHandle(NULL);
slouken@3071
    42
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
slouken@3071
    43
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
slouken@3071
    44
    wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
slouken@3071
    45
    wc.lpszMenuName = NULL;
slouken@3060
    46
    wc.lpszClassName = "SDL Test";
slouken@3060
    47
slouken@3071
    48
    if (!RegisterClass(&wc)) {
slouken@3060
    49
        MessageBox(NULL, "Window Registration Failed!", "Error!",
slouken@3071
    50
                   MB_ICONEXCLAMATION | MB_OK);
slouken@3060
    51
        return 0;
slouken@3060
    52
    }
slouken@3060
    53
slouken@3071
    54
    hwnd =
slouken@3071
    55
        CreateWindow("SDL Test", "", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,
slouken@3071
    56
                     CW_USEDEFAULT, w, h, NULL, NULL, GetModuleHandle(NULL),
slouken@3071
    57
                     NULL);
slouken@3071
    58
    if (hwnd == NULL) {
slouken@3060
    59
        MessageBox(NULL, "Window Creation Failed!", "Error!",
slouken@3071
    60
                   MB_ICONEXCLAMATION | MB_OK);
slouken@3060
    61
        return 0;
slouken@3060
    62
    }
slouken@3060
    63
slouken@3060
    64
    ShowWindow(hwnd, SW_SHOW);
slouken@3060
    65
slouken@3060
    66
    return hwnd;
slouken@3057
    67
}
slouken@3057
    68
slouken@3057
    69
static void
slouken@3057
    70
DestroyWindowWin32(void *window)
slouken@3057
    71
{
slouken@3071
    72
    DestroyWindow((HWND) window);
slouken@3057
    73
}
slouken@3057
    74
slouken@3057
    75
#endif