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

📄 win.h

📁 c游戏编程从入门到精通_全部源代码和文档
💻 H
字号:
#define WINDOWS 0
#define BUTTON 1
#define BUTTON_PRESS 2
#define BUTTON_SMALL 3
#define BUTTON_SMALL_PRESS 4
#define BUTTON_CLOSE 5
#define BUTTON_CLOSE_PRESS 6
#define BUTTON_MENU 7
#define BAR 8

#define BUTTON_COLOR 24
#define BUTTON_COLOR_LIGHT 7
#define BUTTON_COLOR_DARK 8

#define BUTTON_X 40
#define BUTTON_Y 10
#define BUTTON_XY 10

#define WINDOWS_X 0
#define WINDOWS_Y 186
#define WINDOWS_X_MOVE 319
#define WINDOWS_Y_MOVE 13

#define WINDOWS_COLOR_OUT 24
#define WINDOWS_COLOR_IN 15
#define WINDOWS_COLOR_LIGHT 7
#define WINDOWS_COLOR_DARK 8
#define WINDOWS_COLOR_TITLE 12

#define MAX 0
#define MIN 1

#define ACTIVE 1
#define NOACTIVE 0

#define ACTIVE_COLOR 1
#define NOACTIVE_COLOR 8

typedef struct point
{
	int x;
	int y;
}point;


typedef struct windows
{
	int kind;
	point top;
	point move;
	char *word;
	int color;
	int bk_color;
	int status;
//	char *ico;
//	void (far *build)();
	char *hotkey;
	void (far *windows)(struct windows *win);
	char far *background;
	int bk_flag;
	struct windows *next;
	struct windows *father;
	int active;
} windows, *windows_ptr;

windows_ptr head_win;
windows_ptr now_win;
windows_ptr pre_win;
windows_ptr menu_win;
windows_ptr win_now;
windows_ptr last;
int menuflag=MIN;

void men(windows_ptr win);

void Draw_Windows(windows_ptr win)
{
	switch(win->kind)
	{
		case WINDOWS:
		{
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x,win->top.y+win->move.y,WINDOWS_COLOR_DARK);
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x-1,win->top.y+win->move.y-1,WINDOWS_COLOR_LIGHT);
			Fill_Rectangle(win->top.x+1,win->top.y+1,win->top.x+win->move.x-1,win->top.y+win->move.y-1,WINDOWS_COLOR_OUT);
			Fill_Rectangle(win->top.x+1,win->top.y+1,win->top.x+win->move.x-1,win->top.y+10,WINDOWS_COLOR_TITLE);
			if(win->active==ACTIVE)
				Blit_String(win->top.x+2,win->top.y+2,win->color,win->word,1);
			else
				Blit_String(win->top.x+2,win->top.y+2,NOACTIVE_COLOR,win->word,1);
			Fill_Rectangle(win->top.x+2,win->top.y+22,win->top.x+win->move.x-2,win->top.y+win->move.y-2,WINDOWS_COLOR_LIGHT);
			Fill_Rectangle(win->top.x+2,win->top.y+22,win->top.x+win->move.x-3,win->top.y+win->move.y-3,WINDOWS_COLOR_DARK);
			Fill_Rectangle(win->top.x+3,win->top.y+23,win->top.x+win->move.x-3,win->top.y+win->move.y-3,WINDOWS_COLOR_IN);

			break;
		}
		case BAR:
		{
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x,win->top.y+win->move.y,WINDOWS_COLOR_DARK);
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x-1,win->top.y+win->move.y-1,WINDOWS_COLOR_LIGHT);
			Fill_Rectangle(win->top.x+1,win->top.y+1,win->top.x+win->move.x-1,win->top.y+win->move.y-1,WINDOWS_COLOR_OUT);
			if(win->active==ACTIVE)
			{
				Blit_String(win->top.x+79,win->top.y+3,WINDOWS_COLOR_LIGHT,win->word,1);
				Blit_String(win->top.x+80,win->top.y+4,WINDOWS_COLOR_DARK,win->word,1);
			}
			else
			{
				Blit_String(win->top.x+79,win->top.y+3,WINDOWS_COLOR_LIGHT,win->word,1);
				Blit_String(win->top.x+80,win->top.y+4,WINDOWS_COLOR_DARK,win->word,1);
			}
			break;
		}
		case BUTTON_MENU:
		{
			if(win->active==ACTIVE)
				Blit_String(win->top.x+2,win->top.y+1,win->color,win->word,1);
			else
				Blit_String(win->top.x+2,win->top.y+1,NOACTIVE_COLOR,win->word,1);
			break;
		}
		case BUTTON:
		{
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x,win->top.y+win->move.y,BUTTON_COLOR_DARK);
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR_LIGHT);
			Fill_Rectangle(win->top.x+1,win->top.y+1,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR);
			if(win->active==ACTIVE)
				Blit_String(win->top.x+2,win->top.y+1,win->color,win->word,1);
			else
				Blit_String(win->top.x+2,win->top.y+1,NOACTIVE_COLOR,win->word,1);
			break;
		}
		case BUTTON_PRESS:
		{
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x,win->top.y+win->move.y,BUTTON_COLOR_LIGHT);
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR_DARK);
			Fill_Rectangle(win->top.x+1,win->top.y+1,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR);
			Blit_String(win->top.x+2,win->top.y+1,win->color,win->word,1);
			break;
		}
		case BUTTON_CLOSE:
		{
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x,win->top.y+win->move.y,BUTTON_COLOR_DARK);
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR_LIGHT);
			Fill_Rectangle(win->top.x+1,win->top.y+1,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR);
			if(win->active==ACTIVE)
			{
				Bline(win->top.x+2,win->top.y+2,win->top.x+win->move.x-2,win->top.y+win->move.y-2,win->color);
				Bline(win->top.x+win->move.x-2,win->top.y+2,win->top.x+2,win->top.y+win->move.y-2,win->color);
			}
			else
			{
				Bline(win->top.x+2,win->top.y+2,win->top.x+win->move.x-2,win->top.y+win->move.y-2,NOACTIVE_COLOR);
				Bline(win->top.x+win->move.x-2,win->top.y+2,win->top.x+2,win->top.y+win->move.y-2,NOACTIVE_COLOR);
			}
			break;
		}
		case BUTTON_CLOSE_PRESS:
		{
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x,win->top.y+win->move.y,BUTTON_COLOR_LIGHT);
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR_DARK);
			Fill_Rectangle(win->top.x+1,win->top.y+1,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR);
			Bline(win->top.x+2,win->top.y+2,win->top.x+win->move.x-2,win->top.y+win->move.y-2,win->color);
			Bline(win->top.x+win->move.x-2,win->top.y+2,win->top.x+2,win->top.y+win->move.y-2,win->color);
			break;
		}
		case BUTTON_SMALL:
		{
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x,win->top.y+win->move.y,BUTTON_COLOR_DARK);
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR_LIGHT);
			Fill_Rectangle(win->top.x+1,win->top.y+1,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR);
			if(win->active==ACTIVE)
				H_Line(win->top.x+2,win->top.x+win->move.x-2,win->top.y+win->move.y-2,win->color);
			else
				H_Line(win->top.x+2,win->top.x+win->move.x-2,win->top.y+win->move.y-2,NOACTIVE_COLOR);
			break;
		}
		case BUTTON_SMALL_PRESS:
		{
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x,win->top.y+win->move.y,BUTTON_COLOR_LIGHT);
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR_DARK);
			Fill_Rectangle(win->top.x+1,win->top.y+1,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR);
			H_Line(win->top.x+2,win->top.x+win->move.x-2,win->top.y+win->move.y-2,win->color);
			break;
		}
		default:break;
	}
}

void Object_Init(windows_ptr ptr,int kind,int x,int y,int move_x,int move_y,char *word,int color,int bk_color,int status,char *hotkey,int bk_flag,void (far *windows),int active)
{
	ptr->kind=kind;
	ptr->top.x=x;
	ptr->top.y=y;
	ptr->move.x=move_x;
	ptr->move.y=move_y;
	ptr->word=word;
	ptr->color=color;
	ptr->bk_color=bk_color;
	ptr->status=status;
	ptr->hotkey=hotkey;
	ptr->windows=windows;
	ptr->bk_flag=bk_flag;
	if(bk_flag==1)
		ptr->background=(char far *)malloc( (move_x+1)* (move_y+1)+1);
	ptr->active=active;
}

void Behind_Button(windows_ptr win)
{

char far *work_back;
int work_offset=0,offset,y;


work_back = win->background;


offset = (win->top.y << 8) + (win->top.y << 6) + win->top.x;

for (y=0; y<BUTTON_Y; y++)
    {

    _fmemmove((void far *)&work_back[work_offset],
	     (void far *)&video_buffer[offset],
	     BUTTON_X);


    offset      += SCREEN_WIDTH;
    work_offset += BUTTON_X;

    }

}

