I have two questions:
First, I'm trying to get the following program to work. I keep getting an error message that the "DDRAW.LIB" include file cannot be found. I did go into TOOLS/OPTIONS to specify the WINDOWS/SYSTEM directory where the Ddraw.dll is located. What am I doing wrong? The compiler still can't find DDRAW.LIB.
Second, I can see in the program below that there are definitions that need to go into a header file, but I'm not sure what to place in the header file. COuld someone please help me out with this? Thanks much, Dave
<br />
<br />
<br />
#define WIN32_LEAN_AND_MEAN // make sure certain headers are included correctly<br />
<br />
#include windows.h
#include windowsx.h
#include mmsystem.h
#include ddraw.h
<br />
#include stdlib.h
#include stdio.h<br />
#include math.h<br />
#include float.h<br />
<br />
<br />
#define WINDOW_CLASS_NAME "WINDOW_CLASS" // this is the name of the window class<br />
<br />
<br />
#define SCREEN_WIDTH 640 // the width of the viewing surface<br />
#define SCREEN_HEIGHT 480 // the height of the viewing surface<br />
#define SCREEN_BPP 8 // the bits per pixel<br />
#define MAX_COLORS 256 // the maximum number of colors<br />
<br />
<br />
typedef unsigned char UCHAR;<br />
<br />
<br />
<br />
#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)<br />
#define KEY_UP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)<br />
<br />
<br />
int DD_Init(HWND hwnd);<br />
int DD_Shutdown(void);<br />
int Set_Pal_Entry(int index, int red, int green, int blue);<br />
<br />
void Game_Init(void);<br />
void Game_Main(void);<br />
void Game_Shutdown(void);<br />
<br />
<br />
LPDIRECTDRAW lpdd = NULL;
LPDIRECTDRAWSURFACE lpddsprimary = NULL;
LPDIRECTDRAWPALETTE lpddpal = NULL;
PALETTEENTRY color_palette[256];
DDSURFACEDESC ddsd;
DDSCAPS ddscaps;
HRESULT ddrval;
HWND main_window_handle = NULL;
UCHAR *video_buffer = NULL;
<br />
<br />
<br />
<br />
int DD_Init(HWND hwnd)<br />
{<br />
<br />
int index;
<br />
if (DirectDrawCreate(NULL,&lpdd,NULL)!=DD_OK)<br />
{<br />
DD_Shutdown();<br />
return(0);<br />
}
<br />
if (lpdd->SetCooperativeLevel(hwnd, DDSCL_ALLOWREBOOT | DDSCL_EXCLUSIVE |<br />
DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX)!=DD_OK)<br />
{<br />
DD_Shutdown();<br />
return(0);<br />
}
<br />
if (lpdd->SetDisplayMode(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_BPP)!=DD_OK)<br />
{<br />
DD_Shutdown();<br />
return(0);<br />
}
<br />
ddsd.dwSize = sizeof(ddsd);<br />
ddsd.dwFlags = DDSD_CAPS;<br />
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;<br />
<br />
if<br />
(lpdd->CreateSurface(&ddsd,&lpddsprimary,NULL)!=DD_OK)<br />
{<br />
DD_Shutdown();<br />
return(0);<br />
}
<br />
<br />
memset(color_palette,0,256*sizeof(PALETTEENTRY));<br />
<br />
for (index=0; index<256; index++)<br />
{<br />
if ((index / 64)==0)<br />
{<br />
color_palette[index].peRed = index*4;<br />
color_palette[index].peGreen = index*4;<br />
color_palette[index].peBlue = index*4;<br />
}
else<br />
if ((index / 64)==1)<br />
color_palette[index].peRed = (index%64)*4;<br />
else<br />
if ((index / 64)==2) <br />
color_palette[index].peGreen = (index%64)*4;<br />
else<br />
if ((index / 64)==3)<br />
color_palette[index].peBlue = (index%64)*4;<br />
<br />
color_palette[index].peFlags = PC_NOCOLLAPSE;<br />
<br />
}
<br />
if (lpdd->CreatePalette((DDPCAPS_8BIT | DDPCAPS_INITIALIZE),color_palette,&lpddpal,NULL)!=DD_OK)<br />
{<br />
DD_Shutdown();<br />
return(0);<br />
}
<br />
lpddsprimary->SetPalette(lpddpal);<br />
<br />
return(1);<br />
<br />
}
<br />
<br />
int DD_Shutdown(void)<br />
{<br />
<br />
if (lpdd)<br />
{<br />
if(lpddsprimary)<br />
{<br />
lpddsprimary->Release();<br />
lpddsprimary = NULL;<br />
}
<br />
lpdd->Release();<br />
lpdd = NULL;<br />
<br />
return(1);<br />
<br />
}
else<br />
return(0);<br />
<br />
}
<br />
<br />
int Set_Pal_Entry(int index, int red, int green, int blue)<br />
{<br />
<br />
PALETTEENTRY color;
<br />
color.peRed = (BYTE)red;<br />
color.peGreen = (BYTE)green;<br />
color.peBlue = (BYTE)blue;<br />
color.peFlags = PC_NOCOLLAPSE;<br />
<br />
lpddpal->SetEntries(0,index,1,&color);<br />
<br />
memcpy(&color_palette[index],<br />
&color,<br />
sizeof(PALETTEENTRY));<br />
<br />
return(1);<br />
<br />
}
<br />
<br />
LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)<br />
{<br />
<br />
HDC hdc;
PAINTSTRUCT ps;
<br />
<br />
switch(msg)<br />
{ <br />
case WM_CREATE:<br />
{<br />
return(0);<br />
} break;<br />
<br />
case WM_PAINT:<br />
{<br />
hdc = BeginPaint(hwnd,&ps); <br />
EndPaint(hdc,&ps);<br />
<br />
return(0);<br />
} break;<br />
<br />
case WM_DESTROY:<br />
{<br />
PostQuitMessage(0);<br />
return(0);<br />
} break;<br />
<br />
default:break;<br />
<br />
}
<br />
return (DefWindowProc(hwnd, msg, wparam, lparam));<br />
<br />
}
<br />
<br />
int WINAPI WinMain( HINSTANCE hinstance,<br />
HINSTANCE hprevinstance,<br />
LPSTR lpcmdline,<br />
int ncmdshow)<br />
{<br />
WNDCLASSEX winclass;
HWND hwnd;
MSG msg;
<br />
<br />
winclass.cbSize = sizeof(WNDCLASSEX);<br />
winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;<br />
winclass.lpfnWndProc = WindowProc;<br />
winclass.cbClsExtra = 0;<br />
winclass.cbWndExtra = 0;<br />
winclass.hInstance = hinstance;<br />
winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);<br />
winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);<br />
winclass.hCursor = LoadCursor(NULL, IDC_ARROW);<br />
winclass.hbrBackground = GetStockObject(BLACK_BRUSH);<br />
winclass.lpszMenuName = NULL;<br />
winclass.lpszClassName = WINDOW_CLASS_NAME;<br />
<br />
if (!RegisterClassEx(&winclass))<br />
return(0);<br />
<br />
if (!(hwnd = CreateWindowEx(WS_EX_TOPMOST,<br />
WINDOW_CLASS_NAME,
"You can't See This!",
WS_VISIBLE | WS_POPUP,<br />
0,0,
GetSystemMetrics(SM_CXSCREEN),<br />
GetSystemMetrics(SM_CYSCREEN), <br />
NULL,
NULL,
hinstance,
NULL)))
return(0);<br />
<br />
ShowCursor(0);<br />
<br />
main_window_handle = hwnd;<br />
<br />
if (!DD_Init(hwnd))<br />
{<br />
DestroyWindow(hwnd);<br />
return(0);<br />
}
<br />
Game_Init();<br />
<br />
while(1)<br />
{<br />
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))<br />
{ <br />
if (msg.message == WM_QUIT)<br />
break;<br />
<br />
TranslateMessage(&msg);<br />
<br />
DispatchMessage(&msg);<br />
}
else<br />
{<br />
<br />
memset(&ddsd,0,sizeof(ddsd));<br />
ddsd.dwSize = sizeof(ddsd);<br />
lpddsprimary->Lock(NULL,&ddsd,DDLOCK_SURFACEMEMORYPTR,NULL);<br />
video_buffer = (UCHAR *)ddsd.lpSurface;<br />
<br />
Game_Main();<br />
<br />
lpddsprimary->Unlock(ddsd.lpSurface);<br />
<br />
}
<br />
}
<br />
DD_Shutdown();<br />
<br />
Game_Shutdown();<br />
<br />
return(msg.wParam);<br />
<br />
}
<br />
<br />
void Game_Init(void)<br />
{<br />
}
<br />
<br />
void Game_Shutdown(void)<br />
{<br />
}
<br />
<br />
void Game_Main(void)<br />
{<br />
<br />
static int px = SCREEN_WIDTH/2,
py = SCREEN_HEIGHT/2,<br />
color = 0;
<br />
<br />
"VK_"<br />
scan codes<br />
<br />
if (KEY_DOWN(VK_ESCAPE))<br />
PostMessage(main_window_handle,WM_CLOSE,0,0);
<br />
if (KEY_DOWN(VK_RIGHT))<br />
if (++px>SCREEN_WIDTH-8) px=8;<br />
<br />
if (KEY_DOWN(VK_LEFT))<br />
if (--px<8) px=SCREEN_WIDTH-8;<br />
<br />
if (KEY_DOWN(VK_UP))<br />
if (--py<8) py=SCREEN_HEIGHT-8;<br />
<br />
if (KEY_DOWN(VK_DOWN))<br />
if (++py>SCREEN_HEIGHT-8) py=8;<br />
<br />
if (KEY_DOWN('C'))<br />
{<br />
if (++color>=4)<br />
color=0;<br />
Sleep(100);<br />
}
<br />
for (int pixels=0; pixels<32; pixels++)<br />
video_buffer[(px-4+rand()%8)+(py-4+rand()%8)*SCREEN_WIDTH] = (color*64)+rand()%64;<br />
<br />
<br />
Sleep(14);
<br />
<br />
}
"The man who reads nothing is better educated than the man who reads nothing but newspapers."- Thomas Jefferson
|