- Remove dflat32. It doesn't start up in Windows XP at all (when launching edit.exe...
[reactos.git] / rosapps / demos / ddraw / main.cpp
index 231ea17..489da70 100644 (file)
@@ -1,24 +1,26 @@
 #include <windows.h>
+#include <ddrawi.h>
 #include <ddraw.h>
 
-LPDIRECTDRAW7 DirectDraw;
-LPDIRECTDRAWSURFACE7 FrontBuffer;
-LPDIRECTDRAWCLIPPER Clipper;
+LPDIRECTDRAW7 DirectDraw = NULL;
+LPDIRECTDRAWSURFACE7 FrontBuffer = NULL;
+LPDIRECTDRAWCLIPPER Clipper = NULL;
+LPDDRAWI_DIRECTDRAW_INT This = NULL;
 
 PCHAR DDErrorString (HRESULT hResult);
 LONG WINAPI WndProc (HWND hwnd, UINT message, UINT wParam, LONG lParam);
 
 bool Fullscreen, Running;
-
+//#define USE_CLIPPER
 
 bool Init (HWND hwnd)
 {
-       DDSURFACEDESC2 ddsd; 
+       DDSURFACEDESC2 ddsd;
        HRESULT hResult;
 
        // Create the main object
        OutputDebugString("=> DirectDrawCreateEx\n");
-       hResult = DirectDrawCreateEx(NULL, (VOID**)&DirectDraw, IID_IDirectDraw7, NULL); 
+       hResult = DirectDrawCreateEx(NULL, (VOID**)&DirectDraw, IID_IDirectDraw7, NULL);
 
        if (hResult != DD_OK)
        {
@@ -26,6 +28,8 @@ bool Init (HWND hwnd)
                return 0;
        }
 
+    This = (LPDDRAWI_DIRECTDRAW_INT)DirectDraw;
+
        // Set Fullscreen or windowed mode
        OutputDebugString("=> DDraw->SetCooperativeLevel\n");
 
@@ -33,7 +37,7 @@ bool Init (HWND hwnd)
                hResult = DirectDraw->SetCooperativeLevel (hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
        else
                hResult = DirectDraw->SetCooperativeLevel (hwnd, DDSCL_NORMAL);
-               
+
        if (hResult != DD_OK)
        {
                MessageBox(0,DDErrorString(hResult), "DDraw->SetCooperativeLevel", 0);
@@ -45,7 +49,7 @@ bool Init (HWND hwnd)
        {
                OutputDebugString("=> DDraw->SetDisplayMode\n");
                hResult = DirectDraw->SetDisplayMode (800, 600, 32, 0, 0);
-                       
+
                if (hResult != DD_OK)
                {
                        MessageBox(0,DDErrorString(hResult), "DDraw->SetDisplayMode", 0);
@@ -69,6 +73,7 @@ bool Init (HWND hwnd)
                return 0;
        }
 
+#ifdef USE_CLIPPER
        // Set up the clipper
        OutputDebugString("=> DDraw->CreateClipper\n");
 
@@ -85,7 +90,7 @@ bool Init (HWND hwnd)
     {
                MessageBox(0,DDErrorString(hResult), "Clipper->SetHWnd", 0);
         return  0;
-    }    
+    }
 
        OutputDebugString("=> Suface->SetClipper\n");
     hResult = FrontBuffer->SetClipper(Clipper);
@@ -94,21 +99,24 @@ bool Init (HWND hwnd)
                MessageBox(0,DDErrorString(hResult), "FrontBuffer->SetClipper", 0);
         return 0;
     }
+#endif
 
        return true;
 }
 
-void Draw (void)
+void Draw (HWND hwnd)
 {
-       // Make the fronbuffer pink
+       // Make the frontbuffer pink
+       RECT rect;
+       GetWindowRect(hwnd, &rect); // this is not necessary when clippper is used
 
        DDBLTFX  ddbltfx;
        ddbltfx.dwSize = sizeof(DDBLTFX);
-       ddbltfx.dwFillColor = RGB(255, 0, 255); 
+       ddbltfx.dwFillColor = RGB(255, 0, 255);
 
        OutputDebugString("=> Surface->Blt (DDBLT_COLORFILL)\n");
-       
-       FrontBuffer->Blt(NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
+
+       FrontBuffer->Blt(&rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
 }
 
 void CleanUp (void)
@@ -134,60 +142,72 @@ void CleanUp (void)
        }
 }
 
-int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst, 
+int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst,
                                        LPSTR lpCmdLine, int nCmdShow)
 {
-       MSG msg;  
-       WNDCLASS wndclass; 
-
+       MSG msg;
+       WNDCLASS wndclass;
+       HWND hwnd;
        Fullscreen = MessageBox(0, "Do you want to me to run in Fullscreen ?", 0, MB_YESNO) == IDYES;
 
        // Create windnow
-       wndclass.style         = CS_HREDRAW | CS_VREDRAW; 
+       wndclass.style         = CS_HREDRAW | CS_VREDRAW;
        wndclass.lpfnWndProc   = WndProc;
        wndclass.cbClsExtra    = 0;
        wndclass.cbWndExtra    = 0;
        wndclass.hInstance     = hInst;
        wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION);
-       wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW); 
+       wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW);
        wndclass.hbrBackground = (HBRUSH)GetStockObject (LTGRAY_BRUSH);
        wndclass.lpszMenuName  = NULL;
-       wndclass.lpszClassName = "DDrawDemo"; 
+       wndclass.lpszClassName = "DDrawDemo";
 
-       RegisterClass(&wndclass);    
+       RegisterClass(&wndclass);
 
-       HWND hwnd = CreateWindow("DDrawDemo", 
-                         "ReactOS DirectDraw Demo", 
-                                                Fullscreen ? WS_POPUP :WS_OVERLAPPEDWINDOW,
-                                    CW_USEDEFAULT, 
+#ifdef USE_CLIPPER
+       hwnd = CreateWindow("DDrawDemo",
+                         "ReactOS DirectDraw Demo",
+                                                Fullscreen ? WS_POPUP : WS_OVERLAPPEDWINDOW,
+                                                CW_USEDEFAULT,
                                                 CW_USEDEFAULT,
-                         800, 
-                         600,     
-                         NULL, NULL, 
+                                                800,
+                                                600,
+                                                NULL, NULL,
                                                 hInst, NULL);
+#else
+       hwnd = CreateWindow("DDrawDemo",
+                         "ReactOS DirectDraw Demo",
+                         WS_POPUP,
+                                                CW_USEDEFAULT,
+                                                CW_USEDEFAULT,
+                                                800,
+                                                600,
+                                                NULL, NULL,
+                                                hInst, NULL);
+#endif
 
        // Inizalize Ddraw
        if(Init(hwnd))
        {
                Running = true;
 
-               ShowWindow(hwnd, nCmdShow);  
+               ShowWindow(hwnd, nCmdShow);
                UpdateWindow(hwnd);
        }
-    
+
        // Main loop
        while (Running)
        {
                if(Fullscreen)
-                       Draw();
+                       Draw(hwnd);
 
                if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
-               { 
+               {
                        if (msg.message == WM_QUIT) break;
                        TranslateMessage(&msg);
                        DispatchMessage(&msg);
                }
-       } 
+       }
 
        CleanUp();
 
@@ -195,15 +215,15 @@ int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst,
 }
 
 
-LONG WINAPI WndProc (HWND hwnd, UINT message, 
-                         UINT wParam, LONG lParam) 
-{ 
+LONG WINAPI WndProc (HWND hwnd, UINT message,
+                         UINT wParam, LONG lParam)
+{
        switch (message)
        {
                case WM_PAINT:
                {
                        if(!Fullscreen)
-                               Draw();
+                               Draw(hwnd);
                } break;
 
                case WM_KEYDOWN:
@@ -218,13 +238,13 @@ LONG WINAPI WndProc (HWND hwnd, UINT message,
 
                case WM_DESTROY:
                {
-                       PostQuitMessage (0); 
+                       PostQuitMessage (0);
                        return 0;
                } break;
        }
 
        return DefWindowProc (hwnd, message, wParam, lParam);
-} 
+}
 
 PCHAR DDErrorString (HRESULT hResult)
 {