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

📄 windows.cpp

📁 一个微型操作系统源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
#include"splendor\pop.cpp"
#include"splendor\copy.cpp"
#include"shell.cpp"
char curr_directory[50],clipboard[50]={'0'};
Directory curry_dir("C:\\DESKTOP");
extern char Desktop_Color,Resolution;
struct win_properties
{	char fcolor,bcolor;
}win;
int tempx;
void Button(int x,int y,char press)
{       char c1,c2,c,fc;
	int width=70,height=35;
	if(!press)
	{	c1=0;c2=15;
		c=8;fc=15;
	}
	else
	{   c1=15;c2=0;c=7;fc=0;}
	bar(x,y,width,height,c);
	vline(x,y,height,c2);
	hline(x,y,width,c2);
	vline(x+width,y,height,c1);
	hline(x,y+height,width,c1);
}
void Message_Window(int x,int y,int wd,int ht,char *name)
{   int tht=30;
	bar(x,y,wd,tht,1);      //titlebar
	bar(x,y,wd,5,7); //border of titlebar
	hline(x,y+2,wd,15);
	hline(x,y+3,wd,0);
   //	load_font(1);
	write(x+11,y+11,15,name);      //address
 //	load_font(3);
	bar(x,y+tht,wd,ht-(tht+1),28);        //body
	hline(x,y+tht,wd,15);
	bar(x,y+ht-5,wd,5,7); //bar after body
	hline(x,y+ht-2,wd,0);
	hline(x,y+ht-4,wd,15);
	// vlines of window border
	bar(x,y,5,ht,7); //border of titlebar
	vline(x+1,y+2,ht-2,15);
	vline(x+3,y+3,ht-3,0);
	bar(x+wd-5,y,5,ht,7); //border of titlebar
	vline(x+wd-4,y+2,ht-2,0);
	vline(x+wd-2,y+3,ht-3,15);

}
void Error(char *mess)
{
	       int x=xmax/2-150,y=ymax/2-100,ht=120,wd=400,i=0;
		char w[50]={'e'},c1,c2;
		Message_Window(x,y,wd,ht,"OPEN");
		write(x+40,y+50,0,mess);
		asm{ mov ax,0h;
		int 16h;
		}

}
char* Get_File()
{       int x=xmax/2-150,y=ymax/2-100,ht=120,wd=400,startx,starty,i=0;
	static char w[50]={'e'},c1,c2;
	Message_Window(x,y,wd,ht,"OPEN");
	write(x+40,y+50,0,"L o c a t i o n :");
	bar(x+30,y+65,350,20,15);
	rectangle(x+30,y+65,350,20,0);
	startx=x+32;
	starty=y+70;
	while(1)
	{
		asm{   mov  ah,00h;
		       int  16h;
		       mov c1,al;
		       mov c2,ah;
		    }
		if(c2==0x1c||c2==0x01)
		{      if(c2==0x01) w[0]='e';
			return w;
		}
		if(c1==0x08&&c2==0x0E)
		    {
		      if(i>0) { i--; w[i]='\0'; }
		    }
		 else
		   {
			w[i++]=c1;
			w[i]='\0';
		    }
		if(startx+(i*8)<x+372)
		write(startx,starty,0,w);
	}
      //	return("hjfgs");
}

int Turn_Off()
{       char c1,*t1[2]={"Turn off","Reboot"};
	int x=xmax/2-150,y=ymax/2-100,ht=120,wd=300,s=0;
	Message_Window(x,y,wd,ht,"TURN OFF SPLENDOR");
	bar(x+30,y+50,100,20,1);
	rectangle(x+30,y+50,100,20,15);
	write(x+50,y+55,43,t1[0]);
	while(1)
	{
		asm{    mov  ah,00h;
			int  16h;
			mov c1,ah;
		   }
		if(c1==0x50||c1==0x48)
		{
			if(c1==0x50)//downarrow
			{	if(s==0)s=1;}
			else if(c1==0x48)//uparrow
			{       if(s==1)s=0;}
			bar(x+30,y+50,100,20,1);
			rectangle(x+30,y+50,100,20,15);
			write(x+35,y+55,43,t1[s]);
		}
		else if(c1==0x01) return -1;
		else if(c1==0x1c)
		return s;

	}
}

