begin process at 2012 05 27 15:41:43
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Tutoriaux

 > DIRECT DRAW, SOUND / HELLO WORLD (VC++ 5.0)

DIRECT DRAW, SOUND / HELLO WORLD (VC++ 5.0)


 Information sur la source

Note :
8,67 / 10 - par 3 personnes
8,67 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Tutoriaux Niveau :Débutant Date de création :09/12/2001 Vu / téléchargé :6 308 / 237

Auteur : Croqmort

Ecrire un message privé
Site perso
Commentaire sur cette source (4)
Ajouter un commentaire et/ou une note

 Description

voila la source d'un petit programme pour ecrire hello world avec des briques, avec un pacman qui passe derriere en rebondissant et en fesant des bruits ...
un hello world classique ...

Source

  • #include <windows.h>
  • #include <windowsx.h>
  • #include <stdio.h>
  • #include <malloc.h>
  • #include <time.h>
  • #include <ddraw.h>
  • #include <dsound.h>
  • #include "dsutil.h"
  • #include "ddutil.h"
  • char helloworld[375] = {
  • 1,0,0,1,0,1,1,1,1,0,1,0,0,0,0,1,0,0,0,0,1,1,1,1,0,
  • 1,0,0,1,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,1,0,
  • 1,0,0,1,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,1,0,
  • 1,1,1,1,0,1,1,1,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,1,0,
  • 1,0,0,1,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,1,0,
  • 1,0,0,1,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,1,0,
  • 1,0,0,1,0,1,1,1,1,0,1,1,1,1,0,1,1,1,1,0,1,1,1,1,0,
  • 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  • 1,0,0,0,1,0,1,1,1,1,0,1,1,1,0,0,1,0,0,0,0,1,1,1,0,
  • 1,0,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,0,0,1,0,0,1,
  • 1,0,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,0,0,1,0,0,1,
  • 1,0,0,0,1,0,1,0,0,1,0,1,1,1,0,0,1,0,0,0,0,1,0,0,1,
  • 1,0,1,0,1,0,1,0,0,1,0,1,1,0,0,0,1,0,0,0,0,1,0,0,1,
  • 1,1,0,1,1,0,1,0,0,1,0,1,0,1,0,0,1,0,0,0,0,1,0,0,1,
  • 1,0,0,0,1,0,1,1,1,1,0,1,0,0,1,0,1,1,1,1,0,1,1,1,0
  • };
  • LPDIRECTDRAW pDD;
  • LPDIRECTDRAWSURFACE pDDSPrim,pDDSSec;
  • LPDIRECTDRAWSURFACE pDDSFond, pDDSBriques, pDDSPacman;
  • DDSCAPS ddscaps;
  • DDSURFACEDESC ddsd;
  • LPDIRECTDRAWCLIPPER pDDClip;
  • RGNDATA *RegionData;
  • #define NUMEVENTS 2
  • LPDIRECTSOUND lpds;
  • HSNDOBJ HSOBoing = NULL;
  • DWORD LastGetTick;
  • unsigned int tempus, tempus2;
  • int x,y,depx,depy;
  • HICON hIcon;
  • HCURSOR hCursor;
  • int WINAPI WinMain (HINSTANCE, HINSTANCE, LPSTR, int);
  • LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
  • void Dessine(LPDIRECTDRAWSURFACE,int,int,int,int,int,int,DWORD);
  • void Update_Frame(void);
  • int WINAPI WinMain(HINSTANCE hThisInstance,HINSTANCE hPrevInstance,LPSTR lpszArgument,int nFunsterStil){
  • HWND hwnd;
  • MSG msg;
  • WNDCLASSEX wincl;
  • RECT *rc;
  • int i, i2;
  • srand( (unsigned)time( NULL ) );
  • wincl.hInstance = hThisInstance;
  • wincl.lpszClassName = "HelloWorld";
  • wincl.lpfnWndProc = WindowProcedure;
  • wincl.style = CS_HREDRAW|CS_VREDRAW|CS_BYTEALIGNWINDOW;
  • wincl.cbSize = sizeof(WNDCLASSEX);
  • hIcon = LoadIcon(NULL, IDI_APPLICATION);
  • hCursor = LoadCursor(NULL, IDC_ARROW);
  • wincl.hIcon = hIcon;
  • wincl.hIconSm = hIcon;
  • wincl.hCursor = hCursor;
  • wincl.lpszMenuName = NULL;
  • wincl.cbClsExtra = 0;
  • wincl.cbWndExtra = 0;
  • wincl.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
  • if(!RegisterClassEx(&wincl)) return 0;
  • hwnd = CreateWindowEx(0, "HelloWorld", "coucou", WS_POPUP, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), NULL, NULL, hThisInstance, NULL);
  • if (DirectDrawCreate(NULL, &pDD, NULL) != DD_OK) exit(1);
  • pDD->SetCooperativeLevel(hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
  • pDD->SetDisplayMode(640, 480, 16);
  • memset(&ddsd, 0, sizeof ddsd);
  • ddsd.dwSize = sizeof(ddsd);
  • ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
  • ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;
  • ddsd.dwBackBufferCount = 1;
  • pDD->CreateSurface(&ddsd, &pDDSPrim, NULL);
  • pDD->CreateClipper(NULL,&pDDClip,NULL);
  • RegionData=(RGNDATA *) malloc(48);
  • RegionData->rdh.dwSize = 32;
  • RegionData->rdh.iType = RDH_RECTANGLES;
  • RegionData->rdh.nCount = 1;
  • RegionData->rdh.nRgnSize = 16;
  • RegionData->rdh.rcBound.left = 0;
  • RegionData->rdh.rcBound.right = 640;
  • RegionData->rdh.rcBound.top = 0;
  • RegionData->rdh.rcBound.bottom = 480;
  • rc = (RECT *) &RegionData->Buffer[0];
  • rc->left = 0;
  • rc->right = 640;
  • rc->top = 0;
  • rc->bottom = 480;
  • pDDClip->SetClipList(RegionData,0);
  • ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
  • pDDSPrim->GetAttachedSurface(&ddscaps, &pDDSSec);
  • pDDSSec->SetClipper(pDDClip);
  • pDDSFond = DDLoadBitmap(pDD, "fond.bmp", 0, 0);
  • pDDSBriques = DDLoadBitmap(pDD, "brique.bmp", 0, 0);
  • pDDSPacman = DDLoadBitmap(pDD, "pacman.bmp", 0, 0);
  • DDSetColorKey(pDDSPacman, RGB(255, 0, 255));
  • for(i=0;i<15;i++)
  • for(i2=0;i2<25;i2++)
  • if(helloworld[i*25+i2])
  • helloworld[i*25+i2] = 1+(rand()%3);
  • tempus2 = tempus = 0;
  • depx = 5;
  • depy;
  • x = 320;
  • y = 240;
  • if (DirectSoundCreate(NULL, &lpds, NULL)!=DS_OK) exit(1);
  • if (lpds->SetCooperativeLevel(hwnd, DSSCL_PRIORITY)!=DS_OK) exit(1);
  • HSOBoing = SndObjCreate(lpds, "BOING.WAV", 2);
  • ShowWindow(hwnd, nFunsterStil);
  • UpdateWindow(hwnd);
  • LastGetTick = GetTickCount();
  • 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((GetTickCount()-LastGetTick)>50){
  • LastGetTick = GetTickCount();
  • Update_Frame();
  • };
  • }
  • void Dessine(LPDIRECTDRAWSURFACE Image,int x, int y,int ix, int iy,int iw, int ih,DWORD flag){
  • RECT src,drc;
  • src.left = ix;
  • src.top = iy;
  • src.right = ix+iw;
  • src.bottom = iy+ih;
  • drc.left = x;
  • drc.top = y;
  • drc.right = x+iw;
  • drc.bottom = y+ih;
  • pDDSSec->Blt(&drc,Image,&src,flag|DDBLT_WAIT,NULL);
  • };
  • void Update_Frame(void){
  • int i,i2;
  • tempus++;
  • if((tempus&0xF)==0) tempus2++;
  • Dessine(pDDSFond,0,0,0,0,640,480,NULL);
  • if(((x+depx+30)>640)||((x+depx)<0)) depx = -depx;
  • x+=depx;
  • depy++;
  • if((y+depy)>(480-30)){
  • depy = -depy;
  • SndObjPlay(HSOBoing, NULL);
  • }
  • if((y+depy)<0) depy = 0;
  • y+=depy;
  • Dessine(pDDSPacman,x,y,(depx < 0 ? 60 : 0)+(tempus2&0x1)*30,0,30,30,DDBLT_KEYSRC);
  • for(i=0;i<15;i++)
  • for(i2=0;i2<25;i2++)
  • if(helloworld[i*25+i2] != 0)
  • Dessine(pDDSBriques,80+i2*20,100+i*20,20*(helloworld[i*25+i2]-1),0,20,20,NULL);
  • pDDSPrim->Flip(NULL, 0);
  • };
  • LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
  • switch(message){
  • case WM_SETCURSOR:
  • SetCursor(NULL);
  • return TRUE;
  • case WM_KEYDOWN:
  • switch (wParam){
  • case VK_ESCAPE:
  • case VK_F12:
  • PostMessage(hwnd, WM_CLOSE, 0, 0);
  • break;
  • }
  • break;
  • case WM_DESTROY:
  • pDDSPacman->Release();
  • pDDSFond->Release();
  • pDDSBriques->Release();
  • pDDSSec->Release();
  • pDDSPrim->Release();
  • pDD->Release();
  • free(RegionData);
  • SndObjDestroy(HSOBoing);
  • HSOBoing = NULL;
  • lpds->Release();
  • DestroyIcon(hIcon);
  • DestroyCursor(hCursor);
  • PostQuitMessage(0);
  • break;
  • default:
  • return DefWindowProc(hwnd, message, wParam, lParam);
  • }
  • return 0;
  • }