void Erase_Button(windows_ptr win)
{

char far *work_back;
int work_offset=0,offset,y;


work_back = win->background;


offset = (win->top.y << 8) + (win->top.y << 6) + win->top.x;

for (y=0; y<BUTTON_Y; y++)
    {

    _fmemmove((void far *)&video_buffer[offset],
	     (void far *)&work_back[work_offset],
	     BUTTON_X);


    offset      += SCREEN_WIDTH;
    work_offset += BUTTON_X;

    }

}
void Behind_Object(windows_ptr win)
{

char far *work_back;
int work_offset=0,offset,y;


work_back = win->background;


offset = (win->top.y << 8) + (win->top.y << 6) + win->top.x;

for (y=0; y<win->move.y+1; y++)
    {

    _fmemmove((void far *)&work_back[work_offset],
	     (void far *)&video_buffer[offset],
	     win->move.x+1);


    offset      += SCREEN_WIDTH;
    work_offset += win->move.x+1;

    }

}

void Erase_Object(windows_ptr win)
{

char far *work_back;
int work_offset=0,offset,y;


work_back = win->background;


offset = (win->top.y << 8) + (win->top.y << 6) + win->top.x;

for (y=0; y<win->move.y+1; y++)
    {

    _fmemmove((void far *)&video_buffer[offset],
	     (void far *)&work_back[work_offset],
	     win->move.x+1);


    offset      += SCREEN_WIDTH;
    work_offset += win->move.x+1;

    }

}

void Object_Delete(windows_ptr win)
{

	int index;

	if(win->bk_flag==1)
		free(win->background);
	free(&win);
}

void Free_Object(void)
{
	windows_ptr restore;
	restore=head_win;
	if(restore->bk_flag==1)
	{
		Erase_Object(restore);
		Object_Delete(restore);
	}
	do{
		restore=restore->next;
		if(restore->bk_flag==1)
		{
			Erase_Object(restore);
		}
		Object_Delete(restore);
	}while(restore->next!=NULL);
	head_win=NULL;

}

void win(windows_ptr win)
{
//	printf("\n\n\n\n\nwindows fuction is in use\n");
}

void clo(windows_ptr win)
{
	win->kind=BUTTON_CLOSE_PRESS;
	Draw_Windows(win);
	Delay(5);
	win->kind=BUTTON_CLOSE;
	Draw_Windows(win);
	Delay(5);
	Free_Object();
	Set_Video_Mode(TEXT_MODE);
	exit(1);
}

void bt1(windows_ptr win)
{
	int x,y,fcolor;
	long i;
	win->kind=BUTTON_PRESS;
	Draw_Windows(win);
	Delay(5);
	win->kind=BUTTON;
	Draw_Windows(win);
	men(win->father);
}

void bt2(windows_ptr win)
{
	win->kind=BUTTON_PRESS;
	Draw_Windows(win);
	Delay(5);
	win->kind=BUTTON;
	Draw_Windows(win);
	Delay(5);
	Free_Object();
	Set_Video_Mode(TEXT_MODE);
	exit(1);
}

void sma(windows_ptr win)
{
	win->kind=BUTTON_SMALL_PRESS;
	Draw_Windows(win);
	Delay(5);
	win->kind=BUTTON_SMALL;
	Draw_Windows(win);
	Blit_String(WINDOWS_X+10,WINDOWS_Y+30,0,"small button is in use",1);
	Free_Object();
}

void men(windows_ptr win)
{
	windows_ptr restore;
	win->kind=BUTTON_PRESS;
	Draw_Windows(win);
	Delay(5);
	win->kind=BUTTON;
	Draw_Windows(win);
	if(win->status==MIN)
	{
		now_win=(struct windows *)malloc(sizeof(struct windows));
		Object_Init(now_win,BUTTON,WINDOWS_X+2,WINDOWS_Y-BUTTON_Y*2,BUTTON_X-1,BUTTON_Y-1,"game",0,24,0,"",1,bt1,NOACTIVE);
		now_win->father=win;
		Behind_Object(now_win);
		Draw_Windows(now_win);
		last->next=now_win;
		pre_win=now_win;
		now_win=(struct windows *)malloc(sizeof(struct windows));
		Object_Init(now_win,BUTTON,WINDOWS_X+2,WINDOWS_Y-BUTTON_Y,BUTTON_X-1,BUTTON_Y-1,"exit",0,24,0,"",1,bt2,ACTIVE);
		now_win->father=win;
		Behind_Object(now_win);
		Draw_Windows(now_win);
//		getch();
//		Erase_Button(now_win);
//		getch();
		pre_win->next=now_win;
		pre_win=now_win;
		pre_win->next=NULL;

		win->status=MAX;
		menuflag=MAX;
	}
	else if(win->status==MAX)
	{
		restore=head_win;
		do{
			restore=restore->next;
			if(restore->bk_flag==1)
			{
				Erase_Object(restore);
				Object_Delete(restore);
			}
		}while(restore->next!=NULL);
		last->next=NULL;
		win->status=MIN;
		menuflag=MIN;
	}
}

