📄 3_22.c
字号:
/*--------例程3-22--------*/
#include<dos.h>
#include<graphics.h>
void printtext(unsigned char *temp[],int i); /*用于在屏幕上显示字符串*/
main()
{
int i,graphdriver,graphmode;
unsigned char *temp[4];
int freq[96]={784,660,588,660,523,523,
588,494,440,523,392,392,
330,392,440,523,784,440,523,392,
784,1048,880,784,660,784,588,588,
588,660,494,440,392,440,523,588,
330,523,440,392,440,523,392,392,
660,784,494,588,440,523,392,392,
330,392,330,392,392,440,494,588,440,440,392,440,
523,588,784,660,588,660,588,523,440,392,
330,523,440,523,440,392,330,392,440,523,
392,392,660,784,588,660,588,523,494,440,784,784};
int dely[96]={25,50,12,12,50,50,
25,50,12,12,50,50,
50,38,12,38,12,12,12,25,
38,12,12,12,12,12,50,50,
38,12,25,25,38,12,25,25,
25,25,12,12,12,12,50,50,
38,12,25,25,12,12,50,25,
12,12,12,12,12,12,12,12,50,25,12,12,
38,12,25,25,25,12,12,25,12,12,
50,50,12,12,12,12,12,12,12,12,
50,25,12,12,12,12,12,12,25,25,50,50};
graphdriver=DETECT;
graphmode=0;
temp[0]="Welcome !";
temp[1]="Please press any key to start ......";
temp[2]="Enjoy yourself !";
temp[3]="Press any key to end !";
temp[4]="Thank you! Bye Bye ......";
initgraph(&graphdriver,&graphmode,""); /*系统初始化*/
cleardevice(); /*清除屏幕*/
settextjustify(LEFT_TEXT,CENTER_TEXT); /*设置字符排列方式*/
for(i=0;i<2;i++)
printtext(temp,i);
getch();
for(i=2;i<4;i++)
printtext(temp,i);
i=0;
while(i<96&&!kbhit())
{
sound(freq[i]); /*扬声器根据频率发声*/
delay(1100*dely[i]); /* 声音延时*/
i++;
}
nosound(); /* 关闭扬声器*/
printtext(temp,4);
getch();
closegraph(); /* 关闭图形模式 */
}
void printtext(unsigned char *temp[],int i)
{
setcolor(4); /* 设置颜色*/
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3); /* 设置字符的字体,方向和大小*/
outtextxy(100,40+i*50,temp[i]); /* 在所指定的坐标出显示字符串*/
}
/*--------例程3-22结束--------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -