test/testnativew32.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 09 Feb 2009 06:41:49 +0000
changeset 3060 4cf533f434d8
parent 3057 089a77aebb7d
child 3071 6f3308d4b6cd
permissions -rw-r--r--
Implemented Win32 version of the native window test
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@3060
    15
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
slouken@3060
    16
{
slouken@3060
    17
    switch(msg)
slouken@3060
    18
    {
slouken@3060
    19
        case WM_CLOSE:
slouken@3060
    20
            DestroyWindow(hwnd);
slouken@3060
    21
        break;
slouken@3060
    22
        case WM_DESTROY:
slouken@3060
    23
            PostQuitMessage(0);
slouken@3060
    24
        break;
slouken@3060
    25
        default:
slouken@3060
    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@3060
    37
    wc.style         = 0;
slouken@3060
    38
    wc.lpfnWndProc   = WndProc;
slouken@3060
    39
    wc.cbClsExtra    = 0;
slouken@3060
    40
    wc.cbWndExtra    = 0;
slouken@3060
    41
    wc.hInstance     = GetModuleHandle(NULL);
slouken@3060
    42
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
slouken@3060
    43
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
slouken@3060
    44
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
slouken@3060
    45
    wc.lpszMenuName  = NULL;
slouken@3060
    46
    wc.lpszClassName = "SDL Test";
slouken@3060
    47
slouken@3060
    48
    if(!RegisterClass(&wc))
slouken@3060
    49
    {
slouken@3060
    50
        MessageBox(NULL, "Window Registration Failed!", "Error!",
slouken@3060
    51
            MB_ICONEXCLAMATION | MB_OK);
slouken@3060
    52
        return 0;
slouken@3060
    53
    }
slouken@3060
    54
slouken@3060
    55
    hwnd = CreateWindow("SDL Test", "", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, w, h, NULL, NULL, GetModuleHandle(NULL), NULL);
slouken@3060
    56
    if(hwnd == NULL)
slouken@3060
    57
    {
slouken@3060
    58
        MessageBox(NULL, "Window Creation Failed!", "Error!",
slouken@3060
    59
            MB_ICONEXCLAMATION | MB_OK);
slouken@3060
    60
        return 0;
slouken@3060
    61
    }
slouken@3060
    62
slouken@3060
    63
    ShowWindow(hwnd, SW_SHOW);
slouken@3060
    64
slouken@3060
    65
    return hwnd;
slouken@3057
    66
}
slouken@3057
    67
slouken@3057
    68
static void
slouken@3057
    69
DestroyWindowWin32(void *window)
slouken@3057
    70
{
slouken@3060
    71
    DestroyWindow((HWND)window);
slouken@3057
    72
}
slouken@3057
    73
slouken@3057
    74
#endif