• Advertisement
Sign in to follow this  

y is the directx window not compiling

This topic is 4588 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi i am very new to directx and today i have just come to compile the first directx window i have done and i get errors i stop one by saying dont use pre compiled headers. but then i get cannot find iostream. h and that is because i have stopped precompiled headers so i delete that but then i get aload of errors and it is really pissing me off (pardon my french) so pelase can someone help me because everytime i come to directx all i get is problems then in the end i just give up but this time i dont want to i would be very thankfull for a fast reply as i am going on holiday in 5 hours and i would like to get an answer so i can put my mind at rest the code is
// PROG8_2.CPP - Creates a DirectDraw object and sets cooperation

// INCLUDES ///////////////////////////////////////////////
#define WIN32_LEAN_AND_MEAN  
#define INITGUID

#include <windows.h>   // include important windows stuff
#include <windowsx.h> 
#include <mmsystem.h>
#include <iostream.h> // include important C/C++ stuff
#include <conio.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <math.h>
#include <io.h>
#include <fcntl.h>

#include <ddraw.h>  // directX includes

// DEFINES ////////////////////////////////////////////////

// defines for windows 
#define WINDOW_CLASS_NAME "WINXCLASS"  // class name

#define WINDOW_WIDTH  320              // size of window
#define WINDOW_HEIGHT 200

// MACROS /////////////////////////////////////////////////

// these read the keyboard asynchronously
#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEY_UP(vk_code)   ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)

// PROTOTYPES /////////////////////////////////////////////

int Game_Init(void *parms=NULL);
int Game_Shutdown(void *parms=NULL);
int Game_Main(void *parms=NULL);

// GLOBALS ////////////////////////////////////////////////

HWND main_window_handle = NULL; // save the window handle
HINSTANCE main_instance = NULL; // save the instance
char buffer[80];                // used to print text
LPDIRECTDRAW7 lpdd;   // pointer to direct draw object

// FUNCTIONS //////////////////////////////////////////////

						    UINT msg, 
                            WPARAM wparam, 
                            LPARAM lparam)
// this is the main message handler of the system
PAINTSTRUCT	ps;		   // used in WM_PAINT
HDC			hdc;	   // handle to a device context

// what is the message 
	case WM_CREATE: 
		// do initialization stuff here
		} break;

    case WM_PAINT:
         // start painting
         hdc = BeginPaint(hwnd,&ps);

         // end painting
        } break;

	case WM_DESTROY: 
		// kill the application			
		} break;


    } // end switch

// process any messages that we didn't take care of 
return (DefWindowProc(hwnd, msg, wparam, lparam));

} // end WinProc

// WINMAIN ////////////////////////////////////////////////

int WINAPI WinMain(	HINSTANCE hinstance,
					HINSTANCE hprevinstance,
					LPSTR lpcmdline,
					int ncmdshow)

WNDCLASS winclass;	// this will hold the class we create
HWND	 hwnd;		// generic window handle
MSG		 msg;		// generic message
HDC      hdc;       // generic dc
PAINTSTRUCT ps;     // generic paintstruct

// first fill in the window class stucture
winclass.style			= CS_DBLCLKS | CS_OWNDC | 
                          CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc	= WindowProc;
winclass.cbClsExtra		= 0;
winclass.cbWndExtra		= 0;
winclass.hInstance		= hinstance;
winclass.hIcon			= LoadIcon(NULL, IDI_APPLICATION);
winclass.hCursor		= LoadCursor(NULL, IDC_ARROW);
winclass.hbrBackground	= (HBRUSH)GetStockObject(BLACK_BRUSH);
winclass.lpszMenuName	= NULL; 
winclass.lpszClassName	= WINDOW_CLASS_NAME;

// register the window class
if (!RegisterClass(&winclass))

// create the window
if (!(hwnd = CreateWindow(WINDOW_CLASS_NAME, // class
						  "WinX Game Console",	 // title
					 	  0,0,	   // x,y
						  WINDOW_WIDTH,  // width
                          WINDOW_HEIGHT, // height
						  NULL,	   // handle to parent 
						  NULL,	   // handle to menu
						  hinstance,// instance
						  NULL)))	// creation parms

// save the window handle and instance in a global
main_window_handle = hwnd;
main_instance      = hinstance;

// perform all game console specific initialization

// enter main event loop
	if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
		// test if this is a quit
        if (msg.message == WM_QUIT)
		// translate any accelerator keys

		// send the message to the window proc
		} // end if
    // main game processing goes here

	} // end while

// shutdown game and release all resources

// return to Windows like this

} // end WinMain


int Game_Init(void *parms)
// this function is where you do all the initialization 
// for your game

// create object and test for error
if (DirectDrawCreateEx(NULL, (void **)&lpdd, IID_IDirectDraw7, NULL)!=DD_OK)

// set cooperation level to windowed mode normal
if ((lpdd->SetCooperativeLevel(main_window_handle,DDSCL_NORMAL))!=DD_OK)

// return success
} // end Game_Init


int Game_Shutdown(void *parms)
// this function is where you shutdown your game and
// release all resources that you allocated

// release the directdraw object
if (lpdd!=NULL)

// return success
} // end Game_Shutdown


int Game_Main(void *parms)
// this is the workhorse of your game it will be called
// continuously in real-time this is like main() in C
// all the calls for you game go here!

// your code goes here

// return success
} // end Game_Main

thanks for help in advance from mark

Share this post

Link to post
Share on other sites

I know this isn't answering your actual question, but it seems like your ultimate goal is to learn DirectX, so I have some suggestions for that.

First, ditch DirectDraw and go with Direct3D. I, and most people, find D3D alot easier to use than DirectDraw. Plus DD is no longer being updated, and hasn't been since DX7 (I belive).

I would also suggest picking up Focus on: 2D in Direct3D. It is the best book I have found so far on learning DirectX graphics from scratch, and will have you making 2.5D apps in no time.

Oh and when posting large chunks of code like that you should try to use the 'source' tags. You'll get much happier responses that way [grin]

Good Luck,
Matt Hughson

Share this post

Link to post
Share on other sites
o rite it is source not code sorry about that and i will try to get some info on direct3D never new i could do 2d apps in that so i will focus on that more do you no of any sites that could help me

Share this post

Link to post
Share on other sites
Andy Pike
Drunken Hyena
Ultimate Game Programming

Those are the big 3 in my opinion, but I still think that book I suggested is your best bet. You should also keep in mind, none of these sites focus specifically on 2D, but I think after you get some textured triangles on the screen you will see how you can make a 2D game with Direct3D.

Matt Hughson

Share this post

Link to post
Share on other sites
Check your project settings.. It's those stdafx files.. So, rightclick on your project, and goto the C/C++ stuff, then the precompiled header stuff, and try automaticly generate, or not using precompiled headers..

Share this post

Link to post
Share on other sites
yea i have tried that but i still get an error of

fatal error C1083: Cannot open include file: 'iostream.h': No such file or directory

on this line
#include <iostream.h> // include important C/C++ stuff

and i no it is something to do with this darn compiled headers thing but i just cant work it out fully so any more suggestions would be greatfully apprechiated

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement