Implemented Win32 version of the native window test
authorSam Lantinga <slouken@libsdl.org>
Mon, 09 Feb 2009 06:41:49 +0000
changeset 30604cf533f434d8
parent 3059 79b061c4f316
child 3061 94dd49f6b005
Implemented Win32 version of the native window test
test/testnative.c
test/testnativew32.c
     1.1 --- a/test/testnative.c	Mon Feb 09 06:28:45 2009 +0000
     1.2 +++ b/test/testnative.c	Mon Feb 09 06:41:49 2009 +0000
     1.3 @@ -29,7 +29,7 @@
     1.4  {
     1.5      SDL_VideoQuit();
     1.6      if (native_window) {
     1.7 -        factory->DestroyWindow(native_window);
     1.8 +        factory->DestroyNativeWindow(native_window);
     1.9      }
    1.10      exit(rc);
    1.11  }
    1.12 @@ -137,7 +137,7 @@
    1.13          quit(2);
    1.14      }
    1.15      printf("Creating native window for %s driver\n", driver);
    1.16 -    native_window = factory->CreateWindow(WINDOW_W, WINDOW_H);
    1.17 +    native_window = factory->CreateNativeWindow(WINDOW_W, WINDOW_H);
    1.18      if (!native_window) {
    1.19          fprintf(stderr, "Couldn't create native window\n");
    1.20          quit(3);
     2.1 --- a/test/testnativew32.c	Mon Feb 09 06:28:45 2009 +0000
     2.2 +++ b/test/testnativew32.c	Mon Feb 09 06:41:49 2009 +0000
     2.3 @@ -12,17 +12,63 @@
     2.4      DestroyWindowWin32
     2.5  };
     2.6  
     2.7 -static Display *dpy;
     2.8 +LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
     2.9 +{
    2.10 +    switch(msg)
    2.11 +    {
    2.12 +        case WM_CLOSE:
    2.13 +            DestroyWindow(hwnd);
    2.14 +        break;
    2.15 +        case WM_DESTROY:
    2.16 +            PostQuitMessage(0);
    2.17 +        break;
    2.18 +        default:
    2.19 +            return DefWindowProc(hwnd, msg, wParam, lParam);
    2.20 +    }
    2.21 +    return 0;
    2.22 +}
    2.23  
    2.24  static void *
    2.25  CreateWindowWin32(int w, int h)
    2.26  {
    2.27 -    return NULL;
    2.28 +    HWND hwnd;
    2.29 +    WNDCLASS wc;
    2.30 +
    2.31 +    wc.style         = 0;
    2.32 +    wc.lpfnWndProc   = WndProc;
    2.33 +    wc.cbClsExtra    = 0;
    2.34 +    wc.cbWndExtra    = 0;
    2.35 +    wc.hInstance     = GetModuleHandle(NULL);
    2.36 +    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    2.37 +    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    2.38 +    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    2.39 +    wc.lpszMenuName  = NULL;
    2.40 +    wc.lpszClassName = "SDL Test";
    2.41 +
    2.42 +    if(!RegisterClass(&wc))
    2.43 +    {
    2.44 +        MessageBox(NULL, "Window Registration Failed!", "Error!",
    2.45 +            MB_ICONEXCLAMATION | MB_OK);
    2.46 +        return 0;
    2.47 +    }
    2.48 +
    2.49 +    hwnd = CreateWindow("SDL Test", "", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, w, h, NULL, NULL, GetModuleHandle(NULL), NULL);
    2.50 +    if(hwnd == NULL)
    2.51 +    {
    2.52 +        MessageBox(NULL, "Window Creation Failed!", "Error!",
    2.53 +            MB_ICONEXCLAMATION | MB_OK);
    2.54 +        return 0;
    2.55 +    }
    2.56 +
    2.57 +    ShowWindow(hwnd, SW_SHOW);
    2.58 +
    2.59 +    return hwnd;
    2.60  }
    2.61  
    2.62  static void
    2.63  DestroyWindowWin32(void *window)
    2.64  {
    2.65 +    DestroyWindow((HWND)window);
    2.66  }
    2.67  
    2.68  #endif