void Build_Object()
{
	now_win=pre_win=(struct windows *)malloc(sizeof(struct windows));
	Object_Init(now_win,BAR,WINDOWS_X,WINDOWS_Y,WINDOWS_X_MOVE,WINDOWS_Y_MOVE,"This is a game desktop",0,24,0,"",1,win,ACTIVE);
	Behind_Object(now_win);
	win_now=now_win;
	Draw_Windows(now_win);
	head_win=now_win;
	now_win=(struct windows *)malloc(sizeof(struct windows));
	Object_Init(now_win,BUTTON,WINDOWS_X+2,WINDOWS_Y+2,BUTTON_X-1,BUTTON_Y-1,"Star",0,24,MIN,"",0,men,ACTIVE);//start is 5 word which is too long
	Draw_Windows(now_win);
	pre_win->next=now_win;
	pre_win=now_win;
	now_win=(struct windows *)malloc(sizeof(struct windows));
	Object_Init(now_win,BUTTON_SMALL,WINDOWS_X+WINDOWS_X_MOVE-(BUTTON_XY+2)*2,WINDOWS_Y+2,BUTTON_XY-1,BUTTON_XY-1,"",0,24,MAX,"",0,sma,ACTIVE);
	Draw_Windows(now_win);
	pre_win->next=now_win;
	pre_win=now_win;
	now_win=(struct windows *)malloc(sizeof(struct windows));
	Object_Init(now_win,BUTTON_CLOSE,WINDOWS_X+WINDOWS_X_MOVE-BUTTON_XY-2,WINDOWS_Y+2,BUTTON_XY-1,BUTTON_XY-1,"",0,24,0,"",0,clo,ACTIVE);
	Draw_Windows(now_win);
	pre_win->next=now_win;
	pre_win=now_win;
	pre_win->next=NULL;
	last=pre_win;

}



void Judge_Object(void)
{
	int xmouse,ymouse,btnmouse;
	static int btn=-1;
	windows_ptr test;
	Squeeze_Mouse(MOUSE_MOTION_REL,&xmouse,&ymouse,&btnmouse);
	if(ymouse==199&&head_win==NULL)
	{
		Squeeze_Mouse(MOUSE_HIDE,0,0,0);
		Build_Object();
		Squeeze_Mouse(MOUSE_SHOW,0,0,0);
	}
	if(ymouse<=185&&menuflag!=MAX&&head_win!=NULL)
	{
		Squeeze_Mouse(MOUSE_HIDE,0,0,0);
		Free_Object();
		Squeeze_Mouse(MOUSE_SHOW,0,0,0);
	}
	Squeeze_Mouse(MOUSE_BUTT_POS,&xmouse,&ymouse,&btnmouse);
	if(btnmouse==btn)
		return;
	else
		btn=btnmouse;
	xmouse=xmouse/2;
	ymouse=ymouse;
	if(btnmouse==1)
	{
		if(head_win!=NULL)
		{
		test=head_win;
		if((xmouse>=test->top.x&&xmouse<=test->top.x+test->move.x)&&
		(ymouse>=test->top.y&&ymouse<=test->top.y+test->move.y))
		{
			Squeeze_Mouse(MOUSE_HIDE,0,0,0);
			if(test->active==ACTIVE)
				test->windows(test);
			Squeeze_Mouse(MOUSE_SHOW,0,0,0);
		}
		do{
			test=test->next;
			if((xmouse>=test->top.x&&xmouse<=test->top.x+test->move.x)&&
			(ymouse>=test->top.y&&ymouse<=test->top.y+test->move.y))
			{
				Squeeze_Mouse(MOUSE_HIDE,0,0,0);
				if(test->active==ACTIVE)
					test->windows(test);
				Squeeze_Mouse(MOUSE_SHOW,0,0,0);
			}
		}while(test->next!=NULL);
		}
	}
}

⌨️ 快捷键说明

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