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

📄 m_02.cpp

📁 基于vc++写的记事本功能强大非常棒。功能全面统一。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// M_02.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include <conio.h>
#include <string.h>
#include <time.h>

struct stUser       //保存用户信息
{
	char szName[12];
	char szPW[12];
	char szSex[12];
	char szAge[12];
	char szClass[12];
};

struct stRecord     //保存记录信息
{
	char szWriter[12];
	char szTime[20];
	char szTitle[20];
	char szRecord[1380];
};

struct stFrmInfo      //保存菜单信息
{
	int select;      //选择哪个主菜单
	int hasMenu;     //有无子菜单
	int subSelect;
	int x;
	int y;           //光标位置
};

HANDLE hCon=GetStdHandle(STD_OUTPUT_HANDLE);
char szInput[1400];        //最大输入个数1376
/*int inputIndex=0;*/

stRecord topNine[20];     //保存最近的20条记录
int topIndex=0;         //保存用户的记录数
int topSelect;         //保存用户选择的记录号,0为新记录
char *LoginName;

char *szText;       //指向记事本打开的记录

void gotoxy(int x,int y) 
{ 
	COORD c; 
	c.X=x;c.Y=y; 
	SetConsoleCursorPosition (hCon,c); 
}

void menu(int select,int subSelect)
{
	SetConsoleTextAttribute(hCon,112);
	int x=(select-1)*9;
	switch (select)
	{
	case 1:
		if(subSelect==1)
		{
			SetConsoleTextAttribute(hCon,47);
			gotoxy(x,1);printf("  新建(N)   ");
			SetConsoleTextAttribute(hCon,112);
			gotoxy(x,2);printf("  保存(S)   ");
			gotoxy(x,3);printf("  返回(R)   ");
			gotoxy(x,4);printf("  退出(E)   ");
		}
		else if(subSelect==2)
		{
			SetConsoleTextAttribute(hCon,47);
			gotoxy(x,2);printf("  保存(S)   ");
			SetConsoleTextAttribute(hCon,112);
			gotoxy(x,1);printf("  新建(N)   ");
			gotoxy(x,3);printf("  返回(R)   ");
			gotoxy(x,4);printf("  退出(E)   ");
		}
		else if(subSelect==3)
		{
			SetConsoleTextAttribute(hCon,47);
			gotoxy(x,3);printf("  返回(R)   ");
			SetConsoleTextAttribute(hCon,112);
			gotoxy(x,1);printf("  新建(N)   ");
			gotoxy(x,2);printf("  保存(S)   ");
			gotoxy(x,4);printf("  退出(E)   ");
		}
		else if(subSelect==4)
		{
			SetConsoleTextAttribute(hCon,47);
			gotoxy(x,4);printf("  退出(E)   ");
			SetConsoleTextAttribute(hCon,112);
			gotoxy(x,1);printf("  新建(N)   ");
			gotoxy(x,2);printf("  保存(S)   ");
			gotoxy(x,3);printf("  返回(R)   ");
		}
		break;
	case 2:
		if (subSelect==1)
		{
			SetConsoleTextAttribute(hCon,47);
			gotoxy(x,1);printf("  查找(F)   ");
			SetConsoleTextAttribute(hCon,112);
			gotoxy(x,2);printf("  替换(R)   ");
			gotoxy(x,3);printf("  删除(D)   ");
		}
		else if(subSelect==2)
		{
			SetConsoleTextAttribute(hCon,47);
			gotoxy(x,2);printf("  替换(R)   ");
			SetConsoleTextAttribute(hCon,112);
			gotoxy(x,1);printf("  查找(F)   ");
			gotoxy(x,3);printf("  删除(D)   ");
		}
		else if(subSelect==3)
		{
			SetConsoleTextAttribute(hCon,47);
			gotoxy(x,3);printf("  删除(D)   ");
			SetConsoleTextAttribute(hCon,112);
			gotoxy(x,1);printf("  查找(F)   ");
			gotoxy(x,2);printf("  替换(R)   ");
		}
		break;
	case 3:
		if (subSelect==1)
		{
			SetConsoleTextAttribute(hCon,47);
			gotoxy(x,1);printf("  换行(W)   ");
			SetConsoleTextAttribute(hCon,112);
			gotoxy(x,2);printf("  字体(F)   ");
		}
		else if(subSelect==2)
		{
			SetConsoleTextAttribute(hCon,112);
			gotoxy(x,1);printf("  换行(W)   ");
			SetConsoleTextAttribute(hCon,47);
			gotoxy(x,2);printf("  字体(F)   ");
		}
		break;
	case 4:
		SetConsoleTextAttribute(hCon,47);
		gotoxy(x,1);printf("  状态栏(S) ");break;
	case 5:
		if(subSelect==1)
		{
			SetConsoleTextAttribute(hCon,47);
			gotoxy(x,1);printf("  使用帮助  ");
			SetConsoleTextAttribute(hCon,112);
			gotoxy(x,2);printf("  关于本软件");
		}
		else if(subSelect==2)
		{
			SetConsoleTextAttribute(hCon,112);
			gotoxy(x,1);printf("  使用帮助  ");
			SetConsoleTextAttribute(hCon,47);
			gotoxy(x,2);printf("  关于本软件");
		}
		break;
	}

}

int ChangeFont() 
{
	SetConsoleTextAttribute(hCon,95);
	for(int i=5;i<20;++i)
	{
		gotoxy(5,i);
		printf("                                         ");
	}
	gotoxy(19,6);
	printf("改变字体颜色");
	gotoxy(11,8);
	printf("请选择你要改变的字体颜色:");
	gotoxy(13,10);
	printf("0 = 黑色        8 = 深灰色");
	gotoxy(13,11);
	printf("1 = 淡蓝色      9 = 蓝色");
	gotoxy(13,12); 
	printf("2 = 淡绿色      A = 绿色");
	gotoxy(13,13);
	printf("3 = 淡浅绿色    B = 湖蓝色 ");
	gotoxy(13,14);
	printf("4 = 淡红色      C = 红色");
	gotoxy(13,15);
	printf("5 = 淡紫色      D = 紫色");
	gotoxy(13,16);
	printf("6 = 淡黄色      E = 黄色");
	gotoxy(13,17);
	printf("7 = 灰色        F = 亮白色");
	int c;
	while((c=getch())<48||c>57&&(c>'F'||c<'A')&&(c>'f'||c<'a')&&c!=27)
		;
	if(c==27)
		return 0;
	if(c>='0'&&c<='9')return c-'0';
	return c-'a'+10;
}

void MainFrm(const stFrmInfo &frmInfo,int state,int changefont)
{

	SetConsoleTitle("小小记事本");
	system("mode concols=51 lines=31 "); 
	system("COLOR F0");	
	SetConsoleTextAttribute(hCon,1920);
	printf("\n 文件(F)  编辑(E)  格式(O)  查看(V)  帮助(H)       ");
	printf("                                                   ");
	gotoxy(0,30);
 	printf(" F1-选中菜单     ↑↓←→、Enter-选择     Esc-返回 ");
	gotoxy(0,31);
	if(state==1)
		printf("       位置:%3d行 %4d列       共%4d个字节 ",frmInfo.x+1,frmInfo.y+1,strlen(szText));
	else
		printf("                                               ");
	if(frmInfo.select)
	{
		SetConsoleTextAttribute(hCon,1823);
		switch (frmInfo.select)
		{
		case 1:gotoxy(0,0);printf(" 文件(F) ");break;
		case 2:gotoxy(9,0);printf(" 编辑(E) ");break;
		case 3:gotoxy(18,0);printf(" 格式(O) ");break;
		case 4:gotoxy(27,0);printf(" 查看(V) ");break;
		case 5:gotoxy(36,0);printf(" 帮助(H) ");break;
		}
	}
	
	gotoxy(0,2);
	SetConsoleTextAttribute(hCon,240+changefont);
	printf("%s",szText);
	if(frmInfo.hasMenu)
	{
		menu(frmInfo.select,frmInfo.subSelect);
	}
}

void HelpFrm()
{
	SetConsoleTextAttribute(hCon,92);
	for(int i=5;i<13;++i)
	{
		gotoxy(5,i);
		printf("                                         ");
	}
	gotoxy(19,6);
	printf("★使用帮助★");
	gotoxy(7,8);
	printf("1.“小小记事本”可以用来记录简单文档。");
	gotoxy(7,9);
	printf("2.在主窗体空白处输入文字。");
	gotoxy(7,10);
	printf("3.按F1选中菜单,上下左右键选择子菜单。");
	gotoxy(7,11);
	printf("4.按Enter键确认选项,按Esc退出程序。");
	getch();
}

void AboutFrm()
{
	SetConsoleTextAttribute(hCon,92);
	for(int i=5;i<13;++i)
	{
		gotoxy(5,i);
		printf("                                         ");
	}
	gotoxy(7,6);
	printf("小小记事本");
	gotoxy(7,8);
	printf("-版本 0.2");
	gotoxy(7,9);
	printf("-版权所无 (C) 2009");
	gotoxy(7,11);
	printf("-Directed by CAI");
	getch();
}

