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