void TXT_Reader(char* path)
{       char *buffer,c1;
	buffer=new char[2];
	int startx=100,starty=50,m;
	Message_Window(0,0,xmax,winy,"SPLENDOR READER");
	      //	Message_Window(0,0,xmax,winy,path);
       //	bar(15);
       //	bar(15);
       //	write(200,200,0,path);
	File f;
	m=f.file_open(path,RO);
	buffer[0]=f.fget_char();
	buffer[1]='\0';
	while(buffer[0]==13)
	{	*buffer=f.fget_char();
		*buffer=f.fget_char();
		*(buffer+1)='\0';
		starty+=16;
		startx=100;
	}
	while(!f.eof)
	{      Message_Window(0,0,xmax,winy,"SPLENDOR READER");
		startx=100;
		starty=50;
		while(!f.eof&&starty<winy-30)
		{       write(startx,starty,1,buffer);
			buffer[0]=f.fget_char();
			buffer[1]='\0';
			while(buffer[0]==13)
			{	*buffer=f.fget_char();
				*buffer=f.fget_char();
				*(buffer+1)='\0';
				starty+=16;
				startx=100;
			}
	      //	if(flag==0)index++;
			startx+=8;
			if(startx>=xmax-100)
			{	starty+=20;
				startx=100;
			}
		}

		asm{	mov ax,0;
			int 16h;
			mov c1,ah;
			}
		if(c1==0x01||f.eof)break;
	}
}
void Change_Color(char desktop)
{       char *name,c1,color;
	int x=200,y=200,ht=200,wd=350;
	if(desktop)
	{	name="Desktop Color";
		color=Desktop_Color;
	}
	else
	{       name="Frame Settings";
		 color=win.bcolor;
	}
	Message_Window(x,y,wd,ht,name);
	rectangle(x+wd/2-1,y+75-1,102,102,15);
	bar(x+wd/2,y+75,100,100,color);
	while(1)
	{
		asm{    mov  ah,00h;
			int  16h;
			mov c1,ah;
		   }
		if(c1==0x50||c1==0x48)
		{
			if(c1==0x50)//downarrow
			color++;
			else if(c1==0x48)//uparrow
			color--;
			bar(x+wd/2,y+75,100,100,color);
		}
		else if(c1==0x01) break;
		else if(c1==0x1c)
		{       if(desktop)
			Desktop_Color=color;
			else win.bcolor=color;
			break;
		}
	}
}
void Change_Resolution()
{       char *name="Set Resolution",c1,color,*t1[3]={"640 x 480","800 x 600","1024 x 768"};
	int x=200,y=200,ht=100,wd=350,res;

	res=Resolution;
	Message_Window(x,y,wd,ht,name);
	bar(x+30,y+50,100,20,1);
	rectangle(x+30,y+50,100,20,15);
	write(x+35,y+55,43,t1[res]);
	while(1)
	{
		asm{    mov  ah,00h;
			int  16h;
			mov c1,ah;
		   }
		if(c1==0x50||c1==0x48)
		{
			if(c1==0x50)//downarrow
				res=(res+1)%3;
			else if(c1==0x48)//uparrow
			if(res>0)res=(res-1)%3;
			else res=2;
			bar(x+30,y+50,100,20,1);
			rectangle(x+30,y+50,100,20,15);
			write(x+35,y+55,43,t1[res]);
		}
		else if(c1==0x01) break;
		else if(c1==0x1c)
		{       Resolution=res;
			init(Resolution);
			break;
		}
	}
}
void System_Icon(int x,int y,int select)
{ 	char color,color1;
	if(select==0)
	{	color=7;
		color1=20;
	}
	else
	{	color=1;
		color1=1;
	}
	bar(x,y,40,40,color);
	rectangle(x,y,40,40,23);
	bar(x+5,y+5,30,30,54);
	bar(x+7,y+8,5,5,color1);
	bar(x+7,y+18,5,5,color1);
	bar(x+7,y+28,5,5,color1);
	bar(x+15,y+8,5,5,color1);
	bar(x+15,y+18,5,5,color1);
	rectangle(x+5,y+5,30,30,23);
	bar(x+5,y+40,30,5,color);
	rectangle(x+4,y+39,32,7,23);
	fill_par(x,y+45,40,15,-1,color);
	fill_par(x+8,y+48,30,1,-1,23);
	fill_par(x+12,y+52,30,1,-1,23);
	fill_par(x+16,y+56,30,1,-1,23);
	bar(x+16,y+61,40,2,color);
}

class Tool_Bar
{	public :char height,color,fcolor,bcolor,button_width;
			Tool_Bar();
			void Draw_Bar(char);
			void Select_Deselect(char,int);
};

Tool_Bar::Tool_Bar()
{	height=30;
	color=7;
	fcolor=15;
	button_width=44;
}

void Tool_Bar::Draw_Bar(char obj)
{   int x,y,i,jmax;
	if(obj=='t')
	{	 jmax=1;
		 x=0;
		 y=winy;
		 bcolor=8;
	}
	else
	{	 jmax=3;
		 bcolor=7;
		 i=Active_Count+1;
		 x=Active_Position[i][0];
		 y=Active_Position[i][1];
	}
	bar(x,y,xmax-1,height,color);
 //	vline(x,y,height,15);
	hline(x,y,xmax-1,15);
//	vline(,y+5,height-10,0);
	hline(x,y+height-1,xmax-1,15);
	bar(x,y+height,xmax-1,3,7); //bar after filebar
	hline(x,y+height+1,xmax-1,0);
	for(i=0;i<jmax;i++)
	{       bar(x+2,y+5,button_width,height-10,bcolor);
		vline(x+2,y+5,height-10,15);
		hline(x+2,y+5,button_width,15);
		vline(x+button_width+2,y+5,height-10,0);
		hline(x+2,y+height-5,button_width,0);
		Active_Position[Active_Count+1+i][0]=x;
		Active_Position[Active_Count+1+i][1]=y;
		x+=button_width+2;
	 }
	 if(obj=='t')
	 {  	x=0;
		load_font(1);
		write(x+5,y+9,fcolor,"TASKS");
		load_font(3);
	 }
	 else
	 {  load_font(3);
	    x=Active_Position[Active_Count+1][0]+2;
		write(x+6,y+12,fcolor,"File");  x+=button_width+2;
	    write(x+6,y+12,fcolor,"Edit");  x+=button_width+2;
		write(x+6,y+12,fcolor,"View");  x+=button_width+2;
	 }

}

void Tool_Bar::Select_Deselect(char key,int select)
{       int x,y,i;
		char c1,c2,c,fc;
		if(!select)
		{	c1=0;c2=15;c=8;fc=15;}
		else
		{   c1=15;c2=0;c=7;fc=0;}
		if(key=='t')
		{	x=Active_Position[Active_Count][0];
			y=Active_Position[Active_Count][1];
		}
		else
		{   if(!select)c=7;
			if(key=='f') i=0;
			else if(key=='e') i=1;
			else if(key=='v') i=2;
			x=Active_Position[Active_Count+1][0]+(i*(button_width+2));
			y=Active_Position[Active_Count+1][1];
		}
		bar(x+2,y+5,button_width,height-10,c);
		vline(x+2,y+5,height-10,c2);
		hline(x+2,y+5,button_width,c2);
		vline(x+button_width+2,y+5,height-10,c1);
		hline(x+2,y+height-5,button_width,c1);

		if(key=='t')
		{   load_font(1);
			write(x+5,y+9,fc,"TASKS");
			load_font(3);
		}
		else
		{   load_font(3);
			if(key=='f')write(x+6,y+12,fc,"File");
			else if(key=='e')write(x+6,y+12,fc,"Edit");
			else if(key=='v')write(x+6,y+12,fc,"View");
		   //	if(select)
		}

}


class Icons
{
	public :char fcolor,bcolor,hfcolor,hbcolor,obj;
		int height,width;
		Icons(char);
		void Draw(int,char);
		void Icon_Draw(int,int,int);
		void List_Draw(int,char,char);
};

Icons::Icons(char o)
{   obj=o;
	if(obj==0) bcolor=56; //object is desktop
	else if(obj==1)bcolor=15; //object is window
	else if(obj==2)
	{	bcolor=7;
		fcolor=7;
	}
	//setting fontcolor,highlighted background and font color
	fcolor=0;
	hbcolor=1;
	hfcolor=15;
}