int ReturnFrm()
{
	SetConsoleTextAttribute(hCon,92);
	for(int i=8;i<14;++i)
	{
		gotoxy(5,i);
		printf("                                         ");
	}
	gotoxy(7,8);
	printf("提示:");
	gotoxy(7,10);
	printf("你确定要退出编辑吗?");
	gotoxy(7,11);
	printf("退出的话你修改的内容将不会保存!");
	gotoxy(7,12);
	printf("请确认是否退出:(Y-确认  N-取消)");
	int c;
	while((c=getch())!='Y'&&c!='y'&&c!='N'&&c!='n'&&c!=27)
		;
	if(c=='y'||c=='Y')
		return 1;
	else
		return 0;
}

void TextArea(int x,int y,int &size,int &select,int pre,int next,char *string)    //文本框
{
	int c;
	SetConsoleTextAttribute(hCon,240);
	gotoxy(x+size,y);
	c=getch();
	while(c!=224&&c!=8&&c!=9&&c!=13&&!isalnum(c))   //非字母和数字禁止输入
		c=getch();
	while(c==8&&size==0)     //当输入框为空时禁止删除
		c=getch();
	while(size>10&&c!=8&&c!=9&&c!=13)    //当超过11个字符时禁止输入
		c=getch();
	if(c==9||c==13)       //当输入为TAB或ENTER,确认输入
	{
		select=next;
	}
	else if(c==224)    //方向键
	{
		c=getch();
		if(c==72||c==75)
			select=pre;
		if(c==77||c==80)
			select=next;
	}
	else if(c==8)       //DELETE
		string[--size]='\0';
	else       //SAVE
	{
		string[size++]=c;    
		string[size]='\0';
	}
}

void Button(int x,int y,int pre,int next,int &select,char *text,void (*pfun)())    //按钮
{
	int c;
	SetConsoleTextAttribute(hCon,31);
	gotoxy(x,y);
	printf(" %s ",text);
	while((c=getch())!=9&&c!=13&&c!=224)
		;
	if(c==13)
	{
		pfun();
	}
	else if(c==224)
	{
		c=getch();
		if(c==72||c==75)
			select=pre;
		if(c==77||c==80)
			select=next;
	}
	else
		select=next;
}

void Replace()
{
	SetConsoleTextAttribute(hCon,92);
	for(int i=8;i<17;++i)
	{
		gotoxy(5,i);
		printf("                                         ");
	}
	gotoxy(7,9);
	printf("请输入你要替换的字符串,按回车结束:");
	gotoxy(7,12);
	printf("替换为:");

	gotoxy(7,11); 
	SetConsoleTextAttribute(hCon,240);
	printf("                                     ");
	gotoxy(7,13); 
	printf("                                     ");
	char szold[30];
	char sznew[30];
	gotoxy(7,11);
	gets(szold);
	gotoxy(7,13);
	gets(sznew);
	SetConsoleTextAttribute(hCon,94);
	gotoxy(7,15); 
	int n=0,c;
	char *pos=szText,*base;
	while((pos=strstr(pos,szold))!=0)
	{
		++n;
		++pos;
	}
	if(n==0)
		printf("          没找到 %s!! ",szold);
	else
	{
		int nold=strlen(szold);
		int nnew=strlen(sznew);
		printf("  共找到%d处!全部替换吗?(Y/N) ",n);
		n=0;
		
		while((c=getch())!='y'&&c!='Y'&&c!='n'&&c!='N')
			;
		if (topSelect==0)
		{
			base=pos=szInput;
		}
		else
			base=pos=topNine[topIndex-topSelect].szRecord;
		if(c=='y'||c=='Y')
		{
			while((pos=strstr(pos,szold))!=0)
			{
				memmove(pos+nnew,pos+nold,strlen(base)-(pos-base)-nold+1);
				memmove(pos,sznew,nnew);
				++pos;
			}
			SetConsoleTextAttribute(hCon,94);
			gotoxy(5,16);
			printf("              替换完成!!");
		}
	}
	getch();
}

void Search()
{
	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 search[30];
	gets(search);
	SetConsoleTextAttribute(hCon,94);
	gotoxy(7,14);
	int n=0;
	char *pos=szText;
	while((pos=strstr(pos,search))!=0)
	{
		++n;
		++pos;
	}
	if(n==0)
		printf("  没找到 %s!! ",search);
	else if(n==1)
	{
		pos=szText;
		pos=strstr(pos,search);
		printf("  共找到了1个! 位置在 :%d行 %d列 ",(pos-szText)/51+1,(pos-szText)%51+1);
	}
	else
	{
		n=0;
		int x=5,y=15;
		pos=szText;
		while((pos=strstr(pos,search))!=0)
		{
			++n;

⌨️ 快捷键说明

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