📄 1.cpp
字号:
}
for(j=1;;j++)
{
if(Screen[i+j].earmark==0&&Screen[i+j].color1==0) break;
if(Screen[i+j].color1!=LOWORD(wParam)) Screen[i+j].color2=0;
}
break;
}
}
hdc=GetDC(hWnd);
lines=(rect.bottom-rect.top)*8/10/cyChar;
nNumPaint = min( nCurPos+lines,LINES);
for(j=0,i=nCurPos;i<nNumPaint;i++,j++)
{
if(Screen[i].color2)SetTextColor(hdc,RGB(255,0,0));
else SetTextColor(hdc,RGB(0,0,0));
TextOut(hdc,((rect.right-rect.left)/30+295),(rect.bottom-rect.top)*1/10+cyChar*j,Screen[i].Line,strlen(Screen[i].Line));
if(Screen[i].earmark)
{
MoveWindow(hWndList[Screen[i].earmark/10].choose[Screen[i].earmark%10-1],((rect.right-rect.left)/30-5+200+100)-50,(rect.bottom-rect.top)*1/10+cyChar*j,cxChar*2,cyChar,0);
ShowWindow(hWndList[Screen[i].earmark/10].choose[Screen[i].earmark%10-1],1);
}
}
ReleaseDC(hWnd,hdc);
}
switch(LOWORD(wParam))
{
case 2201:
//连接数据服务器
if(TurnOff)
{
GetWindowText(hEdit[0],ip,strlen(ip));
if(!NetLink(hWnd,ip))
{
Displays(hWnd,"网络连接失败...");
break;
}
TurnOff=0;
EnableWindow(hEdit[0],0);
}
GetWindowText(hEdit[1],users.Subject,50);
GetWindowText(hEdit[2],users.Name,50);
GetWindowText(hEdit[3],users.PassWord,50);
strcpy(SendLine,"login:");
StrLen=strlen(SendLine);
for(i=1;i<4;i++)
{
GetWindowText(hEdit[i],&SendLine[StrLen],MAXLINE);
StrLen=strlen(SendLine);
SendLine[StrLen++]='#';
}
SendLine[StrLen]='\0';
if(!SendUser_Lg(sock,SendLine))
break;
Displays(hWnd,"成功发送登陆信息,等待服务器回应...");
if(RecvUser_Lg(sock,ReadLine,MAXLINE+1)==-1)
break;
Displays(hWnd,ReadLine);
if(!strcmp(ReadLine,"student"))
{
strcpy(SendLine,"Srecv:ScanTm:");
if(!SendUser_Lg(sock,SendLine))
break;
if(RecvUser_Lg(sock,ReadLine,MAXLINE+1)==-1)
{
Displays(hWnd,"接收试卷状态设置信息失败.");
break;
}
if(ReadLine[0]=='t')
{
TIMES=atoi(&ReadLine[1]);
}
Displays(hWnd,ReadLine);
strcpy(SendLine,"Srecv:GetSta:");
if(!SendUser_Lg(sock,SendLine))
{
Displays(hWnd,"询问试卷状态失败.");
break;
}
if(RecvUser_Lg(sock,ReadLine,MAXLINE+1)==-1)
{
Displays(hWnd,"接收试卷状态失败.");
break;
}
i=atoi(ReadLine);
switch(i)
{
case 0:
Displays(hWnd,"你所要的试卷还没生成,请与出卷老师联系.");
break;
case 1:
strcpy(SendLine,"Srecv:GetRlt:");
SendUser_Lg(sock,SendLine);
RecvUser_Lg(sock,ReadLine,MAXLINE+1);
strcpy(Buffers,ReadLine);
if(!strcmp(Buffers,"Erro"))
Inherilt=false;
else Inherilt=true;
////////////////////////////////////////////////////////////////////////
strcpy(SendLine,"Srecv:GetNum:");
if(SendUser_Lg(sock,SendLine))
{
if(RecvUser_Lg(sock,ReadLine,MAXLINE+1)!=-1)
{
sscanf(ReadLine,"%d#%d#%d#%d#%d#%d#%d#%d#%d#%d#%s",&Date.year,&Date.month,&Date.day,&Time1.hour,&Time1.minute,&Time1.second,&Time2.hour,&Time2.minute,&Time2.second,&QuestionNumber,&People);
TestPaper=new TestRubric [QuestionNumber];
memset(TestPaper,0,sizeof(TestRubric)*QuestionNumber);
Result=new int [QuestionNumber];
memset(Result,0,sizeof(int)*QuestionNumber);
///////////////////////////////////////////////////
if(Inherilt)
{
for(i=0,j=0;i<QuestionNumber;i++)
{
if(Buffers[j]=='\0') break;
for (int n=0;Buffers[j]!='#';j++,n++)
{
Temp[n]=Buffers[j];
}
Result[i]=atoi(Temp);
j++;
}
}
//////////////////////////////////////////////////
for(i=0;i<QuestionNumber;i++)
{
sprintf(SendLine,"Srecv:GetQue:%d",i);
StrLen=strlen(SendLine);
if(SendUser_Lg(sock,SendLine))
{
if(RecvUser_Lg(sock,ReadLine,MAXLINE+1)!=-1)
{
P=ReadLine;
P2=ReadLine;
while(*P)
{
if(*P=='#')
*P='\0';
P++;
}
strcpy(TestPaper[i].Tile.Text,P2);
P2+=(strlen(P2)+1);
strcpy(TestPaper[i].choose[0].Text,P2);
P2+=(strlen(P2)+1);
strcpy(TestPaper[i].choose[1].Text,P2);
P2+=(strlen(P2)+1);
strcpy(TestPaper[i].choose[2].Text,P2);
P2+=(strlen(P2)+1);
strcpy(TestPaper[i].choose[3].Text,P2);
}
else Displays(hWnd,"接收试题出错.");
}
else Displays(hWnd,"请求接收试题出错.");
}
Displays(hWnd,"试卷接收完毕.");
closesocket(sock);
/************************************************************************************************/
for(i=0;i<4;i++)
{
ShowWindow(hEdit[i],0);
ShowWindow(hStatic[i],0);
}
ShowWindow(Button1,0);
ShowWindow(Button2,0);
sprintf(Temp,"%s试卷",users.Subject);
SetWindowText(hWnd,Temp);
sprintf(Tile2[0],"学科: %s",users.Subject);
sprintf(Tile2[1],"姓名: %s",users.Name);
sprintf(Tile2[2],"考号: %s",users.PassWord);
sprintf(Tile2[3],"监考人: %s",People);
sprintf(Tile2[4],"考题数量: %d",QuestionNumber);
sprintf(Tile2[5],"开考日期: %d.%2d.%2d",Date.year,Date.month,Date.day);
sprintf(Tile2[6],"开考时间: %2d:%2d:%2d",Time1.hour,Time1.minute,Time1.second);
sprintf(Tile2[7],"结束时间: %2d:%2d:%2d",Time2.hour,Time2.minute,Time2.second);
for(i=0,ID=33300;i<8;i++,ID++)
{
hStatic2[i] = CreateWindow( "STATIC", Tile2[i],
WS_CHILD | WS_BORDER |
WS_VISIBLE |
SS_LEFT,
(rect.right-rect.left)/30,(rect.bottom-rect.top)/13*(i+1),
150,
20,
hWnd,
(HMENU) ID,
hInst, NULL );
}
i+=3;
Button3=CreateWindow( "BUTTON","提交试卷",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_FLAT,
(rect.right-rect.left)/30,(rect.bottom-rect.top)/13*i++,150,20,hWnd,(HMENU)2203,hInst, NULL );
Button4=CreateWindow( "BUTTON","返回系统",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_FLAT,
(rect.right-rect.left)/30,(rect.bottom-rect.top)/13*i,150,20,hWnd,(HMENU)2204,hInst, NULL );
hStatic2[8]=CreateWindow( "BUTTON","考试信息栏",WS_CHILD|WS_VISIBLE|BS_GROUPBOX|BS_FLAT,
(rect.right-rect.left)/30-5,(rect.bottom-rect.top)/13-(rect.bottom-rect.top)/20,160,(rect.bottom-rect.top)/13*i+(rect.bottom-rect.top)/20,hWnd,(HMENU)205,hInst, NULL );
hStatic2[9]=CreateWindow( "BUTTON","试卷题目栏",WS_CHILD|WS_VISIBLE|BS_GROUPBOX|BS_FLAT,
(rect.right-rect.left)/30-5+200,(rect.bottom-rect.top)/13-(rect.bottom-rect.top)/20,(rect.right-rect.left)*29/30-200,(rect.bottom-rect.top)/13*i+(rect.bottom-rect.top)/20,hWnd,(HMENU)205,hInst, NULL );
Width=((rect.right-rect.left)*15/30)/cxChar/2*2;
InitRam(QuestionNumber); //堆中申请屏幕内存
InitScreen(cxChar,QuestionNumber); //初始化屏幕为试卷信息
InitClientWindow(hWnd,QuestionNumber);
TurnScreen=true;
InvalidateRect(hWnd,NULL,TRUE);
UpdateWindow(hWnd);
lines=(rect.bottom-rect.top)*8/10/cyChar;
if ( lines < LINES )
{
SCROLLINFO si;
si.cbSize = sizeof( SCROLLINFO );
si.fMask = SIF_POS | SIF_RANGE | SIF_PAGE;
si.nMin = 0;
si.nMax = LINES-1;
si.nPage = lines;
si.nPos = nCurPos;
EnableScrollBar( hWnd, SB_VERT, ESB_ENABLE_BOTH );
SetScrollInfo( hWnd, SB_VERT, &si, TRUE );
}
SetTimer(hWnd,ID_TIMER,1000,(TIMERPROC)TimerProc);
/************************************************************************************************/
}
else Displays(hWnd,"无法接收试卷题数.");
}
else Displays(hWnd,"询问试卷题数出错.");
break;
case 2:
Displays(hWnd,"对不起,考试时间未到.");
break;
case 3:
Displays(hWnd,"该试卷已经答题完毕或者考试时间已过,如要复考请与老师联系.");
break;
}
}
else if(!strcmp(ReadLine,"teacher")){}
else if(!strcmp(ReadLine,"amdin")){}
break;
case 2202:
DestroyWindow( hWnd );
break;
case 2203:
SaveResult(true);
DestroyWindow( hWnd );
break;
case 2204:
DestroyWindow( hWnd );
break;
}
break;
case WM_DESTROY :
KillTimer(hWnd,ID_TIMER);
PostQuitMessage(0);
break;
default :
return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
}
return( 0L );
}
/*
* 网络连接子函数
*/
BOOL NetLink(HWND hWnd,char * IP)
{
int err;
err = WSAStartup(0x0101, &WsaData);
if (err == SOCKET_ERROR)
{
Displays(hWnd,"WSAStartup Failed");
return 0;
}
Displays(hWnd,"正在初始化网络...........");
memset(&serv_addr, 0, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
// 使用这个逻辑服务器
serv_addr.sin_addr.s_addr = inet_addr(IP);
serv_addr.sin_port = htons(SERVER_TCP_PORT);
sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0)
{
Displays(hWnd,"socket() 错误 -- 检查你的TCP/IP是否正确安装?");
return 0;
}
if(connect(sock, (struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0)
{
Displays(hWnd,"connect() 错误 -- 检查服务器程序是否运行?");
return 0;
}
sprintf(Buffers,"已经与 %s 正确连接.",IP);
Displays(hWnd,Buffers);
return 1;
}
/*
* 数据发送子函数
*/
BOOL SendUser_Lg(SOCKET sock,char Sendline[MAXLINE])
{
int n;
int nleft;
int nwritten;
char *Temp;
n=strlen(Sendline);
Sendline[n++]='\n';
Sendline[n]='\0';
n=strlen(Sendline);
Temp=Sendline;
nleft = n;
while (nleft > 0)
{
nwritten = send(sock,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -