Why does this app not work??

Started by
-1 comments, last by zeroshot 22 years, 3 months ago
    

#define WIN32_LEAN_AND_MEAN

#include < windows.h >
#include < windowsx.h >
#include < stdio.h >
#include < ddraw.h >

#include "ddutil.h"
#include "timer.h" 

#define image_count 3

BOOL ActiveApp;


LPDIRECTDRAW7 lpDD ;
LPDIRECTDRAWSURFACE7 lpPrimary;
LPDIRECTDRAWSURFACE7 lpBack;

// Array of images now for the ship

LPDIRECTDRAWSURFACE7 lpSprites[ image_count ] = { NULL } ;

char bitmaps[ image_count ][ 256 ] = { "ship1.bmp" , "ship2.bmp" , "ship3.bmp" };

int cur_image = 0;


BOOL Init_DDraw( HWND hwnd );
void Cleanup_DDraw( );
BOOL RestoreSurfaces( );
BOOL PageFlip( );
BOOL ComposeFrame( );
BOOL ProcessFrame( );

long CALLBACK WindowProc( HWND , UINT , WPARAM , LPARAM );
int WINAPI WinMain( HINSTANCE , HINSTANCE , LPSTR , int );


void GameMain( ){ }


HWND CreateGameWindow( char * , HINSTANCE ); 

BOOL Init_DDraw( HWND hwnd )
{
	if ( FAILED( DirectDrawCreateEx( NULL , (void **)&lpDD , IID_IDirectDraw7 , NULL ) ) ) 
		return FALSE;

	

	if ( FAILED( lpDD->SetCooperativeLevel( hwnd , DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN  ) ) )
		return FALSE;

	if ( FAILED( lpDD->SetDisplayMode( 800, 600, 16 , 0 , 0 ) ) )
		return FALSE;

	
	DDSURFACEDESC2 ddsd;
	DDSCAPS2 ddscaps;

	
	ddsd.dwSize = sizeof( DDSURFACEDESC2 );

	ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT ;
	
	ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX ;



	ddsd.dwBackBufferCount = 1;
	if ( FAILED( lpDD->CreateSurface( &ddsd , &lpPrimary , NULL ) ) )
		return FALSE;


	ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
	

	if ( FAILED( lpPrimary->GetAttachedSurface( &ddscaps , &lpBack ) ) ) 
		return FALSE;

	return TRUE ;
}

void Cleanup_DDraw( )
{
	if ( lpBack ){
		lpBack->Release( );
		lpBack = NULL ;
	}

	if ( lpPrimary ){
		lpPrimary->Release( );
		lpPrimary = NULL;
	}

	if ( lpDD ){
		lpDD->Release( );
		lpDD = NULL ;
	}

	
}


HWND CreateGameWindow( char *name , HINSTANCE hInstance )
{
	WNDCLASS wc;
	wc.style = CS_HREDRAW | CS_VREDRAW;
	wc.hInstance = hInstance;
	wc.lpfnWndProc = WindowProc;
	wc.cbClsExtra = wc.cbWndExtra = 0;
	wc.hbrBackground = NULL ;
	wc.hIcon = LoadIcon( hInstance , IDI_APPLICATION );
	wc.hCursor = LoadCursor( NULL , IDC_ARROW );
	wc.lpszClassName = name ;
	wc.lpszMenuName = NULL;

	RegisterClass( &wc );

	return CreateWindowEx( WS_EX_TOPMOST , 
		name,
		name,
		WS_POPUP,
		0,
		0,
		GetSystemMetrics( SM_CXSCREEN ),
		GetSystemMetrics( SM_CYSCREEN ),
		NULL,
		NULL,
		hInstance,
		NULL );
}

long CALLBACK WindowProc( HWND hwnd , UINT message , WPARAM wParam , LPARAM lParam )
{
	switch( message ){
	case WM_ACTIVATEAPP:
		ActiveApp = wParam;
		break;

	case WM_CREATE:
		break;

	case WM_KEYDOWN:
		if( wParam == VK_ESCAPE )
			DestroyWindow( hwnd );
		break;

	case WM_DESTROY:
		Cleanup_DDraw( );
		ShowCursor( TRUE );
		PostQuitMessage( 0 );
		break;

	default:
		return DefWindowProc( hwnd , message , wParam , lParam );
	}
	return 0L;
}

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
	MSG msg ;

	HWND hwnd = CreateGameWindow( "DDraw - Demo1" , hInstance );

	if ( !hwnd )
		return NULL;

	ShowWindow( hwnd , nCmdShow );
	UpdateWindow( hwnd );
	SetFocus( hwnd );
	ShowCursor( TRUE );

	BOOL OK = Init_DDraw( hwnd );

	if ( !OK ){
		DestroyWindow( hwnd );
		return FALSE;
	}

	while( TRUE )
		if( PeekMessage( &msg , NULL , 0 , 0 , PM_NOREMOVE ) ){
			if( !GetMessage( &msg , NULL , 0 , 0 ) ) 
				return msg.wParam;
			TranslateMessage( &msg );
			DispatchMessage( &msg );
		}
		else if ( ActiveApp )
			GameMain( );
		else WaitMessage( );
}

      
Sorry forgot to mention the problem the apps goes to load then just comes straight back into windows Edited by - zeroshot on January 10, 2002 6:09:00 PM Edited by - zeroshot on January 10, 2002 6:17:27 PM Edited by - zeroshot on January 10, 2002 6:18:37 PM

This topic is closed to new replies.

Advertisement