- Fix my old coding style and get rid of main.h
- Change he color to pink for alternation
svn path=/trunk/; revision=23172
#include <windows.h>
#include <ddraw.h>
#include <windows.h>
#include <ddraw.h>
+LPDIRECTDRAW7 DirectDraw;
+LPDIRECTDRAWSURFACE7 FrontBuffer;
+LPDIRECTDRAWCLIPPER Clipper;
+PCHAR DDErrorString (HRESULT hResult);
+LONG WINAPI WndProc (HWND hwnd, UINT message, UINT wParam, LONG lParam);
+
+bool Fullscreen, Running;
+
+
+bool Init (HWND hwnd)
+ DDSURFACEDESC2 ddsd;
+ HRESULT hResult;
// Create the main object
OutputDebugString("=> DirectDrawCreateEx\n");
// Create the main object
OutputDebugString("=> DirectDrawCreateEx\n");
- ddrval = DirectDrawCreateEx(NULL, (VOID**)&pDD, IID_IDirectDraw7, NULL);
+ hResult = DirectDrawCreateEx(NULL, (VOID**)&DirectDraw, IID_IDirectDraw7, NULL);
- MessageBox(0,DDErrorString(ddrval), "DirectDrawCreateEx", 0);
+ MessageBox(0,DDErrorString(hResult), "DirectDrawCreateEx", 0);
- // set fullscreen or not
+ // Set Fullscreen or windowed mode
OutputDebugString("=> DDraw->SetCooperativeLevel\n");
OutputDebugString("=> DDraw->SetCooperativeLevel\n");
- if(fullscreen)
- ddrval = pDD->SetCooperativeLevel (hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
+ if(Fullscreen)
+ hResult = DirectDraw->SetCooperativeLevel (hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
- ddrval = pDD->SetCooperativeLevel (hwnd, DDSCL_NORMAL);
+ hResult = DirectDraw->SetCooperativeLevel (hwnd, DDSCL_NORMAL);
- MessageBox(0,DDErrorString(ddrval), "DDraw->SetCooperativeLevel", 0);
+ MessageBox(0,DDErrorString(hResult), "DDraw->SetCooperativeLevel", 0);
- // set the new resolution
- if(fullscreen)
+ // Set the new resolution
+ if(Fullscreen)
{
OutputDebugString("=> DDraw->SetDisplayMode\n");
{
OutputDebugString("=> DDraw->SetDisplayMode\n");
- ddrval = pDD->SetDisplayMode (800, 600, 32, 0, 0);
+ hResult = DirectDraw->SetDisplayMode (800, 600, 32, 0, 0);
- MessageBox(0,DDErrorString(ddrval), "DDraw->SetDisplayMode", 0);
+ MessageBox(0,DDErrorString(hResult), "DDraw->SetDisplayMode", 0);
- // create the primary surface
+ // Create the primary surface
memset(&ddsd, 0, sizeof(DDSURFACEDESC2));
ddsd.dwSize = sizeof(DDSURFACEDESC2);
memset(&ddsd, 0, sizeof(DDSURFACEDESC2));
ddsd.dwSize = sizeof(DDSURFACEDESC2);
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
OutputDebugString("=> DDraw->CreateSurface\n");
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
OutputDebugString("=> DDraw->CreateSurface\n");
- ddrval = pDD->CreateSurface(&ddsd, &lpddsPrimary, NULL);
+ hResult = DirectDraw->CreateSurface(&ddsd, &FrontBuffer, NULL);
+
+ if (hResult != DD_OK)
+ {
+ MessageBox(0,DDErrorString(hResult), "DDraw->CreateSurface", 0);
+ return 0;
+ }
+
+ // Set up the clipper
+ OutputDebugString("=> DDraw->CreateClipper\n");
+ hResult = DirectDraw->CreateClipper(0,&Clipper,NULL);
+ if (hResult != DD_OK)
- MessageBox(0,DDErrorString(ddrval), "DDraw->CreateSurface", 0);
+ MessageBox(0,DDErrorString(hResult), "DDraw->CreateSurface", 0);
+ OutputDebugString("=> Clipper->SetHWnd\n");
+ hResult = Clipper->SetHWnd(0,hwnd);
+ if (hResult != DD_OK)
+ {
+ MessageBox(0,DDErrorString(hResult), "Clipper->SetHWnd", 0);
+ return 0;
+ }
+
+ OutputDebugString("=> Suface->SetClipper\n");
+ hResult = FrontBuffer->SetClipper(Clipper);
+ if (hResult != DD_OK)
+ {
+ MessageBox(0,DDErrorString(hResult), "FrontBuffer->SetClipper", 0);
+ return 0;
+ }
+
return true;
}
void Draw (void)
{
return true;
}
void Draw (void)
{
- // make the windows or hole screen green
- RECT rect;
- GetWindowRect(hwnd, &rect);
+ // Make the fronbuffer pink
DDBLTFX ddbltfx;
ddbltfx.dwSize = sizeof(DDBLTFX);
DDBLTFX ddbltfx;
ddbltfx.dwSize = sizeof(DDBLTFX);
- ddbltfx.dwFillColor = RGB(0, 255, 0);
+ ddbltfx.dwFillColor = RGB(255, 0, 255);
OutputDebugString("=> Surface->Blt (DDBLT_COLORFILL)\n");
OutputDebugString("=> Surface->Blt (DDBLT_COLORFILL)\n");
-
- if(fullscreen)
- lpddsPrimary->Blt(NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
- else
- lpddsPrimary->Blt(&rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
+
+ FrontBuffer->Blt(NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
- if (lpddsPrimary != NULL)
- OutputDebugString("=> Surface->Release\n");
- lpddsPrimary->Release();
- lpddsPrimary = NULL;
+ OutputDebugString("=> Clipper->Release\n");
+ Clipper->Release();
+ Clipper = NULL;
+ if (FrontBuffer != NULL)
+ {
+ OutputDebugString("=> Surface->Release\n");
+ FrontBuffer->Release();
+ FrontBuffer = NULL;
+ }
+ if (DirectDraw != NULL)
{
OutputDebugString("=> DDraw->Release\n");
{
OutputDebugString("=> DDraw->Release\n");
- pDD->Release();
- pDD = NULL;
+ DirectDraw->Release();
+ DirectDraw = NULL;
MSG msg;
WNDCLASS wndclass;
MSG msg;
WNDCLASS wndclass;
- // ask
- fullscreen = MessageBox(0, "Do you want to me to run in fullscreen ?", 0, MB_YESNO) == IDYES;
+ Fullscreen = MessageBox(0, "Do you want to me to run in Fullscreen ?", 0, MB_YESNO) == IDYES;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject (LTGRAY_BRUSH);
wndclass.lpszMenuName = NULL;
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 = CreateWindow("ddrawdemo",
+ HWND hwnd = CreateWindow("DDrawDemo",
"ReactOS DirectDraw Demo",
"ReactOS DirectDraw Demo",
+ Fullscreen ? WS_POPUP :WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
800,
CW_USEDEFAULT,
CW_USEDEFAULT,
800,
hInst, NULL);
// Inizalize Ddraw
hInst, NULL);
// Inizalize Ddraw
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
}
- // Go into main loop
- while (running)
+ // Main loop
+ while (Running)
Draw();
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
Draw();
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
switch (wParam)
{
case VK_ESCAPE:
switch (wParam)
{
case VK_ESCAPE:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return DefWindowProc (hwnd, message, wParam, lParam);
}
-char* DDErrorString (HRESULT hr)
+PCHAR DDErrorString (HRESULT hResult)
{
case DD_OK: return "DD_OK";
case DDERR_ALREADYINITIALIZED: return "DDERR_ALREADYINITIALIZED";
{
case DD_OK: return "DD_OK";
case DDERR_ALREADYINITIALIZED: return "DDERR_ALREADYINITIALIZED";
+++ /dev/null
-
-LPDIRECTDRAW7 pDD;
-LPDIRECTDRAWSURFACE7 lpddsPrimary; //, lpddsBack;
-HRESULT ddrval;
-HWND hwnd;
-
-bool running, fullscreen;
-
-void ddRelease ();
-char* DDErrorString (HRESULT hr);
-LONG WINAPI WndProc (HWND hwnd, UINT message, UINT wParam, LONG lParam);
-
-extern "C" bool HookAPICalls();