📄 lwx.c
字号:
#include <windows.h>
#include <stdio.h>
#include "resource.h"
#define COL 6
#define ROW 16
#define MAX_LENTH 100
HINSTANCE hInst;
TCHAR szTitle[MAX_LENTH]="学生信息管理系统";
TCHAR szWindowClass[MAX_LENTH]="hello";
typedef struct Stu
{
char StuNum[10];
char StuName[10];
char StuAge[4];
char StuSex[4];
char StuPhone[20];
char StuOICQ[10];
}stu;
struct node
{
stu per;
struct node *next;
};
struct node *head=NULL,*p=NULL,*q=NULL,*New=NULL;
struct node *sNew=NULL,*sHead=NULL,*sp=NULL;
int lenth=0;//链表长度
int Change = 0;
int nRet = 0;//判断是否确定
int selectNum=0;//单选框判断时的状态
int sAbsCount=0;//当前查找链表记录数
int AbsPage=1;
int ReCount = 0;
int PageCount=0;
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE,int);
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
INT APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
MSG msg;
//对文件中的数据进行加载
FILE *fp;
fp=fopen("read.save","r");
if(fp!=NULL)
{
while(!feof(fp))
{
New=(struct node *)malloc(sizeof(struct node));
fscanf(fp,"%s%s%s%s%s%s\n",New->per.StuNum,New->per.StuName,New->per.StuAge,New->per.StuSex,New->per.StuPhone,New->per.StuOICQ);
New->next=NULL;
if(head==NULL)
{head=New;}
else
{
for(p=head;p->next!=0;)
{
p=p->next;
}
p->next=New;
}
lenth++;
}
}
fclose(fp);
MyRegisterClass(hInstance);
//初始化并创建窗口:
if(!InitInstance(hInstance,nCmdShow)) return FALSE;
//主消息循环
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);//转换消息
DispatchMessage(&msg);//发放消息
}
return msg.wParam ;
}
//注册窗口类
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize=sizeof(WNDCLASSEX);
wcex.style=CS_HREDRAW|CS_VREDRAW;
wcex.lpfnWndProc=(WNDPROC)WndProc;
wcex.cbClsExtra=0;
wcex.cbWndExtra=0;
wcex.hInstance=hInstance;
wcex.hIcon=NULL;
wcex.hCursor=LoadCursor(NULL,IDC_ARROW);
wcex.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName=(char*)IDR_MENU1;
wcex.lpszClassName=szWindowClass;
wcex.hIconSm=NULL;
return RegisterClassEx(&wcex);//调用API函数注册窗口类
}
//初始化应用程序示例并创建窗口
BOOL InitInstance(HINSTANCE hInstance,int nCmdShow)
{
HWND hWnd;
//保存应用程序示例到一个全局变量,防止以后需要使用
hInst=hInstance;
//创建窗口
hWnd=CreateWindow(szWindowClass,szTitle,WS_OVERLAPPEDWINDOW|WS_SIZEBOX,
CW_USEDEFAULT,0,CW_USEDEFAULT,0,NULL,NULL,hInstance,NULL);
if(!hWnd) return FALSE;
ShowWindow(hWnd,nCmdShow);//显示窗口
UpdateWindow(hWnd);//更新窗口
return TRUE;
}
LRESULT CALLBACK DialogBoxProcNEW(HWND hDlgWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
if(LOWORD(wParam)==IDOK)
{
EndDialog(hDlgWnd,IDOK);
}
break;
default:break;
}
return 0;
}
//增加新信息对话框回调函数
LRESULT CALLBACK DialogBoxProcADD(HWND hDlgWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
int key = 0;//判断输入学号是否重复
char stuNum[10];
struct node *mid;
HWND hEditWnd1,hEditWnd2,hEditWnd3,hEditWnd4,hEditWnd5,hEditWnd6;
switch(message)
{
case WM_INITDIALOG:
return 1;
case WM_COMMAND:
if(LOWORD(wParam)==IDOK) //学号应该是唯一的!
{
New=(struct node *)malloc(sizeof(struct node));//增加新结点
hEditWnd1=GetDlgItem(hDlgWnd,IDC_EDTNUM);//申请句柄保存文本框1的值
GetWindowText(hEditWnd1,stuNum,sizeof(New->per.StuNum));//获得学号
for(p=head;p!=0;)
{
if(!strcmp(p->per.StuNum,stuNum))//比较2个字符串
{
key = 1;//学号重复
MessageBox(NULL,"该学号已使用!","系统消息",MB_OK);
break;
}
p=p->next;
}
if(0 == key)
{
//先获取文本框句柄
hEditWnd2=GetDlgItem(hDlgWnd,IDC_EDTNAM);
hEditWnd3=GetDlgItem(hDlgWnd,IDC_EDTAGE);
hEditWnd4=GetDlgItem(hDlgWnd,IDC_EDTSEX);
hEditWnd5=GetDlgItem(hDlgWnd,IDC_EDTPHONE);
hEditWnd6=GetDlgItem(hDlgWnd,IDC_EDTOICQ);
//获取文本框中信息
GetWindowText(hEditWnd1,New->per.StuNum,sizeof(New->per.StuNum));//学号
GetWindowText(hEditWnd2,New->per.StuName,sizeof(New->per.StuName));//姓名
GetWindowText(hEditWnd3,New->per.StuAge,sizeof(New->per.StuAge));
GetWindowText(hEditWnd4,New->per.StuSex,sizeof(New->per.StuSex));
GetWindowText(hEditWnd5,New->per.StuPhone,sizeof(New->per.StuPhone));
GetWindowText(hEditWnd6,New->per.StuOICQ,sizeof(New->per.StuOICQ));
New->next=0;
if(lenth==0) //判断结点个数
{
head=New;
p=New;
lenth++;
}
else
{//先寻找插入位置
for(p=head;p->next!=NULL && lstrcmp(New->per.StuNum,p->per.StuNum) == 1;)
{
mid=p;
p=p->next;
}
if(lstrcmp(New->per.StuNum,p->per.StuNum)==-1)
{
if(head==p)//链表非空插入到第一个结点
{
New->next = head;
head = New;
}
else//链表非空时插入到中间
{
mid->next=New;
New->next=p;
}
}
else//链表不为空插入到最后
{
p->next=New;
New->next=NULL;
}
lenth++;
}
Change=1;
}
nRet=1;
EndDialog(hDlgWnd,IDOK);
}
if(LOWORD(wParam)==IDCANCEL) EndDialog(hDlgWnd,IDCANCEL);
break;
default:break;
}
return 0;
}
//删除信息对话框回调函数
LRESULT CALLBACK DialogBoxProcDEL(HWND hDlgWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
HWND hEditWnd1;
char stuNum[20];
switch(message)
{
case WM_INITDIALOG:
return 1;
case WM_COMMAND:
if(LOWORD(wParam)==IDOK)
{
hEditWnd1=GetDlgItem(hDlgWnd,IDC_EDIT1);
GetWindowText(hEditWnd1,stuNum,sizeof(New->per.StuNum));//获得要删除学生的学号
p=head;
while(p!=0)
{
if(!strcmp(p->per.StuNum,stuNum))//如果两字符串相同时
{
lenth--;
if(p==head)
{
head=p->next;
free(p);
}
else
{
q->next=p->next;
free(p);
}
break;
}
else
{
q=p;
p=p->next;
}
}
nRet=1;
Change=1;
EndDialog(hDlgWnd,IDOK);
}
if(LOWORD(wParam)==IDCANCEL) EndDialog(hDlgWnd,IDCANCEL);
break;
default:break;
}
return 0;
}
//更改信息对话框回调函数
LRESULT CALLBACK DialogBoxProcMODIFY(HWND hDlgWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
char stuNum[10];//获取文本框中的学生学号
HWND hEditWnd1=NULL,hEditWnd2=NULL,hEditWnd3=NULL,hEditWnd4=NULL,hEditWnd5=NULL;
//先获取文本框句柄
hEditWnd1=GetDlgItem(hDlgWnd,IDC_EDIT1);
hEditWnd2=GetDlgItem(hDlgWnd,IDC_EDIT2);
hEditWnd3=GetDlgItem(hDlgWnd,IDC_EDIT3);
hEditWnd4=GetDlgItem(hDlgWnd,IDC_EDIT4);
hEditWnd5=GetDlgItem(hDlgWnd,IDC_EDIT5);
switch(message)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
if(LOWORD(wParam)==IDOK)
{
GetWindowText(hEditWnd1,stuNum,sizeof(p->per.StuNum));
for(p=head;p!=NULL;p=p->next)
{
if(lstrcmp(p->per.StuNum,stuNum)==0)
{
//获取文本框中信息
GetWindowText(hEditWnd2,p->per.StuName,sizeof(p->per.StuName));//姓名
GetWindowText(hEditWnd3,p->per.StuAge,sizeof(p->per.StuAge));//年龄
GetWindowText(hEditWnd4,p->per.StuPhone,sizeof(p->per.StuPhone));//电话
GetWindowText(hEditWnd5,p->per.StuOICQ,sizeof(p->per.StuOICQ));//OICQ
nRet=1;
EndDialog(hDlgWnd,IDOK);
Change=1;
break;
}
}
if(p == NULL)MessageBox(NULL,"此学生不存在!","系统消息",MB_OK);
}
if(LOWORD(wParam)==IDCANCEL) EndDialog(hDlgWnd,IDCANCEL);
break;
default:break;
}
return 0;
}
//查询对话框回调函数
LRESULT CALLBACK DialogBoxProcFIND(HWND hDlgWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
HWND hEditWnd1,hEditWnd2,hEditWnd3,hEditWnd4,hEditWnd5,hEditWnd6,hEditWnd7,hEditWnd8;
char stuNum[20],stuNam[20];
char C[20];
int i=0,sum=0,j=0;
//先获取文本框句柄
hEditWnd1=GetDlgItem(hDlgWnd,IDC_EDIT1);
hEditWnd2=GetDlgItem(hDlgWnd,IDC_EDIT2);
hEditWnd3=GetDlgItem(hDlgWnd,IDC_EDIT3);
hEditWnd4=GetDlgItem(hDlgWnd,IDC_EDIT4);
hEditWnd5=GetDlgItem(hDlgWnd,IDC_EDIT5);
hEditWnd6=GetDlgItem(hDlgWnd,IDC_EDIT6);
hEditWnd7=GetDlgItem(hDlgWnd,IDC_EDIT7);
hEditWnd8=GetDlgItem(hDlgWnd,IDC_EDIT8);
switch(message)
{
case WM_INITDIALOG:
EnableWindow(hEditWnd1,FALSE);
return 1;
case WM_COMMAND:
if(LOWORD(wParam)==IDC_RADIO1)
{
selectNum=1;
EnableWindow(hEditWnd1,TRUE);
}
if(LOWORD(wParam)==IDC_RADIO2)
{
selectNum=2;
EnableWindow(hEditWnd1,TRUE);
}
if(LOWORD(wParam)==IDOK)
{
if(selectNum==1)//学号唯一,按照学号找,只有1个
{
GetWindowText(hEditWnd1,stuNum,sizeof(stuNum));
for(p=head;p!=NULL;)
{
if(!strcmp(p->per.StuNum,stuNum))
{
SetWindowText(hEditWnd2,p->per.StuNum);//学号
SetWindowText(hEditWnd3,p->per.StuName);//姓名
sprintf(C,"%s",(p->per.StuAge));
SetWindowText(hEditWnd4,C);//年龄
sprintf(C,"%s",(p->per.StuSex));
SetWindowText(hEditWnd5,C);//性别
sprintf(C,"%s",(p->per.StuPhone));
SetWindowText(hEditWnd6,C);//电话
sprintf(C,"%s",(p->per.StuOICQ));
SetWindowText(hEditWnd7,C);//OICQ
SetWindowText(hEditWnd8,"1");
break;
}
p=p->next;
}
selectNum=0;
if(p == NULL)
{
MessageBox(NULL,"查无此人!","系统消息",MB_OK);
}
}
if(selectNum==2)//按照姓名查,可能有多条//将查找到的多条记录存在新的链表中
{
GetWindowText(hEditWnd1,stuNam,sizeof(New->per.StuName));
for(p=head;p!=0;)
{
if(strstr(p->per.StuName,stuNam)!=0)//stuNam数组包含结构体中的stuNam项的时候,表示模糊查询
{
sNew=(struct node *)malloc(sizeof(struct node));
strcpy(sNew->per.StuName,p->per.StuName);
strcpy(sNew->per.StuNum,p->per.StuNum);
strcpy(sNew->per.StuAge,p->per.StuAge);
strcpy(sNew->per.StuSex,p->per.StuSex);
strcpy(sNew->per.StuPhone,p->per.StuPhone);
strcpy(sNew->per.StuOICQ,p->per.StuOICQ);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -