標題:
通信錄程序設計(圖形界面)
[打印本頁]
作者:
benbens
時間:
2015-7-15 02:22
標題:
通信錄程序設計(圖形界面)
本帖最后由 benbens 于 2015-7-15 02:23 編輯
#include <stdio.h>
#include <graphics.h>
#include <conio.h>
int BackColor ;
int Color ;
struct _Linkman
{
char name [20]; //姓名
char age [5]; //年齡
char sex [5]; //性別
char phone[12]; //電話
char QQ [13]; //QQ
};
struct _Mu
{
int _1;
int _2;
int _3;
}Menu;
void (*Key_up_down)(int num) ;
void (*Key_exit)(void) ;
struct _Linkman Pernum[100]; //人數(shù)限額
int pernum=0; //當前實際人數(shù)
int PerNo=0; //當前第幾個人
int TermNo=0; //第幾個服務選項
FILE *fp; //文件指針
void DisAllLineMan(void);
/***********************************************************************
文件初始化
***********************************************************************/
void FileInit(void)
{
int i=0;
if ((fp=fopen("LinkemanDate.dat","rd"))==NULL)
{
printf("文件路徑錯誤!\n");
pernum=0;
exit(0);
}
else
{
while (!feof(fp))
{
if (fread(&Pernum[i],sizeof(struct _Linkman),1,fp)==1)
{
i++;
}
}
pernum=i;
}
fclose(fp);
}
/***********************************************************************
文件保存
***********************************************************************/
void SaveFile(void)
{
int i=0;
int Cn=0;
if ((fp=fopen("LinkemanDate.dat","wb"))==NULL)
{
printf("文件路徑錯誤!\n");
exit(0);
}
while (i<pernum)
{
fwrite(&Pernum[i],sizeof(struct _Linkman),1,fp);
i++;
}
fclose(fp);
}
/***********************************************************************
防止按鍵誤操作
***********************************************************************/
void Null(int num)
{
int Num=0;
Num+=num;
while(!Key_exit);
Num=0;
}
/***********************************************************************
主 界 面
***********************************************************************/
void Menu_Init(void)
{
Menu._1=0;Menu._2=0;Menu._3=0;PerNo=0;TermNo=0;
setbkcolor(BackColor);
setcolor(Color);
setfillstyle(BackColor);
bar3d(10 , 10 , 310 , 310 , 3 , 1);
setcolor(WHITE);
loadimage(NULL, "16.jpg"); //插入圖片
setbkcolor(BLACK);
outtextxy(15 , 12+16*0 , "=============通信錄設計=============");
outtextxy(15 , 12+16*1 , "************************************************");
outtextxy(90 , 12+16*5 , "◆制作人:劉鴻波");
outtextxy(80 , 12+16*8 , "◆制作時間:2012-5-9");
setcolor(YELLOW);
outtextxy(50 , 15+16*25 ,"←確認");
outtextxy(220, 15+16*25 ,"退出→");
outtextxy(150, 15+16*22 ,"↑");
outtextxy(140, 15+16*23 ,"上翻");
outtextxy(140, 15+16*27 ,"下翻");
outtextxy(150, 15+16*28 ,"↓");
outtextxy(150, 15+16*25,"★");
setcolor(CYAN);
ellipse(50,15+16*22,268,480); //繪制橢圓
ellipse(98,18+16*24,218,13+16*27);
setcolor(Color);
Key_up_down=Null;
}
/***********************************************************************
個人信息顯示、修改個人信息
***********************************************************************/
void PersonalMessage(int num)
{
loadimage(NULL, "15.jpg");
setbkcolor(LIGHTGRAY);
setcolor(YELLOW);
setfillstyle(LIGHTGRAY);
bar3d(310-16*4,430,310,470,1,1);
bar3d(10,430,310,470,1,1);
setcolor(BLACK);
line(160,430,160,470);
setcolor(Color);
setbkcolor(LIGHTGRAY);
outtextxy(22 , 442 ,"修 改");
outtextxy(258 ,442 ,"確 定");
setcolor(YELLOW);
setbkcolor(BLACK);
outtextxy(35 , 12+16*0 ,"============個 人 信 息============");
outtextxy(15 , 12+16*2 ,"姓名:");
outtextxy(15+16*4 , 12+16*2,Pernum[num].name);
outtextxy(15 , 12+16*4 ,"年齡:");
outtextxy(15+16*4 , 12+16*4,Pernum[num].age);
outtextxy(15 , 12+16*6 ,"性別:");
outtextxy(15+16*4 , 12+16*6,Pernum[num].sex);
outtextxy(15 , 12+16*8 ,"電話:");
outtextxy(15+16*4 , 12+16*8,Pernum[num].phone);
outtextxy(15 , 12+16*10 ," Q Q:");
outtextxy(15+16*4 , 12+16*10,Pernum[num].QQ);
}
/***********************************************************************
選擇修改項(↑↓選擇)
***********************************************************************/
void ChooseTerm(int num) //選擇修改項
{
TermNo+=num;
if (TermNo==6)
{
TermNo=1;
}
if (TermNo<1)
{
TermNo=5;
}
PersonalMessage(PerNo);
setbkcolor(BROWN);
setcolor(Color);
setfillstyle(BROWN);
bar3d(15+16*3,12+16*(2*TermNo),310,12+16*(2*TermNo+1),1,1);
setcolor(WHITE);
setbkcolor(BROWN);
switch(TermNo)
{
case 1:outtextxy(15+16*4 , 12+16*2,Pernum[PerNo].name);
break;
case 2:outtextxy(15+16*4 , 12+16*4,Pernum[PerNo].age);
break;
case 3:outtextxy(15+16*4 , 12+16*6,Pernum[PerNo].sex);
break;
case 4:outtextxy(15+16*4 , 12+16*8,Pernum[PerNo].phone);
break;
case 5:outtextxy(15+16*4 , 12+16*10,Pernum[PerNo].QQ);
break;
default: break;
}
}
void OpenLineman(int num) //選擇聯(lián)系人
{
Menu._3=1;
PersonalMessage(num);
Key_up_down=ChooseTerm;
Key_exit=DisAllLineMan;
}
void Modification(void) //輸入選擇修改內容
{
switch(TermNo)
{
case 1:
{
InputBox(Pernum[PerNo].name,20,"請輸入姓名:");
outtextxy(15+16*4 , 12+16*2,Pernum[PerNo].name);
}break;
case 2:
{
InputBox(Pernum[PerNo].age,5,"請輸入年齡:");
outtextxy(15+16*4 , 12+16*4,Pernum[PerNo].age);
}break;
case 3:
{
InputBox(Pernum[PerNo].sex,4,"請輸入性別:");
outtextxy(15+16*4 , 12+16*6,Pernum[PerNo].sex);
}break;
case 4:
{
InputBox(Pernum[PerNo].phone,12,"請輸入電話:");
outtextxy(15+16*4 , 12+16*8,Pernum[PerNo].phone);
}break;
case 5:
{
InputBox(Pernum[PerNo].QQ,12,"請輸入QQ:");
outtextxy(15+16*4 , 12+16*10,Pernum[PerNo].QQ);
}break;
default:break;
}
SaveFile();
}
void OpenLinemanOption(void)
{
switch(Menu._3)
{
case 0:OpenLineman(PerNo);
break;
case 1:Modification();
break;
default: break;
}
}
/***********************************************************************
添加聯(lián)系人
***********************************************************************/
void ChooseYesOrNoInit(void) //姓名重合選擇窗口
{
setbkcolor(CYAN);
setcolor(Color);
setfillstyle(CYAN);
bar3d(0,12+16*14,320,480,1,1);
setcolor(WHITE);
outtextxy(50, 12+16*17,"該聯(lián)系人已存在,是否覆蓋?");
setbkcolor(LIGHTGRAY);
setcolor(LIGHTGRAY);
setfillstyle(LIGHTGRAY);
bar3d(10,430,10+16*4,470,3,1);
bar3d(310-16*4,430,310,470,3,1);
setcolor(WHITE);
outtextxy(35 , 442 ,"是");
outtextxy(270 ,442 ,"否");
}
void InputLinkemanMes(int num) //輸入新增聯(lián)系人信息
{
loadimage(NULL, "15.jpg");
setbkcolor(CYAN);
setcolor(Color);
setfillstyle(CYAN);
bar3d(310-16*4,430,310,470,3,1);
outtextxy(258 ,442 ,"退 出");
setcolor(CYAN);
setbkcolor(BLACK);
outtextxy(10 , 12+16*0 ,"=============添加聯(lián)系人=============");
outtextxy(15 , 12+16*2 ,"姓名:");
InputBox(Pernum[num].name,20,"請輸入姓名:");
outtextxy(15+16*4 , 12+16*2,Pernum[num].name);
outtextxy(15 , 12+16*4 ,"年齡:");
InputBox(Pernum[num].age,5,"請輸入年齡:");
outtextxy(15+16*4 , 12+16*4,Pernum[num].age);
outtextxy(15 , 12+16*6 ,"性別:");
InputBox(Pernum[num].sex,4,"請輸入性別:");
outtextxy(15+16*4 , 12+16*6,Pernum[num].sex);
outtextxy(15 , 12+16*8 ,"電話:");
InputBox(Pernum[num].phone,12,"請輸入電話:");
outtextxy(15+16*4 , 12+16*8,Pernum[num].phone);
outtextxy(15 , 12+16*10 ," Q Q:");
InputBox(Pernum[num].QQ,12,"請輸入QQ:");
outtextxy(15+16*4 , 12+16*10,Pernum[num].QQ);
}
void DisChoose(int num) //顯示選擇
{
loadimage(NULL, "15.jpg");
setbkcolor(CYAN);
setcolor(Color);
setfillstyle(CYAN);
bar3d(310-16*4,430,310,470,3,1);
outtextxy(258 ,442 ,"退 出");
setcolor(CYAN);
setbkcolor(BLACK);
outtextxy(10 , 12+16*0 ,"=============添加聯(lián)系人=============");
outtextxy(15 , 12+16*2 ,"姓名:");
outtextxy(15+16*4 , 12+16*2,Pernum[num].name);
outtextxy(15 , 12+16*4 ,"年齡:");
outtextxy(15+16*4 , 12+16*4,Pernum[num].age);
outtextxy(15 , 12+16*6 ,"性別:");
outtextxy(15+16*4 , 12+16*6,Pernum[num].sex);
outtextxy(15 , 12+16*8 ,"電話:");
outtextxy(15+16*4 , 12+16*8,Pernum[num].phone);
outtextxy(15 , 12+16*10 ," Q Q:");
outtextxy(15+16*4 , 12+16*10,Pernum[num].QQ);
}
void ChooseYes(int num1,int num2 )
{
strcpy(Pernum[num1].name, Pernum[num2].name);
strcpy(Pernum[num1].age, Pernum[num2].age);
strcpy(Pernum[num1].sex, Pernum[num2].sex);
strcpy(Pernum[num1].phone,Pernum[num2].phone);
strcpy(Pernum[num1].QQ, Pernum[num2].QQ);
DisChoose(num2);
outtextxy(15, 12+16*13,"添加成功!");
}
void AddLinkeman(void)
{
int ch=0;int i=0;
int flag=0;
Menu._3=2;
InputLinkemanMes(pernum);
for (i=0;i<pernum;i++)
{
if (!strcmp(Pernum[i].name,Pernum[pernum].name))
{
flag++;
ChooseYesOrNoInit();
ch=getch();
if (ch==224)
{
ch=getch();
{
switch(ch)
{
case 75:ChooseYes(i,pernum);
break;
case 77:{
DisChoose(pernum);
pernum++;
outtextxy(15, 12+16*13,"添加成功!");
}
break;
default: break;
}
}
}
}
}
if (!flag)
{
outtextxy(15, 12+16*13,"添加成功!");
pernum++;
}
SaveFile();
Key_up_down=Null;
Key_exit=DisAllLineMan;
}
/***********************************************************************
刪除當前聯(lián)系人
***********************************************************************/
void DeleteLinkeman(int num)
{
Menu._3=3;
loadimage(NULL, "14.jpg");
setbkcolor(BROWN);
setcolor(Color);
setfillstyle(BROWN);
bar3d(10 , 390 , 310 , 430 , 3 , 1);
setcolor(YELLOW);
outtextxy(15,402,"是否刪除");
outtextxy(15+16*4 ,402,Pernum[num].name);
setbkcolor(YELLOW);
setcolor(BROWN);
line(160,430,160,470);
outtextxy(22 , 442 ,"確 定");
outtextxy(258 ,442 ,"退 出");
Key_exit=DisAllLineMan;
}
void Delete(void)
{
int j;
setbkcolor(YELLOW);
setcolor(Color);
setfillstyle(YELLOW);
bar3d(10 , 10 , 310 , 470 , 3 , 1);
loadimage(NULL, "14.jpg");
setbkcolor(BROWN);
setcolor(Color);
setfillstyle(BROWN);
bar3d(10 , 390 , 310 , 430 , 3 , 1);
bar3d(310-16*4,430,310,470,1,1);
for (j=PerNo;j<pernum;j++)
{
strcpy(Pernum[j].name, Pernum[j+1].name);
strcpy(Pernum[j].age, Pernum[j+1].age);
strcpy(Pernum[j].sex, Pernum[j+1].sex);
strcpy(Pernum[j].phone,Pernum[j+1].phone);
strcpy(Pernum[j].QQ, Pernum[j+1].QQ);
}
pernum--;
SaveFile();
setbkcolor(BROWN);
setcolor(YELLOW);
outtextxy(128,402,"刪除成功");
outtextxy(258 ,442 ,"退 出");
Key_up_down=Null;
Key_exit=DisAllLineMan;
}
void DeleteOption(void)
{
switch(Menu._3)
{
case 0:DeleteLinkeman(PerNo);
break;
case 3:Delete();
break;
}
}
/***********************************************************************
選擇初始界面的聯(lián)系人(↑↓鍵選擇)
***********************************************************************/
void ChooseLineMan(int num)
{
int i=0,j=0;
int CurrentPer=0;
PerNo+=num;
if (PerNo>pernum)
{
PerNo=pernum;
}
if (PerNo<0)
{
PerNo=0;
}
loadimage(NULL, "15.jpg");
setbkcolor(LIGHTGRAY);
setcolor(LIGHTGRAY);
setfillstyle(LIGHTGRAY);
bar3d(10,430,10+16*4,470,3,1);
bar3d(310-16*4,430,310,470,3,1);
setcolor(YELLOW);
setbkcolor(RED);
outtextxy(22 , 442 ,"選 項");
setbkcolor(GREEN);
outtextxy(258 ,442 ,"退 出");
setcolor(YELLOW);
setbkcolor(BLACK);
outtextxy(15+16*5 , 12+16*1 ,"AddressBook");
outtextxy(15+16*2 , 12+16*2 ,"姓名");
outtextxy(15+16*11 , 12+16*2 ,"電話");
if (PerNo>9)
CurrentPer=PerNo-9;
else
CurrentPer=0;
for (i=0,j=CurrentPer;j<pernum && i<10;j++,i++)
{
outtextxy(15+16*1 , 12+16*(4+i),Pernum[j].name);
outtextxy(15+16*9 , 12+16*(4+i),Pernum[j].phone);
}
setbkcolor(BROWN);
setcolor(Color);
setfillstyle(BROWN);
if (PerNo<10)
{
bar3d(10,12+16*(4+PerNo),310,12+16*(5+PerNo),1,1);
setcolor(LIGHTGRAY);
outtextxy(15+16*1 , 12+16*(4+PerNo),Pernum[PerNo].name);
outtextxy(15+16*9 , 12+16*(4+PerNo),Pernum[PerNo].phone);
}
else
{
bar3d(10,12+16*(4+9),310,12+16*(5+9),1,1);
setcolor(LIGHTGRAY);
outtextxy(15+16*1 , 12+16*(4+9),Pernum[PerNo].name);
outtextxy(15+16*9 , 12+16*(4+9),Pernum[PerNo].phone);
}
}
/***********************************************************************
初始界面(顯示全部聯(lián)系人)
***********************************************************************/
void DisAllLineMan(void)
{
int i,j;
Menu._1=1;Menu._2=0;Menu._3=0;TermNo=0;
loadimage(NULL, "15.jpg");
setbkcolor(LIGHTGRAY);
setcolor(LIGHTGRAY);
setfillstyle(LIGHTGRAY);
bar3d(10,430,10+16*4,470,3,1);
bar3d(310-16*4,430,310,470,3,1);
setcolor(YELLOW);
setbkcolor(RED);
outtextxy(22 , 442 ,"選 項");
setbkcolor(GREEN);
outtextxy(258 ,442 ,"退 出");
setcolor(YELLOW);
setbkcolor(BLACK);
setcolor(YELLOW);
setbkcolor(BLACK);
outtextxy(15+16*5 , 12+16*1 ,"AddressBook");
outtextxy(15+16*2 , 12+16*2 ,"姓名");
outtextxy(15+16*11 , 12+16*2 ,"電話");
for (i=0,j=0;j<pernum && i<10;j++,i++)
{
outtextxy(15+16*1 , 12+16*(4+i),Pernum[j].name);
outtextxy(15+16*9 , 12+16*(4+i),Pernum[j].phone);
}
setbkcolor(BROWN);
setcolor(Color);
setfillstyle(BROWN);
if (PerNo>10)
{
bar3d(10,12+16*(4+9),310,12+16*(5+9),1,1);
setcolor(LIGHTGRAY);
outtextxy(15+16*1 , 12+16*(4+9),Pernum[PerNo].name);
outtextxy(15+16*9 , 12+16*(4+9),Pernum[PerNo].phone);
}
else
{
bar3d(10,12+16*(4+PerNo),310,12+16*(5+PerNo),1,1);
setcolor(LIGHTGRAY);
outtextxy(15+16*1 , 12+16*(4+PerNo),Pernum[PerNo].name);
outtextxy(15+16*9 , 12+16*(4+PerNo),Pernum[PerNo].phone);
}
Key_up_down=ChooseLineMan;
Key_exit=Menu_Init;
}
/***********************************************************************
條件查找(可混音輸入)
***********************************************************************/
void TermRefer(void)
{
char Temp[20]={' '};
int temp=0;
int i,j,n=0,k;
int InputCharLen=0;
int LineNo=0;
setbkcolor(YELLOW);
setcolor(Color);
setfillstyle(YELLOW);
bar3d(10 , 10 , 310 , 470 , 3 , 1);
loadimage(NULL, "15.jpg");
setbkcolor(BROWN);
setcolor(YELLOW);
setfillstyle(BROWN);
bar3d(10 , 10 , 310 , 50 , 1 , 1);
bar3d(310-16*4,430,310,470,1,1);
outtextxy(15,30,"請輸入您需要查找的姓名:");
outtextxy(258 ,442 ,"退 出");
InputBox(Temp,20,"請輸入姓名:");
outtextxy(15+16*12,30,Temp);
setcolor(YELLOW);
setbkcolor(BLACK);
while (Temp[n]!='\0')
{
InputCharLen++;
n++;
}
for (i=0; i<pernum; i++)
{
temp=0;
for (k=0;k<InputCharLen;k++)
{
for (j=0;j<20;j++)
{
if(Pernum[i].name[j]==Temp[k])
{
temp++;
}
}
}
if (temp==InputCharLen)
{
outtextxy(15+16*1 , 12+16*(6+LineNo),Pernum[i].name);
outtextxy(15+16*9 , 12+16*(6+LineNo),Pernum[i].phone);
LineNo++;
}
}
if (LineNo==0)
{
outtextxy(15+16*3,12+16*7,"沒找到符合您要求的人");
}
setbkcolor(BLACK);
outtextxy(15+16*0 , 12+16*3,"查找結果如下:");
setcolor(GREEN);
outtextxy(15+16*1 , 12+16*5,"姓名");
outtextxy(15+16*9 , 12+16*5,"電話號碼");
Key_up_down=Null;
Key_exit=DisAllLineMan;
}
/***********************************************************************
選擇服務項
***********************************************************************/
void ChooseOption(int num)
{
Menu._2+=num;
if (Menu._2==5)
{
Menu._2=1;
}
if (Menu._2<1)
{
Menu._2=4;
}
setbkcolor(YELLOW);
setcolor(Color);
setfillstyle(YELLOW);
bar3d(10 , 240 , 160 , 470 , 3 , 1);
setcolor(BLACK);
outtextxy(15,240+16*1,"◆打開");
outtextxy(15,240+16*2,"◆添加聯(lián)系人");
outtextxy(15,240+16*3,"◆刪除聯(lián)系人");
outtextxy(15,240+16*4,"◆查找聯(lián)系人");
setbkcolor(BROWN);
setcolor(Color);
setfillstyle(BROWN);
bar3d(10,240+16*(Menu._2),160,240+16*(Menu._2+1),1,1);
setcolor(LIGHTGRAY);
switch(Menu._2)
{
case 1:outtextxy(15,240+16*1,"◆打開");
break;
case 2:outtextxy(15,240+16*2,"◆添加聯(lián)系人");
break;
case 3:outtextxy(15,240+16*3,"◆刪除聯(lián)系人");
break;
case 4:outtextxy(15,240+16*4,"◆查找聯(lián)系人");
break;
default:break;
}
}
void ServeOption(void) //服務項初始化
{
Menu._2=1;Menu._3=0;
setbkcolor(YELLOW);
setcolor(Color);
setfillstyle(YELLOW);
bar3d(10 , 240 , 160 , 470 , 3 , 1);
setcolor(BLACK);
outtextxy(15,240+16*1,"◆打開");
outtextxy(15,240+16*2,"◆添加聯(lián)系人");
outtextxy(15,240+16*3,"◆刪除聯(lián)系人");
outtextxy(15,240+16*4,"◆查找聯(lián)系人");
setbkcolor(BROWN);
setcolor(Color);
setfillstyle(BROWN);
bar3d(10,(240+16),160,240+16*2,1,1);
setcolor(LIGHTGRAY);
outtextxy(15,240+16*1,"◆打開");
Key_up_down=ChooseOption;
Key_exit=DisAllLineMan;
}
void ChooseServe(void) //選擇服務項操作
{
switch(Menu._2)
{
case 0:ServeOption();
break;
case 1:OpenLinemanOption();
break;
case 2:AddLinkeman();
break;
case 3:DeleteOption();
break;
case 4:TermRefer();
break;
default:break;
}
}
/***********************************************************************
按鍵掃描
***********************************************************************/
int GetKeyValue(void)
{
static int value=0;
int ch=0;
ch=getch();
if (ch==224)
{
ch=getch();
switch(ch)
{
case 72: return 1;break;
case 80: return 2;break;
case 75: return 3;break;
case 77: return 4;break;
default :break;
}
}
return 10;
}
/***********************************************************************
按鍵處理函數(shù)
***********************************************************************/
void Sure(void) //確認
{
if(Menu._1>0)
{
ChooseServe();
}else
DisAllLineMan();
}
void Up_key(void) //上翻
{
(*Key_up_down)(-1);
}
void Down_key(void) //下翻
{
(*Key_up_down)(+1);
}
void Exit_key(void) //退出
{
(*Key_exit)();
}
void Key_with(int name) //按鍵選擇
{
switch(name)
{
case 1:Up_key();break;
case 2:Down_key();break;
case 3:Sure();break;
case 4:Exit_key();break;
default :break;
}
}
/***********************************************************************
main函數(shù)
***********************************************************************/
void main(void)
{
int MenuCnt = 0 ;
BackColor = WHITE ;
Color = RED ;
initgraph(320 , 480);
Menu_Init();
FileInit();
SaveFile();
while (1)
{
MenuCnt=GetKeyValue();
if (MenuCnt<5)
{
Key_with(MenuCnt);
}
}
closegraph();
}
復制代碼
作者:
qlasam
時間:
2024-4-17 10:30
厲害,這是對那款單片機或者什么IDE開發(fā)出來的呢?
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1