Original Post
I use the ddraw tutorials from borland and typed in the code into my own project and its just like the other one, I did this just so I could learn to use it, and when it runs, it says that some of my variables are not declared...can somebody tell me whats wrong..I''ll show you the code and put *** by the basic ones that it says arent declared.
//---------------------------------------------------------------------------
#include <vcl.h>
#include <ddraw.h>
#pragma hdrstop
#include "main.h"
//---------------------------------------------------------------------------
#pragma resource "*.dfm"
#define TIMER_ID 1
#define TIMER_RATE 500
TFormMain *FormMain;
//---------------------------------------------------------------------------
__fastcall TFormMain::TFormMain(TComponent* Owner)
: TForm(Owner)
{
lpDD = NULL; ***
phase = 0; ***
bActive = false; ***
FrontMsg = "Front buffer (F12 or Esc to Quit)"; ***
BackMsg = "Back buffer (F12 or Esc to Quit)"; ***
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::FormDestroy(TObject *Sender)
{
if(lpDD != NULL){
if(lpDDSPrimary != NULL){
lpDDSPrimary -> Release();
lpDDSPrimary = NULL;
}
lpDD -> Release();
lpDD = NULL;
}
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::start()
{
HRESULT ddrval;
DDSURFACEDESC ddsd;
DDSCAPS ddscaps;
HDC DC;
char buf[256];
ddrval = DirectDrawCreate(NULL, &lpDD, NULL);
if(ddrval == DD_OK){
ddrval = lpDD -> SetCooperativeLevel(Handle, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
if(ddrval == DD_OK){
ddrval = lpDD -> SetDisplayMode(640, 480, 8);
if(ddrval == DD_OK){
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
DDSCAPS_FLIP |
DDSCAPS_COMPLEX;
ddsd.dwBackBufferCount = 1;
ddrval = lpDD -> CreateSurface(&ddsd, &lpDDSPrimary, NULL);
if(ddrval == DD_OK){
ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
ddrval = lpDDSPrimary -> GetAttachedSurface(&dscaps,
&lpDDSBack);
if(ddrval == DD_OK){
//DRAWING TEXT
if(lpDDSPrimary -> GetDC(&DC) == DD_OK){
SetBkColor(DC, RGB(0, 0, 255));
SetTextColor(DC, RGB(255, 225, 0));
TextOut(DC, 0,0, FrontMsg.c_str(), FrontMsg.Length());
lpDDSPrimary -> ReleaseDC(DC);
}
if(lpDDSPrimary -> GetDC(&DC) == DD_OK){
SetBkColor(DC, RGB(0, 0, 255));
SetTextColor(DC, RGB(255, 225, 0));
TextOut(DC, 0,0, BackMsg.c_str(), BackMsg.Length());
lpDDSBack -> ReleaseDC(DC);
}
Timer1 -> Enabled = true;
bActive = true;
return;
}
}
}
}
}
wsprintf(buf, "Direct Draw Init Failed (%801x)\n", ddrval);
MessageBox(Handle, buf, "Error", MB_OK);
Close();
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::FormKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
switch (Key){
case VK_F3:
start();
break;
case VK_ESCAPE:
case VK_F12:
Close();
break;
}
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::FormPaint(TObject *Sender)
{
RECT rc;
SIZE size;
char szMsg[] = "Page Flipping Test: Press F3 to start, F12 or Esc to Exit";
if(!bActive){
HDC DC = GetDC(Handle);
rc = GetClientRect();
GetTextExtentPoint(DC, szMsg, lstrlen(szMsg), &size);
SetBkColor(DC, RGB(0, 0, 0));
SetTextColor(DC, RGB(255, 255, 0));
TextOut(DC, (rc.right - size.cx)/2, (rc.bottom - size.cy)/2, szMsg, sizeof(szMsg)-1);
ReleaseDC(Handle, DC);
}
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::Timer1Timer(TObject *Sender)
{
HDC DC;
if(lpDDSBack -> GetDC(&DC) == DD_OK){
if(phase){
SetBkColor(DC, RGB(0, 0, 255));
SetTextColor(DC, RGB(255, 225, 0));
TextOut(DC, 0,0, FrontMsg.c_str(), FrontMsg.Length());
phase = 0;
}
else{
SetBkColor(DC, RGB(0, 0, 255));
SetTextColor(DC, RGB(255, 225, 0));
TextOut(DC, 0,0, BackMsg.c_str(), BackMsg.Length());
phase = 1;
}
lpDDSBack -> ReleaseDC(DC);
}
while(1){
HRESULT ddrval;
ddrval = lpDDSPrimary -> Flip(NULL, 0);
if(ddrval == DD_OK)
break;
if(ddrval == DDERR_SURFACELOST){
ddrval = lpDDSPrimary -> Restore();
if(ddrval != DD_OK)
break;
}
if(ddrval != DDERR_WASSTILLDRAWING)
break;
}
}
//---------------------------------------------------------------------------
thats it, somebody help plz...!!...