|
6#
![](static/image/common/ico_lz.png)
楼主 |
发表于 2010-5-28 21:57:39
|
只看该作者
补上源码,各位高手不要见笑小弟的程序代码~~
另,如哪位高手将代码更新的话请贴切上来,感谢!
/*=========================================================================================*/
/* Last Mod Data:2009.05.10 */
/* Program By Plum QQ:393591090 */
/* Ver:3.0 */
/*==============================================================================================*/
#include"dos.h"
#include"conio.h"
#include"graphics.h"
#include"alloc.h"
#include"stdlib.h"
#include"math.h"
#include"stdio.h"
#include"bios.h"
#include <io.h>
#include <fcntl.h>
#include <sys\stat.h>
#include <time.h>
#include <sys\types.h>
/*关机重启宏定义*/
#define Bs 0x8
#define Tab 0x9
#define Esc 27
#define Enter 0xd
static int focX,focY;/*当前X与Y坐标*/
static int CKeyCode;/*保存用光标移动键盘时的键盘ASCII码*/
static int KeyPushCount;/*方向键按下的总数*/
static int CuFocXY;/*当前X与Y坐标值相加的值,用于判断用方向键+回车后将要处理的事务*/
/*获取键盘码*/
int GET_KEY()
{
int key;
while(bioskey(1)==0);
key=bioskey(0);
return(key&0xff?key&0xff:key>>8);
}
/*汉字显示函数*/
void hz(int firstx,int firsty,int color,char *p)
{
int x,x0=0,y=0,i,j,pos;
unsigned char qh,wh;
unsigned long offset;
unsigned char mask[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
char mat[32];
FILE *fp=fopen("hzk16","rb");/*hzk16*/
while(*p){
qh=*p-0xa0;
wh=*(p+1)-0xa0;
offset=(94*(qh-1)+(wh-1))*32L;
fseek(fp,offset,SEEK_SET);
fread(mat,32,1,fp);
for (i=0;i<16;i++)
{
x=x0;
pos=2*i;
for(j=0;j<16;j++)
{
if ((mask[j%8]&mat[pos+j/8])!=NULL)
putpixel(x+firstx,y+firsty,color);
x++;
}
y++;
}
p+=2,x0+=20,y=0;
}
fclose(fp);
}
/*关闭计算机*/
void off()
{
union REGS r;
r.x.ax=0x5300;
r.x.bx=0;
int86(0x15,&r,&r);
r.x.ax=0x5308;
r.x.bx=1;
r.x.cx=1;
int86(0x15,&r,&r);
r.x.ax=0x5308;
r.x.bx=0x0ffff;
r.x.cx=1;
int86(0x15,&r,&r);
r.x.ax=0x5301;
r.x.bx=0;
int86(0x15,&r,&r);
r.x.ax=0x530e;
r.x.bx=0;
int86(0x15,&r,&r);
r.x.ax=0x530d;
r.x.bx=1;
r.x.cx=1;
int86(0x15,&r,&r);
r.x.ax=0x530f;
r.x.bx=1;
r.x.cx=1;
int86(0x15,&r,&r);
r.x.ax=0x5307;
r.x.bx=1;
r.x.cx=3;
int86(0x15,&r,&r);
r.x.ax=0x4c00;
int86(0x20,&r,&r);
}
/*重新启动计算机*/
Reboot()
{
typedef void interrupt (*FP) ();
FP Reset;
Reset = (FP) MK_FP(peek(0xffff, 0x0003), peek(0xffff, 0x0001));
Reset();
}
/*初始化显卡*/
void InitGra()
{
int gd=DETECT,gm;
registerbgidriver(EGAVGA_driver);
initgraph(&gd,&gm,"");
}
/*绘制主窗口*/
void DrawWin()
{
setbkcolor(BLACK);/*设置背景*/
setcolor(WHITE);
settextstyle(2,0,4);
outtextxy(1,460,"Corpyright (C) BM S.T.C Corp. 1999-2009. All rights reserved.");
outtextxy(1,470,"Program by Plum QQ:393591090 Email:lch9906@126.com NetDisk:http://lch9906.ys168.com");
/*屏幕中心文字*/
setcolor(GREEN);
settextstyle(2,0,9);
outtextxy(10,10,"Welcome to use BM S.T.C DOS TOOL");
setcolor(WHITE);
/*外围框*/
setfillstyle(1,WHITE);
bar(504,98,140,403);
/*绘制标题栏*/
setfillstyle(1,1);
bar(142,120,502,100);
setcolor(15);
rectangle(142,120,502,100);
/*标题文字*/
hz(145,102,7,"便民科技");
setcolor(7);
settextstyle(2,0,7);
outtextxy(225,100,"DOS");
hz(263,102,7,"工具");
settextstyle(2,0,5);
outtextxy(300,105," Ver:3.0 Build 0510");
/*绘制标题栏按钮*/
setcolor(BLACK);
settextstyle(2,0,5);
line(142,120,501,120);/*模拟标题栏-横线*/
/*绘制模拟最小化按钮*/
setfillstyle(1,8);
bar(470,104,482,116);
setcolor(15);
rectangle(470,104,482,116);
/*绘制模拟关闭按钮*/
setfillstyle(1,8);
bar(485,104,497,116);
setcolor(15);
rectangle(485,104,497,116);
line(473,110,479,110);/*模拟关闭按钮*/
line(486,115,496,105);/*模拟关闭按钮*/
line(497,116,486,105);/*模拟最小化按钮*/
/*绘制操作区主窗口*/
setfillstyle(1,8);
bar(142,122,502,402);
setcolor(15);
rectangle(142,120,502,402);
setcolor(RED);
line(150,310,493,310);/*分隔-横线*/
/*提示区文字*/
hz(160,320,3,"温馨提示");
setcolor(3);
outtextxy(240,320,"!");
hz(160,350,3,"您可以用上下方向键移动高亮条来选");
hz(160,380,3,"择项目然后回车执行");
/*消息区*/
setfillstyle(1,WHITE);
bar(150,135,370,300);
}
/*绘制模拟按钮--------------------------------------------------------------------------------------
每个按钮间相隔30个象素
按钮大小:x1,y1
位置:x2,y2
边框色:Fcolor
背景色:Bcolor
------------------------------------------------------------------------------------------------*/
void DrawButt(long x1,long y1,long x2,long y2,long Fcolor,long Bcolor)
{
setfillstyle(1,Bcolor);
bar(x1,y1,x2,y2);
setcolor(Fcolor);
rectangle(x1+2,y1-2,x2-2,y2+2);
}
/*绘制按钮文字--------------------------------------*/
void DrawButtChar()
{
hz(387,154,0,"恢复系统");
setcolor(RED);
outtextxy(464,156,"[R]");
hz(387,184,0,"备份系统");
setcolor(28);
outtextxy(464,186,"[B]");
hz(387,214,0,"进入");
setcolor(BLACK);
outtextxy(423,216,"DOS");
hz(447,214,0,"下");
setcolor(GREEN);
outtextxy(464,216,"[E]");
hz(387,244,0,"重启");
setcolor(5);
outtextxy(448,248,"[ESC]");
hz(387,274,0,"关机");
setcolor(22);
outtextxy(464,276,"[S]");
}
/*移动焦点--------------------------------------------------------------------------------------------------
CS:方向标志:0:按上方向键;1:按下方向键
--------------------------------------------------------------------------------------------------------------*/
void MoveFocus(int CS)
{
void CheckAll();
/*重绘制按钮*/
/*绘制按钮*/
DrawButt(380,175,486,148,WHITE,7);/*恢复系统的按钮*/
DrawButt(380,205,486,178,WHITE,7);/*备份系统的按钮*/
DrawButt(380,235,486,208,WHITE,7);/*返回DOS*/
DrawButt(380,265,486,238,WHITE,7);/*重启*/
DrawButt(380,295,486,268,WHITE,7);/*关机*/
if(CS==1)
{
focX=focX+30;
focY=focY+30;
}
if(CS==0)
{
focX=focX-30;
focY=focY-30;
}
CuFocXY=focX+focY;/*保存当前获得焦点的按钮的X与Y坐标的和*/
/*绘制获得焦点的按钮*/
setcolor(13);
DrawButt(380,focX,486,focY,14,WHITE);/*绘制获得焦点的按钮*/
DrawButtChar(); /*重显示按钮文字*/
CheckAll();/*调用状态检测并显示相关消息*/
}
/*清除图形并退出图形系统*/
void CCGra()
{
cleardevice();
closegraph();
}
/*检测文件与显示相关帮助信息工作*/
void CheckAll()
{
int handle;
struct stat buffer;
/*重绘消息区*/
setfillstyle(1,WHITE);
bar(150,135,370,300);
switch(CuFocXY)
{
case 323:/*当前焦点处于恢复系统按钮上*/
if ((handle = open("sysbak\\xp.gho", O_RDONLY)) == -1)
{
setcolor(RED);
outtextxy(152,140,"Error Code:1 No found XP.GHO");
}
else
{
if (fstat(handle, &buffer))
outtextxy(152,140,"Error!Don't get file information.");
else
if((buffer.st_size/1024)>3000)
{
setcolor(GREEN);
outtextxy(152,140,"Find system backup file...OK");
}
else
{
setcolor(RED);
outtextxy(152,140,"Error Code:2");
outtextxy(152,150,"Find system backup file,");
outtextxy(152,160,"But the file maybe bad.");
}
close(handle);
}
break;
case 383:/*当前焦点处于备份系统按钮上*/
if((handle = open("sysbak\\xp.gho", O_RDONLY)) == -1)
{
setcolor(RED);
outtextxy(152,140,"system is not backup...");
}
else
{
if (fstat(handle, &buffer))
{
setcolor(RED);
outtextxy(152,140,"Error!Don't get file information.");
}
else
if((buffer.st_size/1024)>3000)
{
setcolor(GREEN);
outtextxy(152,140,"Find system backup file...");
}
else
{
setcolor(RED);
outtextxy(152,140,"Error Code:2");
outtextxy(152,150,"Find system backup file,");
outtextxy(152,160,"But the file maybe bad.");
}
close(handle);
}
break;
case 443:/*当前焦点处于返回DOS按钮上*/
setcolor(0);
outtextxy(152,140,"Return DOS command.");
break;
case 503:/*当前焦点处于重启按钮上*/
setcolor(0);
outtextxy(152,140,"Rester your Computer.");
break;
case 563:/*当前焦点处于关机按钮上*/
setcolor(0);
outtextxy(152,140,"Power off your Computer.");
break;
}
}
/*-----------------------------------------------------------------------------------------主函数----------------------------------------------------------------------------------*/
int main()
{
int key_code;
int exit_sign;
/*初始化操作开始----------------------------------------------------------------------------------------------*/
/*初始化当前坐标值*/
focX=145;/*175,如要为166则第一次按下方向键的话焦点会处于第二个按钮上,所以要减30*/
focY=118;/*148,同上理*/
CKeyCode=0;/*初始化当前键盘码*/
KeyPushCount=0;/*初始化键盘按下的次数值*/
CuFocXY=0;/*当前光标X与Y坐座和,用于判断当前焦点处于哪个按钮上*/
exit_sign=1;/*进入等待用户输入退出循环标志值*/
/*初始化操作结束----------------------------------------------------------------------------------------------*/
InitGra();/*初始化显卡*/
DrawWin();/*绘主窗口*/
/*绘制按钮*/
DrawButt(380,175,486,148,WHITE,7);/*恢复系统的按钮*/
DrawButt(380,205,486,178,WHITE,7);/*备份系统的按钮*/
DrawButt(380,235,486,208,WHITE,7);/*返回DOS*/
DrawButt(380,265,486,238,WHITE,7);/*重启*/
DrawButt(380,295,486,268,WHITE,7);/*关机*/
DrawButtChar();/*显示按钮文字*/
/*等待键盘输入*/
while(exit_sign)
{
key_code=GET_KEY();
switch(key_code)
{
case 27: /*按下ESC则重启电脑*/
CCGra();
exit_sign=0;
Reboot();
break;
case 83: /*按下S则关机*/
CCGra();
exit_sign=0;
off();
break;
case 115: /*按下s则关机*/
CCGra();
exit_sign=0;
off();
break;
case 82: /*按下R则开始恢复系统*/
CCGra();
system("R.bat");
exit_sign=0;
break;
case 114: /*按下r则开始恢复系统*/
CCGra();
system("R.bat");
exit_sign=0;
break;
case 66: /*按下B则开始备份系统*/
CCGra();
system("B.bat");
exit_sign=0;
break;
case 98: /*按下b则开始备份系统*/
CCGra();
system("B.bat");
exit_sign=0;
break;
case 69: /*按下E则返回到DOS*/
CCGra();
exit_sign=0;
break;
case 101:/*按下e则返回到DOS*/
CCGra();
exit_sign=0;
break;
case 72:/*按下向上方向键*/
if (KeyPushCount>1)/*控制焦点只能在6个按钮上移动*/
{
MoveFocus(0);
KeyPushCount=KeyPushCount-1;
}
break;
case 80:/*按下向下方向键*/
if (KeyPushCount<5)/*控制焦点只能在6个按钮上移动*/
{
MoveFocus(1);
KeyPushCount=KeyPushCount+1;
}
break;
case 13:/*按下回车键*/
switch(CuFocXY)
{
case 323:/*当前焦点处于恢复系统按钮上*/
printf("Rescue system\n");
CCGra();
system("R.bat");
exit_sign=0;
break;
case 383:/*当前焦点处于备份系统按钮上*/
printf("Backup system\n");
CCGra();
system("B.bat");
exit_sign=0;
break;
case 443:/*当前焦点处于返回DOS按钮上*/
printf("Return DOS\n");
CCGra();
exit_sign=0;
break;
case 503:/*当前焦点处于重启按钮上*/
printf("Rester computer\n");
CCGra();
Reboot();
exit_sign=0;
break;
case 563:/*当前焦点处于关机按钮上*/
printf("Power off\n");
CCGra();
off();
exit_sign=0;
break;
}
break;
default:/*什么也不做*/
break;
}
}
return(0);
} |
|