⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 resource.c

📁 一个minigui 工程框架,需要windows 下的minigui 开发环境
💻 C
字号:
#include "const.h"#include "resource.h"LatticeList latticelist = 0;int PushLattice(lattice* latt)
{
	
	int i = 0;
	LatticeList p;
	LatticeList prv;
	LatticeList* address;	
	address = &latticelist;
	p = latticelist;
	prv = p;

	if(!latt)
		return -1;

	while(p){

		i++;
		prv = p;
		address = &p->next;
		p = p->next;
		
	}

	p =(LatticeList) malloc(sizeof(struct LATTICELIST));
	if(0 == p)
		return 0;

	memset(p,0,sizeof( struct LATTICELIST));

	p->lattice_p = latt;
	
	*address = p;		// .insert into list.

	i++;
	return i;
	
}

// Parsel.Res.
int ParselRes(char* filename)
{
	FILE* file ;
	
	unsigned int num = 0;
	unsigned int loop = 0;
	unsigned int index = 0;
	unsigned int length = 0;
	unsigned short cx = 0;
	unsigned short cy = 0;
	int len = 0;
	
	file = fopen(filename,"rb");
	if(file<=0)
	{
		if(debug_flag)
			printf("Resource file open failed!\n");
		return 0;
	}
	
	fseek(file,0,SEEK_SET);

	len = fread((void*)&num,sizeof(unsigned char),sizeof(unsigned int),file);
	if(len != sizeof(unsigned int))
	{
		
		if(debug_flag)
			printf("Resource file error!\n");
		fclose(file);
		return 0;
	}

	if(num<0) 
	{
		if(debug_flag)
			printf("Resource file error!\n");
		if(file)
			fclose(file);
		return 0;
	}	for(loop = 0;loop <num;loop++)
	{
		// index.
		lattice* latt;
		unsigned char* p = 0;
		len = fread((void*)&index,sizeof(unsigned char),sizeof(unsigned int),file);
		if(len !=sizeof(unsigned int))
			continue;
		if(index<0)
			continue;
		len = fread((void*)&length,sizeof(unsigned char),sizeof(unsigned int),file);
		if(len !=sizeof(unsigned int))
			continue;	
		if(length<=0)
			continue;
		len = fread((void*)&cx,sizeof(unsigned char),sizeof(unsigned short),file);
		if(len !=sizeof(unsigned short))
			continue;
		if(cx<=0)
			continue;
		len = fread((void*)&cy,sizeof(unsigned char),sizeof(unsigned short),file);
		if(len !=sizeof(unsigned short))
			continue;
		if(cy<=0)
			continue;
		if(length-2*sizeof(unsigned short)<=0)
			continue;
		p = ( unsigned char*)malloc(length-2*sizeof(unsigned short));
		if(0 == p)
		{
			if(debug_flag)
				printf("Resource file error!\n");
			if(file) 
				fclose(file);
			return 0;
		}
		memset(p,0,length-2*sizeof(unsigned short));
		len = fread((void*)p,sizeof(unsigned char),length-2*sizeof(unsigned short),file);
		if(len !=(int)(length-2*sizeof(unsigned short)))
		{
			if(p) free(p);
			continue;
		}

		latt =(lattice*) malloc (sizeof(lattice));
		if(0 == latt)
		{
			if(p) free(p);
			if(debug_flag)
				printf("Resource file error!\n");
			if(file) 
				fclose(file);
			return 0;
		}
		memset((void*)latt,0,sizeof(lattice));		
		latt->index = index;
		latt->width = cx;
		latt->height = cy;
		latt->pResdata = p;
		if(PushLattice(latt) <=0)
		{
			if(debug_flag)
				printf("Resource file err or!\n");
			if(file) 
				fclose(file);
			return 0;
		}
	}
	if(file) 
		fclose(file);
	return 1;
}



lattice* SearchLattice(int index)
{
	LatticeList ll = 0;
	ll= latticelist;
	while(ll)
	{
		lattice* latt = (lattice*)ll->lattice_p;
		if( index == (int)latt->index)
			return latt;
		ll=ll->next;
	}
	return 0;
}

void AssoilRes()
{
	LatticeList pLatticelist,pLatticeNext;

	pLatticelist = latticelist;
	while(pLatticelist)
	{
		lattice* latt;
		latt = pLatticelist->lattice_p;
		Assoillattice(latt);
		pLatticelist->lattice_p = 0;
		pLatticelist = pLatticelist->next;
	}

	pLatticelist = latticelist;
	if(pLatticelist)
	{
		pLatticeNext = pLatticelist->next;
		while(pLatticelist)
		{
			free(pLatticelist);
			pLatticelist = pLatticeNext;
			pLatticeNext = pLatticelist?pLatticelist->next :NULL;
		}
	}

	latticelist = 0;
}
void Assoillattice(lattice* latt)
{
	if(!latt)
		return;
	if(latt && latt->pResdata)
		free (latt->pResdata);
	if(latt)
		free (latt);
	latt = 0;

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -