typedef struct		{
	unsigned char	*Bits;
	unsigned int	largeur, hauteur;
	unsigned int	vLarg, vHaut;
	HDC				hdcEcran;
	HBITMAP			hbmEcran;
} ECRAN;

ECRAN *CreeEcran(unsigned int largeur, unsigned int hauteur)		{
	ECRAN *ecr;
	ecr=(ECRAN*)malloc(sizeof(ECRAN));
	if (!ecr)
		return NULL;
	ecr->hdcEcran=CreateCompatibleDC(GetDC(NULL));
	ecr->largeur=largeur;
	ecr->hauteur=hauteur;
	if (largeur%4==0)
		ecr->vLarg=largeur;
	else
		ecr->vLarg=largeur+(4-largeur%4);
	ecr->vHaut=hauteur;
	CreeDIB(ecr->hdcEcran,ecr->vLarg,ecr->vHaut,24,&ecr->hbmEcran,(void**)&ecr->Bits);
	return ecr;
}

void DetruitEcran(ECRAN *ecr)		{
	DeleteObject(ecr->hbmEcran);
	DeleteObject(ecr->hdcEcran);
	ecr->hbmEcran=NULL;
	ecr->hdcEcran=NULL;
	ecr->Bits=NULL;
	ecr->largeur=ecr->vHaut=ecr->vLarg=0;
}

int ChoisitEcran(ECRAN *ecr)		{
	Bits=ecr->Bits;
	LARG=ecr->largeur;
	HAUT=ecr->hauteur;
	LARG_BUF=ecr->vLarg;
	HAUT_BUF=ecr->vHaut;
	hdcImage=ecr->hdcEcran;
	hbm=ecr->hbmEcran;
	CLIP_X0=CLIP_Y0=0;
	CLIP_X1=LARG;
	CLIP_Y1=HAUT;
	return 0;
}

/*ECRAN *EcranCourant()		{
	ECRAN *ecr;
	ecr=(ECRAN*)malloc(sizeof(ECRAN));
	ecr->Bits=Bits;
	ecr->largeur=LARG;
	ecr->hauteur=HAUT;
	ecr->vLarg=LARG_BUF;
	ecr->vHaut=HAUT_BUF;
	ecr->hdcEcran=hdcImage;
	ecr->hbmEcran=hbm;
	return ecr;
}*/

void EcranCourant(ECRAN *ecr)		{
	ecr->Bits=Bits;
	ecr->largeur=LARG;
	ecr->hauteur=HAUT;
	ecr->vLarg=LARG_BUF;
	ecr->vHaut=HAUT_BUF;
	ecr->hdcEcran=hdcImage;
	ecr->hbmEcran=hbm;
}

OBJET *EcranVersObjet(ECRAN *ecr)		{
	OBJET *obj;
	obj=(OBJET*)malloc(sizeof(OBJET));
	if (!obj)
		return NULL;
	obj->hauteur=ecr->hauteur;
	obj->largeur=ecr->largeur;
	obj->sprite=ecr->Bits+obj->largeur*3;
	obj->x=obj->y=0;
	return obj;
}

void CreeObjet(OBJET *obj, int l, int h)		{
	obj->x=obj->y=0;
	obj->sprite=(unsigned char*)malloc(h*l*3);
	obj->largeur=l;
	obj->hauteur=h;
}

//#define min(x,y)	((x<y)?(x):(y))
//#define max(x,y)	((x>y)?(x):(y))

void CopieEcran(ECRAN *dst, ECRAN *src)		{
	int x,y;
	x=min(src->vLarg,dst->vLarg);
	y=min(src->hauteur,dst->hauteur);
	if (src->Bits && dst->Bits)
		memcpy(dst->Bits,src->Bits,x*(y+1)*3);
}