void Icons::Draw(int i,char select)  // for desktop & windows
{   int x=Active_Position[i][0],j;
	int y=Active_Position[i][1];
	char color,fc,*dt;
	type t=Active_Type[i];
	if(t==0)                  // Folders
	{	height=20;
		width=40;
		if(select==0) color=43;
		else color=1;
		if(obj) y+=30;
		fill_par(x,y+2,30,18,1,color);
		rectangle(x-17,y+5,30,16,8);
		bar(x-16,y+6,28,14,color);
		x-=height;
	}
	else if(t==1)             // Files
	{	height=50;
		width=40;
		if(select==0) color=4;
		else color=1;
		bar(x,y,1,50,color); //v
		bar(x,y,20,1,color); //h
		//triangle
		bar(x+20,y,1,15,color);  //v
		bar(x+20,y+15,15,1,color);//h
		line(x+20,y,x+35,y+15,color);
		//----------
		bar(x+33,y+15,3,38,color);   //v
		bar(x,y+50,35,3,color);  //h
		// three lines

		bar(x+5,y+23,25,1,0);   //h
		bar(x+8,y+30,22,1,0);  //h
		bar(x+11,y+37,19,1,0);//h

	}
	else if(t==system)
	{	height=62;
		width=40;
		System_Icon(x,y,select);
		x+=8;
	}
	else if(t==floppy)
	{       height=42;
		width=50;
		if(select==0) color=20;
		else color=1;
		bar(x,y,50,40,color);
		bar(x+10,y-2,30,15,23);
		if(select==0) color=0;
		else color=1;
		bar(x+32,y+1,5,10,color);
		bar(x+7,y+17,36,20,15);
		bar(x+2,y+30,3,5,25);
		bar(x+46,y+30,3,5,25);
		line(x+10,y+20,x+40,y+20,0);
		line(x+10,y+24,x+40,y+24,0);
		line(x+10,y+28,x+40,y+28,0);
		line(x+10,y+32,x+40,y+32,0);
	}
	else if(t==drive)
	{   height=20;
	    width=45;
	    if(select==0) color=7;
	    else color=1;
	    bar(x+1,y-1,width,height,color);
	    bar(x,y,width,height,color);           //background
	    rectangle(x,y,width,height,19);
	    bar(x+5,y+14,width-10,1,15);    // lines
	    bar(x+5,y+12,width-10,1,15);
	    bar(x+5,y+10,width-10,1,15);
	    bar(x+width/2-2,y+height,5,7,color);
	    bar(x,y+height+8,width+2,5,color);
	    rectangle(x,y+height+8,width+2,5,23);
	    bar(x,y+height+10,width,1,15);
	    bar(x+width/2-6,y+height+7,15,8,color);
	    rectangle(x+width/2-6,y+height+6,15,10,23);
	    height+=16;
       }
       else if(t==bmp)
       {        y+=20;
		height=25;
		width=53;
		int wd=45,ht=20;
		if(select==0) color=15;
		else color=1;
		bar(x+5,y-15,wd-15,ht+20,color); // paper
		rectangle(x+5,y-15,wd-15,ht+20,8);
		bar(x+7,y-11,wd-20,ht+12,4);       // frame
		line(x+13,y+18,x+17,y-9,10);    // picture
		line(x+25,y+18,x+20,y-9,10);
		hline(x+13,y+18,wd-34,10);
		fill_par(x,y,wd,ht-5,1,color);   // palette background
		bar(x,y+2,wd-38,ht-15,2);                // palette
		fill_par(x+25,y-20,wd-41,ht+5,1,24);   //brush
		bar(x+9,y+2,wd-40,ht-15,0);           // palette
		bar(x+17,y+2,wd-40,ht-15,6);
		bar(x+24,y+2,wd-40,ht-15,4);
		bar(x+32,y+2,wd-40,ht-15,1);
		bar(x-5,y+8,wd-40,ht-15,5);
		bar(x+2,y+8,wd-40,ht-15,8);
		bar(x+9,y+8,wd-40,ht-15,12);
		bar(x+17,y+8,wd-40,ht-15,43);
		bar(x+25,y+8,wd-40,ht-15,13);
	     //	height+=20;
       }
       else                              //Unknown files
       {	height=30;
		width=40;
		if(obj) y+=20;
		if(!select) { color=47;fc=0;}
		else {color=1;fc=15;}
		/*fill_circle(x+19,y+15,15,0);
		fill_circle(x+15,y+15,15,color);     */
		fill_par(x+19,y+10,5,15,1,color);
		fill_par(x+5,y+10,5,15,-1,color);
	}
	if(select==0)                 // If selected
	{      color=bcolor;
	       fc=fcolor;
	}
	else                           // If not yet selected or deselected
	{      color=hbcolor;
	       fc=hfcolor;
	}

	dt=Active_List[i];
	for(j=0;dt[j]!='\0';j++);
	size=j*8;
	if(size<=width)
		x+=(width-size)/2;
	else x-=(size-width)/2;
	bar(x-2,y+height+10,size+4,12,color);
	load_font(3);
	write(x,y+height+12,fc,Active_List[i]);
		  /*if(select==1)
		  rectangle_shade(x-10,y+height+10,width+20,12,15);  */
}

void Icons::Icon_Draw(int x,int y,int i)  // for properties
{
	char color;
	type t=Active_Type[i];
	if(t==0)                  // Folders
	{	height=20;
		width=40;
		color=43;
		x+=10;
		fill_par(x,y,35,20,1,color);
		rectangle(x-20,y+5,35,15,8);
		bar(x-19,y+6,33,13,color);
	}
	else if(t==1)             // Files
	{	height=50;
		width=40;
		color=4;
		bar(x,y,1,50,color); //v
		bar(x,y,20,1,color); //h
		//triangle
		bar(x+20,y,1,15,color);  //v
		bar(x+20,y+15,15,1,color);//h
		line(x+20,y,x+35,y+15,color);
		//----------
		bar(x+33,y+15,3,38,color);   //v
		bar(x,y+50,35,3,color);  //h
		// three lines

		bar(x+5,y+23,25,1,0);   //h
		bar(x+8,y+30,22,1,0);  //h
		bar(x+11,y+37,19,1,0);//h
	}

⌨️ 快捷键说明

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