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

📄 m_02.cpp

📁 基于vc++写的记事本功能强大非常棒。功能全面统一。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
			++pos;
			gotoxy(x,y);
			printf("  %2d:(%2d,%2d)  ",n,(pos-szText)/51+1,(pos-szText)%51+1);
			x+=13;
			if(x>35)
			{
				x=5;
				y+=1;
			}
		}
		if(n>3)
		{
			if(n%3==1)
				printf("                          ");
			else if(n%3==2)
				printf("             ");
			if(n%3==0)
				y-=1;
			gotoxy(5,y+1);
			printf("                                         ");
		}
		gotoxy(7,13);
		printf("共找到了%d个:(行,列)",n);
	}
	getch();
}

void AlterRecord()    //修改记录内容
{
	SetConsoleTextAttribute(hCon,92);
	for(int i=8;i<13;++i)
	{
		gotoxy(5,i);
		printf("                                         ");
	}
	SetConsoleTextAttribute(hCon,94);
	gotoxy(7,10);
	printf("             修改完成!! ");

	FILE *fp;
	fp=fopen("record.data","rb+");
	stRecord st1;
	int size=sizeof(stRecord);
	while(!feof(fp))
	{
		fread(&st1,size,1,fp);
		if(strcmp(st1.szTime,topNine[topIndex-topSelect].szTime)==0)
		{
			fseek(fp,-size,SEEK_CUR);
			fwrite(&topNine[topIndex-topSelect],size,1,fp);
			break;
		}
	}
	fclose(fp);
	getch();
}

void AddRecord()        //增加记录
{
	SetConsoleTextAttribute(hCon,92);
	for(int i=8;i<17;++i)
	{
		gotoxy(5,i);
		printf("                                         ");
	}
	gotoxy(7,9);
	printf("请在下框中输入标题,按回车键结束:");
	gotoxy(7,11);
	SetConsoleTextAttribute(hCon,240);
	printf("                                     ");
	gotoxy(7,11);
	char title[30];
	gets(title);

	time_t now=time(NULL);      //获取当前时间
	tm *t=localtime(&now);
	char dayTime[22];
	char temp[5];
	itoa(t->tm_year+1900,dayTime,10);
	strcat(dayTime,"-");
	itoa(t->tm_mon+1,temp,10);
	strcat(dayTime,temp);
	strcat(dayTime,"-");
	itoa(t->tm_mday,temp,10);
	strcat(dayTime,temp);
	strcat(dayTime," ");
	itoa(t->tm_hour,temp,10);
	strcat(dayTime,temp);
	strcat(dayTime,":");
	itoa(t->tm_min,temp,10);
	strcat(dayTime,temp);
	strcat(dayTime,":");
	itoa(t->tm_sec,temp,10);
	strcat(dayTime,temp);

	stRecord record;
	strcpy(record.szWriter,LoginName);
	strcpy(record.szTitle,title);
	strcpy(record.szTime,dayTime);
	strcpy(record.szRecord,szText);

	FILE *fp;
	fp=fopen("record.data","ab");
	fwrite(&record,sizeof(stRecord),1,fp);
	fclose(fp);

	SetConsoleTextAttribute(hCon,94);
	gotoxy(7,14);
	printf("             保存完成!! ");

	getch();
}

void Input(int n)
{
	int inputIndex=strlen(szText);
	int isChange=inputIndex;       //判断是否内容有改变
	int state=1,changefont=0;
	int nsubMenu[6]={0,4,3,2,1,2};    //子菜单个数
	stFrmInfo frmInfo={0,0,0,0,0};
	frmInfo.x=inputIndex/51;
	frmInfo.y=inputIndex%51;
	MainFrm(frmInfo,state,changefont);
	gotoxy(frmInfo.y,frmInfo.x+2); 
	SetConsoleTextAttribute(hCon,240);
	int c;
	while(1)
	{
		if(frmInfo.select==0)
		{
			while((c=getche())!=0&&c!=224&&c!=13&&c!=8&&c!=27)
			{
				szText[inputIndex++]=c;
				szText[inputIndex]='\0';
			}
		}
		else
			while((c=getch())!=0&&c!=224&&c!=13&&c!=8&&c!=27)
				;

		
		
		if(c==224)     //判断方向键
		{
			c=getch();
			

			if(frmInfo.select!=0)      //当主菜单被选中时
			{
				if(c==77)                 //判断左右键
				{
					frmInfo.select=frmInfo.select%5+1;
					if(frmInfo.hasMenu!=0)
						frmInfo.subSelect=1;      //当主菜单选中时左右移动,子菜单选项回归到1
				}
				else if(c==75)
				{
					if(frmInfo.select==1)
						frmInfo.select=5;
					else
						frmInfo.select-=1;
					if(frmInfo.hasMenu!=0)
						frmInfo.subSelect=1;
				}
				else if(c==80)      //向下方向键
				{
					if(frmInfo.hasMenu==0)
					{
						frmInfo.hasMenu=1;
						frmInfo.subSelect=1;
					}
					else
					{
						if(frmInfo.subSelect==nsubMenu[frmInfo.select])
							frmInfo.subSelect=1;
						else
							++frmInfo.subSelect;
					}
				}
				else if(c==72&&frmInfo.hasMenu!=0)     //向上方向键
				{
					if(frmInfo.subSelect==1)
						frmInfo.subSelect=nsubMenu[frmInfo.select];
					else
						--frmInfo.subSelect;
				}
			}
			else
			{
				   //当主菜单没被选中时
			}
		}
		else if(c==0)                //判断是否按了F1
		{
			c=getch();
			if(c==59)                     
			{
				if(frmInfo.select==0)
					frmInfo.select=1;
				else
				{
					frmInfo.select=0;
					frmInfo.hasMenu=0;
					frmInfo.subSelect=0;
				}
			}
		}
		else if(c==13&&frmInfo.subSelect!=0)
		{
			if(frmInfo.select==5)        //选择第5个菜单时
			{
				if(frmInfo.subSelect==1)
					HelpFrm();
				else if(frmInfo.subSelect==2)
					AboutFrm();
			}
			else if(frmInfo.select==1)
			{
				switch (frmInfo.subSelect)
				{
				case 1:
					szText=szInput;memset(szInput,'\0',sizeof(szInput));topIndex=0;
					isChange=inputIndex=0;frmInfo.x=inputIndex/51;
					frmInfo.y=inputIndex%51;topSelect=0;break;
				case 2:
					if(topSelect==0)
						AddRecord();
					else
						AlterRecord();
					isChange=inputIndex;
					break;
				case 3:
					if(isChange==inputIndex)
						return;
					if(ReturnFrm()==1)
						return;
					break;
				case 4:
					if(isChange==inputIndex)
						exit(0);
					if(ReturnFrm()==1)
						exit(0);
				}
			}
			else if(frmInfo.select==4)
			{
				if (frmInfo.subSelect==1)
				{
					state=-state;
				}
			}
			else if(frmInfo.select==3)
			{
				if (frmInfo.subSelect==1)
				{
					while((inputIndex+1)%51!=0)
					{
						szText[inputIndex++]=' ';     //用空格代替
					}
					szText[inputIndex++]=' ';
					szText[inputIndex]='\0';
				}
				else if(frmInfo.subSelect==2)
				{
					changefont=ChangeFont();
				}
			}
			else if(frmInfo.select==2)
			{
				if(frmInfo.subSelect==1)
				{
					Search();
				}
				else if (frmInfo.subSelect==2)
				{
					Replace();
					inputIndex=strlen(szText);
					frmInfo.x=inputIndex/51;
					frmInfo.y=inputIndex%51;
				}
				else if (frmInfo.subSelect==3)
				{
					if(szText[--inputIndex]==' ')
					{
						while(szText[--inputIndex]==' ');      //把连续的空格去掉
						szText[++inputIndex]='\0';
					}
					else
					szText[inputIndex]='\0';
				}
			}
			frmInfo.select=0;     //去掉菜单的选择
			frmInfo.subSelect=0;
			frmInfo.hasMenu=0;

		}


		else if(c==13&&frmInfo.select!=0)    //主菜单选中的情况下按回车键
		{
			if(frmInfo.hasMenu==0)
			{
				frmInfo.hasMenu=1;
				frmInfo.subSelect=1;
			}
		}
		


		else if(c==13&&frmInfo.select==0)    //主菜单没选中时按回车键,即文本换行
		{
			while((inputIndex+1)%51!=0)
			{
				szText[inputIndex++]=' ';     //用空格代替
			}
			szText[inputIndex++]=' ';
			szText[inputIndex]='\0';
		}
		else if(c==8&&frmInfo.select==0)       //按退格键时
		{
			if(inputIndex!=0)
			{
				if(szText[--inputIndex]==' ')
				{
					while(szText[--inputIndex]==' ');      //把连续的空格去掉
					szText[++inputIndex]='\0';
				}
				else
					szText[inputIndex]='\0';
			}
		}
		else if(c==27)    //ESC
		{
			if(frmInfo.subSelect!=0)
			{
				frmInfo.hasMenu=0;
				frmInfo.subSelect=0;
			}
			else if(frmInfo.select!=0)
				frmInfo.select=0;
			else
			{
				if(isChange==inputIndex)
					return;
				if(ReturnFrm()==1)
					return;
			}
		}
// 		else if(frmInfo.select==0)
// 		{
// 			szText[inputIndex++]=c;
// 			szText[inputIndex]='\0';
// 		}

		frmInfo.x=inputIndex/51;
		frmInfo.y=inputIndex%51;
		MainFrm(frmInfo,state,changefont);
		gotoxy(frmInfo.y,frmInfo.x+2);
	}
}

