[COMCTL32_WINETEST] Sync with Wine Staging 1.9.23. CORE-12409
[reactos.git] / rostests / dxtest / ddraw / helper.cpp
1 #include "ddrawtest.h"
2
3 LRESULT WINAPI BasicWindowProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
4 {
5 switch (message)
6 {
7 case WM_DESTROY:
8 {
9 PostQuitMessage (0);
10 return 0;
11 } break;
12 }
13
14 return DefWindowProc (hwnd, message, wParam, lParam);
15 }
16
17 HWND CreateBasicWindow (VOID)
18 {
19 WNDCLASS wndclass = {0};
20 wndclass.lpfnWndProc = BasicWindowProc;
21 wndclass.hInstance = GetModuleHandle(NULL);
22 wndclass.lpszClassName = "DDrawTest";
23 RegisterClass(&wndclass);
24
25 return CreateWindow("DDrawTest", "ReactOS DirectDraw Test", WS_POPUP, 0, 0, 10, 10, NULL, NULL, GetModuleHandle(NULL), NULL);
26 }
27
28 BOOL CreateSurface(LPDIRECTDRAWSURFACE7* pSurface)
29 {
30 LPDIRECTDRAW7 DirectDraw;
31 LPDIRECTDRAWSURFACE7 Surface;
32 HWND hwnd;
33
34 // Create DDraw Object
35 if (DirectDrawCreateEx(NULL, (VOID**)&DirectDraw, IID_IDirectDraw7, NULL) != DD_OK)
36 {
37 printf("ERROR: Failed to set up ddraw\n");
38 return FALSE;
39 }
40
41 if(!( hwnd = CreateBasicWindow() ))
42 {
43 printf("ERROR: Failed to create window\n");
44 DirectDraw->Release();
45 return FALSE;
46 }
47
48 if (DirectDraw->SetCooperativeLevel (hwnd, DDSCL_NORMAL) != DD_OK)
49 {
50 printf("ERROR: Could not set cooperative level\n");
51 DirectDraw->Release();
52 return 0;
53 }
54
55 // Creat Surface
56 DDSURFACEDESC2 Desc = { 0 };
57 Desc.dwHeight = 200;
58 Desc.dwWidth = 200;
59 Desc.dwSize = sizeof (DDSURFACEDESC2);
60 Desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
61 Desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
62
63 if(DirectDraw->CreateSurface(&Desc, &Surface, NULL) != DD_OK)
64 {
65 printf("ERROR: Faild to create Surface\n");
66 return FALSE;
67 }
68
69 DirectDraw->Release();
70
71 *pSurface = Surface;
72 return TRUE;
73 }