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

📄 menue0-file.cpp

📁 tc 2.0下用680*480 256 色模式下写成的中文菜单程序
💻 CPP
字号:

void menue0();           /*file*/
{
	int xk,yk;
	int state=0;
	char *filepath;
	Loadimage(x,y,"e:\\keshe\\file.bmp");
	while(1)
	{
		getkey(&xk,&yk);
    	if(yk==13)
		{
			Loadimage(x,y,"e\\keshe\\temp.bmp");
			return ;
		}
		else if(yk==27)
			switch(state)
			case 0: while(1)     /*打开文件*/
		             {
						 diaologe1(x,y,"请输入您要打开的文件",filepath);
						 {
							 if(fileopen(filepath,phead)==0)
							 {
								 if(dioaloge2(x,y,"无法打开","继续","取消")==0)
									 contune ;
								 else break:
							 }
							 else 
							 {
								 diaologe("文件成功打开");
									 break;
							 }
						 }
		             }
		             break ;
            case 1:savefile(filepath,phead);  /*保存文件*/
				   break ;
			case 2:while(1)                      /*新建文件*/
				   {
					   diaologe2(x,y,"输入要保存的文件路径",filepath);
				       if(savefile(filepath,phead))
					      dialogole(x,y,"保存成功");
				       else 
				          dialoge1e(x,y,"无法保存");
					   if(diaologe2(x,y,"重试吗?","确定","取消")==0)
						   continue ;
					   else 
						   break;
				   }
				   break;
			case 3:if(dialoge2(x,y,"确定退出吗?","确定","取消")==0)  /*退出*/
					   return :
				    break;
		 else if(yk==80)  /*up*/
			 if(state==0)
			 {
				 state=2;
				 unrectangle(0);
				 rectangle(2);
			 }
			 else
			 {
				 state--;
				 unrectangle(state+1);
				 rectangle(state);
			 }
		 else if(yk==72)
			 if(state==0)
			 {   

				 state=2
				 unrectangle(2);
				 rectangle(0);
			 }
			 else
			 {
				 state++;
				 unrectangle(state-1);
				 rectangle(state);
			 }
	}
}


void savefile(char *filepath,struct section *phead)
{
    FILE *fp;
    struct section *ptr;
    struct work *p;
    struct payroll *q;
    struct reduce  *p1;
    struct salary *p2;
    if(fp=(fopen(filepath,"w"))=NULL)
    {
        dialoge("无法打开目标文件");
        return ;
    }
    for(ptr=phead;ptr!=NULL;ptr=ptr->next)
    {
            fwrite(ptr,sizeof(struct section),fp);
            for(p=ptr->p;p!=NULL;p=p->next)
            {
                    fwrite(p,sizeof(struct work),1,fp);
                    for(q=p->p;p!=NULL;p=p->next)
                        {
                            fwrite(q,sizeof(struct work),1,fp);
                            p1=&(q.a),p2=&(q.b);
                            fwrite(p1,sizeof(struct reduce),1,fp);
                            fwrite(p2,sizeof(struct salary),1,fp);
                        }
            }
	}
}

void loadfile(char *filepath,struct section *phead)
{
    FILE *fp;
    struct section *ptr;
    struct work *p,*head;
    struct payroll *q,*qhead;
    struct reduce  *p1;
    struct salary *p2;
    int mun,i,j,month;
    phead=NULL;
    if(fp=(fopen(filepath,"r"))=NULL)
    {
        dialoge("无法打开目标文件");
        return ;
    }
    while(feof(fp))
    {
        ptr=(struct section *)malloc(sizeof(struct section));           /*建立部门链*/
        if(ptr==NULL)
        {
           dialoge("内存不够");
           return ;
         }
        fread(ptr,sizeof(struct section),1,fp);
        mun=ptr->mun;
        ptr->next=phead;
        phead=ptr;
        ptr->p=phead;
        head=NULL;
        for(i=0;i<mun;i++)                                     /*mun记录有多少职工*/
        {
             p=(struct work *)malloc(sizeof(struct work));   /*建立工人链*/
             if(q==NULL)
             {
                 dialoge("内存不够");
                 return ;
             }
             fread(p,sizeof(struct work),1,fp);
             p->next=head;
             head=p;
             month=p->month;
             p->p=qhead;
             qhead=NULL;
             for(j=0;j<month;j++)
             {                                                        /*month记录有几个月的工资*/
                q=(struct payroll *)maiioc(sizeof(struct payroll));   /*建立工资链*/
                if(q==NULL)
                {
                    dialoge("内存不够");
                     return ;
                }
                q->next=qhead;
                qhead=q;
                fread(q,sizeof(struct payroll),1,fp);
                fread(&(p->b),sizeof(struct reduce),1,fp);
                fread(&(p->a),sizeof(struct salary),1,fp);
            }
        }
    }
}

⌨️ 快捷键说明

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