void RegisterFrm()
{
	SetConsoleTitle("注册窗口");
 	system("mode concols=34 lines=20 ");
	system("color 70");
	SetConsoleTextAttribute(hCon,128);
	for(int i=1;i<17;++i)
	{
		gotoxy(3,i);
		printf("                            ");
	}
	gotoxy(5,2);
	printf("------新用户注册:------");
	gotoxy(5,4);
	printf(" *用户名:");
	gotoxy(5,6);
	printf("   *密码:");
	gotoxy(4,8);
	printf("*重复密码:");
	gotoxy(5,10);
	printf("    性别:");
	gotoxy(5,12);
	printf("    年龄:");
	gotoxy(5,14);
	printf("    班级:");
	gotoxy(4,18);
	printf("   确认   ");
	gotoxy(20,18);
	printf("   取消   ");
	SetConsoleTextAttribute(hCon,240);
	for(i=4;i<16;i+=2)
	{
		gotoxy(16,i);
		printf("            ");
	}
	SetConsoleTextAttribute(hCon,142);
	gotoxy(3,16);
	printf("注:带*的必须填写");
}

int RegOK(char *name,char *pw1,char *pw2)
{
	SetConsoleTitle("错误");
	system("mode concols=41 lines=12 "); 
	system("color 5F");
	if(strlen(name)==0||strlen(pw1)==0)
	{
		printf("\n\n\n     出错啦,用户名和密码不能为空!!\n\n");
		printf("            请返回重新输入...");
		getch();
		return 0;
	}
	else if(strcmp(pw1,pw2)!=0)
	{
		printf("\n\n\n      出错啦,你输入的密码不一致!! \n\n");
		printf("            请返回重新输入...");
		getch();
		return 0;
	}
	FILE *fp;
	fp=fopen("user.data","rb");
	stUser user;
	if(fp!=0)
	{
		fread(&user,sizeof(stUser),1,fp);
		while (!feof(fp))
		{
			if (strcmp(user.szName,name)==0)
			{
				printf("\n\n\n       你输入的用户名已经被注册了! \n\n");
				printf("            请返回重新输入...");
				getch();
				fclose(fp);
				return 0;
			}
			fread(&user,sizeof(stUser),1,fp);
		}
		fclose(fp);
	}
	SetConsoleTitle("注册成功");
	printf("\n\n\n            恭喜,注册成功!! \n\n\n");
	printf("        程序将在3内返回登陆窗口");
	for(int i=3;i>0;--i)
	{
		gotoxy(16,6);
		printf("%d",i);
		gotoxy(31,6);
		Sleep(950);
	}
	return 1;
	

}

void RegInput()
{
	char userInfo[6][20]={"","","","","",""};
	int select=1,i=0,j=0,k=0,i1=0,j1=0,k1=0,x=0,c;
	while (1)
	{
		RegisterFrm();
		SetConsoleTextAttribute(hCon,240);
		gotoxy(16,4);
		printf("%s",userInfo[0]);
		gotoxy(16,6);
		for(x=0;x<j;++x)    //隐藏密码

⌨️ 快捷键说明

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