test/testnativew32.c
author Paul Hunkin <paul@bieh.net>
Mon, 17 May 2010 15:14:34 +1200
changeset 4695 b7918263da92
parent 3071 6f3308d4b6cd
child 5062 e8916fe9cfc8
permissions -rw-r--r--
Initial commit, adding __ANDROID__ to the platform list
     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
    16 WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    17 {
    18     switch (msg) {
    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         MessageBox(NULL, "Window Registration Failed!", "Error!",
    50                    MB_ICONEXCLAMATION | MB_OK);
    51         return 0;
    52     }
    53 
    54     hwnd =
    55         CreateWindow("SDL Test", "", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,
    56                      CW_USEDEFAULT, w, h, NULL, NULL, GetModuleHandle(NULL),
    57                      NULL);
    58     if (hwnd == NULL) {
    59         MessageBox(NULL, "Window Creation Failed!", "Error!",
    60                    MB_ICONEXCLAMATION | MB_OK);
    61         return 0;
    62     }
    63 
    64     ShowWindow(hwnd, SW_SHOW);
    65 
    66     return hwnd;
    67 }
    68 
    69 static void
    70 DestroyWindowWin32(void *window)
    71 {
    72     DestroyWindow((HWND) window);
    73 }
    74 
    75 #endif