#include <windows.h>
#include <windowsx.h>
#include <stdio.h>
#include <malloc.h>
#include <time.h>
#include <ddraw.h>
#include <dsound.h>
#include "dsutil.h"
#include "ddutil.h"

char helloworld[375] = {
1,0,0,1,0,1,1,1,1,0,1,0,0,0,0,1,0,0,0,0,1,1,1,1,0,
1,0,0,1,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,1,0,
1,0,0,1,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,1,0,
1,1,1,1,0,1,1,1,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,1,0,
1,0,0,1,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,1,0,
1,0,0,1,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,1,0,
1,0,0,1,0,1,1,1,1,0,1,1,1,1,0,1,1,1,1,0,1,1,1,1,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1,0,0,0,1,0,1,1,1,1,0,1,1,1,0,0,1,0,0,0,0,1,1,1,0,
1,0,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,0,0,1,0,0,1,
1,0,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,0,0,1,0,0,1,
1,0,0,0,1,0,1,0,0,1,0,1,1,1,0,0,1,0,0,0,0,1,0,0,1,
1,0,1,0,1,0,1,0,0,1,0,1,1,0,0,0,1,0,0,0,0,1,0,0,1,
1,1,0,1,1,0,1,0,0,1,0,1,0,1,0,0,1,0,0,0,0,1,0,0,1,
1,0,0,0,1,0,1,1,1,1,0,1,0,0,1,0,1,1,1,1,0,1,1,1,0
};

LPDIRECTDRAW	pDD;
LPDIRECTDRAWSURFACE		pDDSPrim,pDDSSec;
LPDIRECTDRAWSURFACE	pDDSFond, pDDSBriques, pDDSPacman;
DDSCAPS	ddscaps;
DDSURFACEDESC	ddsd;
LPDIRECTDRAWCLIPPER	pDDClip;
RGNDATA	*RegionData;


#define NUMEVENTS 2
 
LPDIRECTSOUND	lpds;
HSNDOBJ			HSOBoing = NULL;

DWORD LastGetTick;
unsigned int tempus, tempus2;
int x,y,depx,depy;

HICON hIcon;
HCURSOR hCursor;

int WINAPI WinMain (HINSTANCE, HINSTANCE, LPSTR, int);
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
void Dessine(LPDIRECTDRAWSURFACE,int,int,int,int,int,int,DWORD);
void Update_Frame(void);

int WINAPI WinMain(HINSTANCE hThisInstance,HINSTANCE hPrevInstance,LPSTR lpszArgument,int nFunsterStil){
	HWND hwnd;
	MSG msg;
	WNDCLASSEX wincl;
	RECT *rc;
	int i, i2;

	srand( (unsigned)time( NULL ) );
	wincl.hInstance = hThisInstance;
	wincl.lpszClassName = "HelloWorld";
	wincl.lpfnWndProc = WindowProcedure;	
	wincl.style = CS_HREDRAW|CS_VREDRAW|CS_BYTEALIGNWINDOW;
	wincl.cbSize = sizeof(WNDCLASSEX);

	hIcon = LoadIcon(NULL, IDI_APPLICATION);
	hCursor = LoadCursor(NULL, IDC_ARROW);
	wincl.hIcon = hIcon;
	wincl.hIconSm = hIcon;
	wincl.hCursor = hCursor;
	wincl.lpszMenuName = NULL;
	wincl.cbClsExtra = 0;
	wincl.cbWndExtra = 0;
	wincl.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
	if(!RegisterClassEx(&wincl)) return 0;
	hwnd = CreateWindowEx(0, "HelloWorld", "coucou", WS_POPUP, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), NULL, NULL, hThisInstance, NULL);

	if (DirectDrawCreate(NULL, &pDD, NULL) != DD_OK) exit(1);
	pDD->SetCooperativeLevel(hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
	pDD->SetDisplayMode(640, 480, 16);
	memset(&ddsd, 0, sizeof ddsd);
	ddsd.dwSize = sizeof(ddsd);
	ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
	ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;
	ddsd.dwBackBufferCount = 1;
	pDD->CreateSurface(&ddsd, &pDDSPrim, NULL);
	pDD->CreateClipper(NULL,&pDDClip,NULL);
	RegionData=(RGNDATA *) malloc(48);
	RegionData->rdh.dwSize = 32;
	RegionData->rdh.iType = RDH_RECTANGLES;
	RegionData->rdh.nCount = 1;
	RegionData->rdh.nRgnSize = 16;
	RegionData->rdh.rcBound.left = 0;
	RegionData->rdh.rcBound.right = 640;
	RegionData->rdh.rcBound.top = 0;
	RegionData->rdh.rcBound.bottom = 480;
	rc = (RECT *) &RegionData->Buffer[0];
	rc->left = 0;
	rc->right = 640;
	rc->top = 0;
	rc->bottom = 480;
	pDDClip->SetClipList(RegionData,0);
	ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
	pDDSPrim->GetAttachedSurface(&ddscaps, &pDDSSec);
	pDDSSec->SetClipper(pDDClip);
	pDDSFond = DDLoadBitmap(pDD, "fond.bmp", 0, 0);
	pDDSBriques = DDLoadBitmap(pDD, "brique.bmp", 0, 0);
	pDDSPacman = DDLoadBitmap(pDD, "pacman.bmp", 0, 0);
	DDSetColorKey(pDDSPacman, RGB(255, 0, 255));

	for(i=0;i<15;i++)
		for(i2=0;i2<25;i2++)
			if(helloworld[i*25+i2])
				helloworld[i*25+i2] = 1+(rand()%3);

	tempus2 = tempus = 0;
	depx = 5;
	depy;
	x = 320;
	y = 240;

    if (DirectSoundCreate(NULL, &lpds, NULL)!=DS_OK)  exit(1);
    if (lpds->SetCooperativeLevel(hwnd, DSSCL_PRIORITY)!=DS_OK) exit(1);
	HSOBoing = SndObjCreate(lpds, "BOING.WAV", 2);
	
	ShowWindow(hwnd, nFunsterStil);
	UpdateWindow(hwnd);

	LastGetTick = GetTickCount();

	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((GetTickCount()-LastGetTick)>50){
			LastGetTick = GetTickCount();
			Update_Frame();
		};
}

void Dessine(LPDIRECTDRAWSURFACE Image,int x, int y,int ix, int iy,int iw, int ih,DWORD flag){
	RECT src,drc;
	src.left = ix;
	src.top = iy;
	src.right = ix+iw;
	src.bottom = iy+ih;
	drc.left = x;
	drc.top = y;
	drc.right = x+iw;
	drc.bottom = y+ih;
	pDDSSec->Blt(&drc,Image,&src,flag|DDBLT_WAIT,NULL);
};

void Update_Frame(void){
	int i,i2;
	tempus++;
	if((tempus&0xF)==0) tempus2++;
	Dessine(pDDSFond,0,0,0,0,640,480,NULL);

	if(((x+depx+30)>640)||((x+depx)<0)) depx = -depx;
	x+=depx;

	depy++;
	if((y+depy)>(480-30)){
		depy = -depy;
		SndObjPlay(HSOBoing, NULL);
	}
	if((y+depy)<0) depy = 0;
	y+=depy;

	Dessine(pDDSPacman,x,y,(depx < 0 ? 60 : 0)+(tempus2&0x1)*30,0,30,30,DDBLT_KEYSRC);

	for(i=0;i<15;i++)
		for(i2=0;i2<25;i2++)
			if(helloworld[i*25+i2] != 0)
				Dessine(pDDSBriques,80+i2*20,100+i*20,20*(helloworld[i*25+i2]-1),0,20,20,NULL);

	pDDSPrim->Flip(NULL, 0);
};

LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
	switch(message){
	case WM_SETCURSOR:
		SetCursor(NULL);
	return TRUE;

	case WM_KEYDOWN:
		switch (wParam){
		case VK_ESCAPE:
		case VK_F12:
			PostMessage(hwnd, WM_CLOSE, 0, 0);
		break;
		}
	break;

	case WM_DESTROY:
		pDDSPacman->Release();
		pDDSFond->Release();
		pDDSBriques->Release();
		pDDSSec->Release();
		pDDSPrim->Release();
		pDD->Release();
		free(RegionData);
		SndObjDestroy(HSOBoing);
        HSOBoing = NULL;
		lpds->Release();
		DestroyIcon(hIcon);
		DestroyCursor(hCursor);
		PostQuitMessage(0); 
	break; 

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

 Conclusion

Bon voila sinon sinon le tutorial est aussi sur :
www.ifrance.com/frenchcodeur/croq/croq.html

 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Sources du même auteur

LEPENWORLD : JEU AVEC LEPEN [VC++ 5.0][DIRECTX 7.0]
Source avec Zip Source avec une capture CLIENT IRC (VC++ 5.0)
Source avec Zip COMPRESSION RLE (VC++ 5.0)
EFFET DE FLAMME (SOUS DOS EN 320*200) (BC++)
Source avec Zip Source avec une capture CHIRACWORLD (VC++ 5.0)

 Sources de la même categorie

LISTER FICHIERS ET RÉPERTOIRES (MULTIPLATEFORME) par christophedlr
UTILISATION DES TYPELIST EN C++ par wyden
Source avec Zip Source avec une capture QCSSCOMPRESSOR par alphaone
AFFICHAGE D'UN TRIANGLE ISOCELE par nabche
Source avec Zip GESTION D'UNE BIBLOTHEQUE par leclerro19

Commentaires et avis

Commentaire de seito le 04/05/2004 12:15:57

l'ami le zip quand j'essai de l'ouvrir il me ferme mon explorer essai de voir ce qu'il a

Commentaire de pumbaa666 le 07/11/2004 15:14:08

C'est vrai, très classique comme Hello World...
loool.
Vachement bien vu en tout cas, bon boulot :-p
J'y met un 8/10

Commentaire de wikamk le 18/12/2004 10:13:16

et pouuoi tout ces libraiies et si tu ajoutais des lignes de commanteires
merci

Commentaire de missinfo24 le 22/05/2011 22:04:53

SVP quelqu'un pourrait m'aider en me donnant le code source d'un programme qui "Hello World" en langage NesC car je travaille sous Tinyos version 2.1.1 et je n'arrive pas du tout à le trouver merci d'avance

 Ajouter un commentaire




Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,452 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales