可以添加,删除,查找,修改。
代码如下:
// PhoneBook.cpp : 此文件包含 “main” 函数。程序执行将在此处开始并结束。
//
#include <stdio.h>
#include “console.h”
#pragma comment(lib,“console.lib”)
#include <io.h>
int circulation = 1;
int interface_num = 0;
void MainInterface(); // 0
void Add(); // 1
void Delete(); // 2
void Find(); // 3
void Modify(); // 4
char phone_book[] = “dianhuabu.txt”;
struct Dhb
{
char name[10], telephone[20];
};
extern COORD mouse;
int main()
{
Screen screen;
screen.ShowOrHideCursor(0);
Event event;
event.AddMouseMode();
while (circulation)
{
screen.Clear_screen();
switch (interface_num)
{
case 0:
MainInterface();
break;
case 1:
Add();
break;
case 2:
Delete();
break;
case 3:
Find();
break;
case 4:
Modify();
break;
}
}
event.RestoreMode();
//screen.Pause();
screen.Close_handle();
return 0;
}
void MainInterface()
{
Screen screen;
screen.SetSize(70, 29);
screen.SetTitle(“电话簿”);
if (_access(phone_book, 0) == -1)
{
FILE* dhb;
fopen_s(&dhb, phone_book, "a");
fclose(dhb);
}
screen.text_color_num = 6;
screen.DisplayText(30, 2, "电话簿管理");
Listbox listbox = Listbox(24, 5, 20, 8);
listbox.Attribute(3, 13, 13, true, false, 0);
char item[][100] = { " 添加"," 删除"," 查找"," 修改" };
int item_num = 4;
listbox.AddArrayto_SinglePageListbox(item, item_num);
Form form;
form.Attribute(listbox.listbox_textcolor_num, listbox.listbox_textBgcolor_num);
form.DrawSeparatorBar_H(11, listbox.cx0 - 2, listbox.cx0 + listbox.wide + 1);
Button EXIT_button = Button(listbox.cx0, 12, " 退出程序 ");
EXIT_button.button_color_num = 3;
EXIT_button.button_Bgcolor_num = 13;
EXIT_button.Display_button();
Event event;
int index = 0;
while (1)
{
event.ReadEvent();
if (event.Mouse_Event())
{
if (EXIT_button.MousePosition_At_button()
&& event.Left_Button_Pressed())
{
circulation = 0;
return;
}
if (EXIT_button.MousePosition_At_button())
{
EXIT_button.PaintText_button(2, 13);
}
else
{
EXIT_button.PaintText_button(3, 13);
}
if (listbox.MousePosition_At_listbox())
{
listbox.index_textbox.PaintText_textbox(3, 13);
event.Get_mouse_position();
listbox.index_textbox.cy0 = mouse.Y;
listbox.index_textbox.PaintText_textbox(1, 6);
if (event.Left_Button_Pressed())
{
index = listbox.SinglePageItemIndex();
interface_num = index + 1;
return;
}
}
else listbox.index_textbox.PaintText_textbox(3, 13);
}
if (event.Key_Event()