mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 05:22:57 +00:00
- Use clipper so we can use a normal instead of a popup window
- Fix my old coding style and get rid of main.h - Change he color to pink for alternation svn path=/trunk/; revision=23172
This commit is contained in:
parent
d1ecea1424
commit
6eca31ac9d
2 changed files with 87 additions and 66 deletions
|
@ -1,50 +1,59 @@
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <ddraw.h>
|
#include <ddraw.h>
|
||||||
#include "main.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 (void)
|
bool Init (HWND hwnd)
|
||||||
{
|
{
|
||||||
DDSURFACEDESC2 ddsd;
|
DDSURFACEDESC2 ddsd;
|
||||||
|
HRESULT hResult;
|
||||||
|
|
||||||
// Create the main object
|
// Create the main object
|
||||||
OutputDebugString("=> DirectDrawCreateEx\n");
|
OutputDebugString("=> DirectDrawCreateEx\n");
|
||||||
ddrval = DirectDrawCreateEx(NULL, (VOID**)&pDD, IID_IDirectDraw7, NULL);
|
hResult = DirectDrawCreateEx(NULL, (VOID**)&DirectDraw, IID_IDirectDraw7, NULL);
|
||||||
|
|
||||||
if (ddrval != DD_OK)
|
if (hResult != DD_OK)
|
||||||
{
|
{
|
||||||
MessageBox(0,DDErrorString(ddrval), "DirectDrawCreateEx", 0);
|
MessageBox(0,DDErrorString(hResult), "DirectDrawCreateEx", 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set fullscreen or not
|
// Set Fullscreen or windowed mode
|
||||||
OutputDebugString("=> DDraw->SetCooperativeLevel\n");
|
OutputDebugString("=> DDraw->SetCooperativeLevel\n");
|
||||||
|
|
||||||
if(fullscreen)
|
if(Fullscreen)
|
||||||
ddrval = pDD->SetCooperativeLevel (hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
|
hResult = DirectDraw->SetCooperativeLevel (hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
|
||||||
else
|
else
|
||||||
ddrval = pDD->SetCooperativeLevel (hwnd, DDSCL_NORMAL);
|
hResult = DirectDraw->SetCooperativeLevel (hwnd, DDSCL_NORMAL);
|
||||||
|
|
||||||
if (ddrval != DD_OK)
|
if (hResult != DD_OK)
|
||||||
{
|
{
|
||||||
MessageBox(0,DDErrorString(ddrval), "DDraw->SetCooperativeLevel", 0);
|
MessageBox(0,DDErrorString(hResult), "DDraw->SetCooperativeLevel", 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the new resolution
|
// Set the new resolution
|
||||||
if(fullscreen)
|
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);
|
||||||
|
|
||||||
if (ddrval != DD_OK)
|
if (hResult != DD_OK)
|
||||||
{
|
{
|
||||||
MessageBox(0,DDErrorString(ddrval), "DDraw->SetDisplayMode", 0);
|
MessageBox(0,DDErrorString(hResult), "DDraw->SetDisplayMode", 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// create the primary surface
|
// Create the primary surface
|
||||||
memset(&ddsd, 0, sizeof(DDSURFACEDESC2));
|
memset(&ddsd, 0, sizeof(DDSURFACEDESC2));
|
||||||
|
|
||||||
ddsd.dwSize = sizeof(DDSURFACEDESC2);
|
ddsd.dwSize = sizeof(DDSURFACEDESC2);
|
||||||
|
@ -52,49 +61,76 @@ bool Init (void)
|
||||||
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
|
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
|
||||||
|
|
||||||
OutputDebugString("=> DDraw->CreateSurface\n");
|
OutputDebugString("=> DDraw->CreateSurface\n");
|
||||||
ddrval = pDD->CreateSurface(&ddsd, &lpddsPrimary, NULL);
|
hResult = DirectDraw->CreateSurface(&ddsd, &FrontBuffer, NULL);
|
||||||
|
|
||||||
if (ddrval != DD_OK)
|
if (hResult != DD_OK)
|
||||||
{
|
{
|
||||||
MessageBox(0,DDErrorString(ddrval), "DDraw->CreateSurface", 0);
|
MessageBox(0,DDErrorString(hResult), "DDraw->CreateSurface", 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set up the clipper
|
||||||
|
OutputDebugString("=> DDraw->CreateClipper\n");
|
||||||
|
|
||||||
|
hResult = DirectDraw->CreateClipper(0,&Clipper,NULL);
|
||||||
|
if (hResult != DD_OK)
|
||||||
|
{
|
||||||
|
MessageBox(0,DDErrorString(hResult), "DDraw->CreateSurface", 0);
|
||||||
|
return 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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Draw (void)
|
void Draw (void)
|
||||||
{
|
{
|
||||||
// make the windows or hole screen green
|
// Make the fronbuffer pink
|
||||||
RECT rect;
|
|
||||||
GetWindowRect(hwnd, &rect);
|
|
||||||
|
|
||||||
DDBLTFX ddbltfx;
|
DDBLTFX ddbltfx;
|
||||||
ddbltfx.dwSize = sizeof(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)
|
FrontBuffer->Blt(NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
|
||||||
lpddsPrimary->Blt(NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
|
|
||||||
else
|
|
||||||
lpddsPrimary->Blt(&rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CleanUp (void)
|
void CleanUp (void)
|
||||||
{
|
{
|
||||||
if (lpddsPrimary != NULL)
|
if (Clipper != NULL)
|
||||||
{
|
{
|
||||||
OutputDebugString("=> Surface->Release\n");
|
OutputDebugString("=> Clipper->Release\n");
|
||||||
lpddsPrimary->Release();
|
Clipper->Release();
|
||||||
lpddsPrimary = NULL;
|
Clipper = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pDD != 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();
|
DirectDraw->Release();
|
||||||
pDD = NULL;
|
DirectDraw = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,10 +140,9 @@ int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst,
|
||||||
MSG msg;
|
MSG msg;
|
||||||
WNDCLASS wndclass;
|
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;
|
|
||||||
|
|
||||||
// create windnow
|
// Create windnow
|
||||||
wndclass.style = CS_HREDRAW | CS_VREDRAW;
|
wndclass.style = CS_HREDRAW | CS_VREDRAW;
|
||||||
wndclass.lpfnWndProc = WndProc;
|
wndclass.lpfnWndProc = WndProc;
|
||||||
wndclass.cbClsExtra = 0;
|
wndclass.cbClsExtra = 0;
|
||||||
|
@ -117,13 +152,13 @@ int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst,
|
||||||
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
|
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
|
||||||
wndclass.hbrBackground = (HBRUSH)GetStockObject (LTGRAY_BRUSH);
|
wndclass.hbrBackground = (HBRUSH)GetStockObject (LTGRAY_BRUSH);
|
||||||
wndclass.lpszMenuName = NULL;
|
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",
|
||||||
WS_POPUP,
|
Fullscreen ? WS_POPUP :WS_OVERLAPPEDWINDOW,
|
||||||
CW_USEDEFAULT,
|
CW_USEDEFAULT,
|
||||||
CW_USEDEFAULT,
|
CW_USEDEFAULT,
|
||||||
800,
|
800,
|
||||||
|
@ -132,18 +167,18 @@ int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst,
|
||||||
hInst, NULL);
|
hInst, NULL);
|
||||||
|
|
||||||
// Inizalize Ddraw
|
// Inizalize Ddraw
|
||||||
if(Init())
|
if(Init(hwnd))
|
||||||
{
|
{
|
||||||
running = true;
|
Running = true;
|
||||||
|
|
||||||
ShowWindow(hwnd, nCmdShow);
|
ShowWindow(hwnd, nCmdShow);
|
||||||
UpdateWindow(hwnd);
|
UpdateWindow(hwnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Go into main loop
|
// Main loop
|
||||||
while (running)
|
while (Running)
|
||||||
{
|
{
|
||||||
if(fullscreen)
|
if(Fullscreen)
|
||||||
Draw();
|
Draw();
|
||||||
|
|
||||||
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
|
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
|
||||||
|
@ -154,7 +189,6 @@ int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// the end
|
|
||||||
CleanUp();
|
CleanUp();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -168,7 +202,7 @@ LONG WINAPI WndProc (HWND hwnd, UINT message,
|
||||||
{
|
{
|
||||||
case WM_PAINT:
|
case WM_PAINT:
|
||||||
{
|
{
|
||||||
if(!fullscreen)
|
if(!Fullscreen)
|
||||||
Draw();
|
Draw();
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
@ -177,7 +211,7 @@ LONG WINAPI WndProc (HWND hwnd, UINT message,
|
||||||
switch (wParam)
|
switch (wParam)
|
||||||
{
|
{
|
||||||
case VK_ESCAPE:
|
case VK_ESCAPE:
|
||||||
running=false;
|
Running=false;
|
||||||
return 0;
|
return 0;
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
|
@ -192,9 +226,9 @@ LONG WINAPI WndProc (HWND hwnd, UINT message,
|
||||||
return DefWindowProc (hwnd, message, wParam, lParam);
|
return DefWindowProc (hwnd, message, wParam, lParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* DDErrorString (HRESULT hr)
|
PCHAR DDErrorString (HRESULT hResult)
|
||||||
{
|
{
|
||||||
switch (hr)
|
switch (hResult)
|
||||||
{
|
{
|
||||||
case DD_OK: return "DD_OK";
|
case DD_OK: return "DD_OK";
|
||||||
case DDERR_ALREADYINITIALIZED: return "DDERR_ALREADYINITIALIZED";
|
case DDERR_ALREADYINITIALIZED: return "DDERR_ALREADYINITIALIZED";
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
|
|
||||||
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();
|
|
Loading…
Add table
Add a link
Reference in a new issue