?? 1.cpp
字號:
// 1.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include <winsock2.h>
#include <stdio.h>
#include <stdlib.h>
#include <ODBCINST.H>
#include <SQLEXT.H>
#pragma comment (lib,"ws2_32.lib")
#define ID_TIMER 3000
/*結(jié)構(gòu)體定義*/
//試卷每道題的結(jié)構(gòu)
struct Questions{
BOOL state;
char Text [512];
};
struct SelectObject{
BOOL state;
char Text[256];
};
struct TestRubric{
struct Questions Tile;
struct SelectObject choose [4];
};
struct User
{
char Subject[50];
char Name[50];
char PassWord[50];
};
//將試卷按屏幕行寬格式化
struct Lines{
int earmark;
BOOL color1;
BOOL color2;
char Line [512];
};
Lines * Screen=NULL;
int Width;
BOOL TurnScreen=false;
//子窗口句柄結(jié)構(gòu)
struct hWndChoose{
HWND choose[4];
};
HINSTANCE hInst; // current instance
HWND hWnd;
LPCTSTR lpszAppName = "MyApp";
LPCTSTR lpszTitle = "登陸窗";
RECT rect ;
WSADATA WsaData;
SOCKET sock;
struct sockaddr_in serv_addr;
char Buffers[1024];
TestRubric * TestPaper=NULL;
hWndChoose * hWndList;
int * Result;
BOOL TurnOff=1;
BOOL Inherilt=false;
int LINES=0;
ULONG TIMES=0;
//試卷信息表
int QuestionNumber=0;
User users;
DATE_STRUCT Date;
TIMESTAMP_STRUCT Time1,Time2;
char People[20];
int cxChar,cyChar;
/* Constants */
#define MAXLINE 512
#define SERVER_TCP_PORT 5554
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About (HWND, UINT, WPARAM, LPARAM);
BOOL SendUser_Lg(SOCKET,char Sendline[MAXLINE]);
int RecvUser_Lg(SOCKET,char * readline,int n);
BOOL NetLink(HWND,char *);
void Displays(HWND hWnd,char * P);
void InitClientWindow(HWND hWnd,int N); //初始化子窗口控件子函數(shù)
void InitRam(int QNum);
void InitScreen(int cxChar,int QNum);
void Scroll( HWND hWnd, int* pnCurPos, DWORD wScroll ); //滾動條控制子函數(shù)
void CALLBACK TimerProc(HWND hWnd,UINT iMsg, UINT iTimerID, DWORD dwTime); //定時器回調(diào)子函數(shù)
void SaveResult(BOOL Turn);
int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow)
{
MSG msg;
WNDCLASSEX wc;
// Register the main application window class.
//............................................
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon( hInstance, lpszAppName );
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = lpszAppName;
wc.cbSize = sizeof(WNDCLASSEX);
wc.hIconSm = NULL;
if ( !RegisterClassEx( &wc ) )
return( FALSE );
hInst = hInstance;
GetWindowRect(GetDesktopWindow(),&rect);
// Create the main application window.
//....................................
hWnd = CreateWindowEx(WS_EX_OVERLAPPEDWINDOW,lpszAppName,
lpszTitle,
WS_BORDER|WS_VSCROLL|WS_VISIBLE|WS_SYSMENU,
0, 0,
rect.right-rect.left, rect.bottom-rect.top,
NULL,
NULL,
hInstance,
NULL
);
if ( !hWnd )
return( FALSE );
ShowWindow( hWnd, nCmdShow );
UpdateWindow( hWnd );
while( GetMessage( &msg, NULL, 0, 0) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
if(hWndList)
delete[] hWndList;
if(TestPaper)
delete[] TestPaper;
if(Screen)
delete[] Screen;
if(Result)
delete[] Result;
// closesocket(sock); /***********************************************/
return( msg.wParam );
}
LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
static HWND hStatic [4];
static HWND hEdit [4];
static HWND Button1,Button2,Button3,Button4;
static HWND hStatic2 [10];
static char * Tile []={"服務器IP地址:","科目:","賬號:","密碼/考號:"};
static char Tile2[8][50];
static int nCurPos;
char Temp[20];
char * P;
char * P2;
char ip[32];
char SendLine[MAXLINE];
char ReadLine[MAXLINE+1];
int StrLen=0;
int i,ID,j,lines,nNumPaint;
HDC hdc;
TEXTMETRIC tm;
PAINTSTRUCT ps;
switch( uMsg )
{
case WM_CREATE :
// Create a static and edit control that will be sized to match
// the parent window's client area.
//.............................................................
GetClientRect (hWnd, &rect) ;
for(i=0,ID=10000;i<4;i++,ID++)
{
hStatic[i] = CreateWindow( "STATIC", Tile[i],
WS_CHILD | WS_BORDER |
WS_VISIBLE |
SS_LEFT,
(rect.right-rect.left)/2-100, (rect.bottom-rect.top)/2-100+50*i,
CW_USEDEFAULT,
CW_USEDEFAULT,
hWnd,
(HMENU) ID, // The control ID.
hInst, NULL );
}
hEdit [0]= CreateWindow( "EDIT", "127.0.0.1",
WS_CHILD | WS_BORDER |
WS_VISIBLE |
ES_LEFT | ES_MULTILINE ,
(rect.right-rect.left)/2, (rect.bottom-rect.top)/2-100, // Set the upper left
// corner
CW_USEDEFAULT, // to be under the static
CW_USEDEFAULT, // window.
hWnd,
(HMENU) 110, // The control ID.
hInst, NULL );
hEdit [1]= CreateWindow( "EDIT", "",
WS_CHILD | WS_BORDER |
WS_VISIBLE |
ES_LEFT | ES_MULTILINE ,
(rect.right-rect.left)/2, (rect.bottom-rect.top)/2-50, // Set the upper left
// corner
CW_USEDEFAULT, // to be under the static
CW_USEDEFAULT, // window.
hWnd,
(HMENU) 111, // The control ID.
hInst, NULL );
hEdit [2]= CreateWindow( "EDIT", "",
WS_CHILD | WS_BORDER |
WS_VISIBLE |
ES_LEFT | ES_MULTILINE ,
(rect.right-rect.left)/2, (rect.bottom-rect.top)/2, // Set the upper left
// corner
CW_USEDEFAULT, // to be under the static
CW_USEDEFAULT, // window.
hWnd,
(HMENU) 112, // The control ID.
hInst, NULL );
hEdit [3]= CreateWindow( "EDIT", "",
WS_CHILD | WS_BORDER |
WS_VISIBLE |
ES_LEFT | ES_PASSWORD,
(rect.right-rect.left)/2, (rect.bottom-rect.top)/2+50, // Set the upper left
// corner
CW_USEDEFAULT, // to be under the static
CW_USEDEFAULT, // window.
hWnd,
(HMENU) 113, // The control ID.
hInst, NULL );
Button1=CreateWindow( "BUTTON","登陸",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_FLAT,
(rect.right-rect.left)/2-100,(rect.bottom-rect.top)/2-100+50*i,100,20,hWnd,(HMENU)2201,hInst, NULL );
Button2=CreateWindow( "BUTTON","退出",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_FLAT,
(rect.right-rect.left)/2,(rect.bottom-rect.top)/2-100+50*i,100,20,hWnd,(HMENU)2202,hInst, NULL );
hdc = GetDC (hWnd) ;
GetTextMetrics (hdc, &tm) ;
cxChar = tm.tmAveCharWidth ;
cyChar = tm.tmHeight + tm.tmExternalLeading;
ReleaseDC (hWnd, hdc) ;
SetScrollRange(hWnd,SB_VERT,0,0,FALSE);
break;
case WM_SIZE :
{
// The parent window was resized. Size the static and edit
// controls to match the parent window's client area but
// don't move the the controls.
//.........................................................
for(i=0;i<4;i++)
{
HDWP hdwp = BeginDeferWindowPos(2);
hdwp = DeferWindowPos( hdwp, hStatic[i], NULL, 0, 0,
100, 20,
SWP_NOACTIVATE | SWP_NOZORDER |
SWP_NOMOVE );
hdwp = DeferWindowPos( hdwp, hEdit[i], NULL, 0, 0,
100, 20,
SWP_NOACTIVATE | SWP_NOZORDER |
SWP_NOMOVE );
EndDeferWindowPos( hdwp );
}
}
break;
case WM_VSCROLL :
Scroll( hWnd, &nCurPos, wParam );
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
//____________________________________________________________________________________________________
if(TurnScreen)
{
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);
}
}
}
//__________________________________________________________________________________________________
EndPaint(hWnd, &ps);
break;
case WM_COMMAND:
if(LOWORD(wParam)>=0&&LOWORD(wParam)<=QuestionNumber*10+4)
{
for(i=0;i<LINES;i++)
{
if(Screen[i].earmark==LOWORD(wParam))
{
Screen[i].color2=1;
for(j=1;;j++)
{
if(Screen[i+j].color1==LOWORD(wParam))
Screen[i+j].color2=1;
else break;
}
for(j=1;;j++)
{
if(Screen[i-j].earmark==0&&Screen[i-j].color1==0) break;
Screen[i-j].color2=0;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -