Graduation design C++ is based on MFC laboratory computer room management system graduation thesis | Find the treasure of C station

Subject

C++ based on MFC laboratory computer room management system

table of Contents

1 Introduction

2. Introduction to Development Technology

2.1 Introduction of VC++ 6.0 development platform

2.2 Introduction to the database system

3. System requirement analysis

3.1 Demand analysis

3.2 Design objective analysis

3.3 Analysis of security and confidentiality requirements

3.4 Development and operating environment

3.5 System feasibility analysis

3.5.1 Technical feasibility

3.5.2 Economic feasibility

3.5.3 Management feasibility

3.5.4 Legal feasibility

4. System Design

4.1 Outline design

4.1.1 Master Plan

4.1.2 Student planning

4.2 Design of functional module structure

4.3 System operation flow chart

4.4 System database design

4.4.1 Data sheet design

4.4.2 View design

4.4.3 Trigger design

5. System implementation

5.1 HOOK message hook design

5.1.1 Overview

5.1.2 Program related code analysis

5.2 Design of full-screen transparent login form on student side

5.2.1 Overview

5.2.2 Program related code analysis

5.3 System tray design

5.3.1 Overview

5.3.2 Program related code analysis

5.4 Student monitoring server background thread design

5.4.1 Overview

5.4.2 Program related code analysis

5.5 System Recovery Failure Detection

5.5.1 Overview

5.5.2 Program related code analysis

5.6 Multi-threaded master control terminal design

5.6.1 Overview

5.6.2 Program related code analysis

5.7 Implementation of Excel table import and export

5.7.1 Overview

5.7.2 Program related code analysis

5.8 Implementation of a single program instance

5.8.1 Overview

5.7.2 Program related code analysis

5.9 Implementation of the host list.

5.9.1 Overview

5.9.2 Main code analysis

5.10 Realization of Remote Desktop

5.10.1 Overview

5.10.2 Main code analysis.

5.11 Implementation of configuration information registry storage

5.11.1 Overview

5.11.2 Related code analysis

5.12 Realize the progress bar under the status bar

6. System testing and performance analysis

7. Summary

references

Thanks


Thousands of words omitted here


Outline design

The laboratory computer room management system is a typical C/S mode application, including two parts: the student terminal and the main control terminal.

Host planning

The main control terminal is responsible for the verification of the student terminal's computer login, the remote control of the student terminal, etc. The specific functional modules are as follows:

(1) System setting module

1) Communication settings: the communication port settings of the host and the controlled end.

2) Password modification: modify the unlocking password of the master control terminal.

(2) Account management:

1) Add account: the required fields are: student ID, name, class, and password.

2) Account modification: Modify the specified account. If the student forgets the password, the administrator can change the password.

3) Batch import: You can import Excel table data containing account information into the database.

4) Batch delete: You can delete the queried accounts in batch.

(3) Daily maintenance:

1) Computer log: record every log on and log off of students.

2) Abnormal log: record the abnormal log of the student terminal, such as the failure of the recovery card.

3) Database backup: the administrator can perform data backup on a regular basis

(4) Student list:

1) List dynamic maintenance: manage student connections and dynamically update the list.

2) Message sending: send a message to the selected student.

3) Remote desktop: remote desktop control for a single student.

4) Remote shutdown: issue a shutdown command to the selected student terminal.

5) Remote restart: issue a shutdown command to the selected student terminal.

Student planning

The student terminal is responsible for locking the screen of the student computer, executing the commands of the main control terminal, etc. The specific functional modules are as follows:

(1) Login module:

1) Hot key shielding: shield related hot keys when the system starts, lock the screen, and display the login box.

2) Login verification: Send the student ID and password to the server. If the verification is successful, it will be automatically unlocked.

3) Administrator unlock: The administrator can use the unlock password to unlock the student terminal.

(2) Communication module with server:

1) Receive messages: Receive messages from the server and automatically prompt on the desktop.

2) Receive remote control: respond to various controls required by the server.

3) Abnormality monitoring: send the abnormality that occurs on the student end to the server end.

4) Modify password: Students modify the login password.

(3) Student settings: you need to be in the management mode to use, set the communication method and unlock password.

Functional module structure design

System operation flow chart

System database design

Data sheet design (partial)

For the laboratory computer room management system, the main function is to control the computer on the student side, and the database design is relatively simple. This system uses SQL 2000 database, the name of the system database is db_LabMS, and the database db_LabMS includes 3 data tables. The following is a summary of the database and the structure of the data table.

(1) User data sheet

The user saves the account information of the system user, the data table is named " student ", and the structure is shown in Table 4-1.

Table: 4-1 User table (student)

Serial number

Column name

type of data

length

Logo

Primary key

Allow empty

Defaults

Description

1

s_id

int

4

Yes

 

no

 

Automatic ID

2

s_xh

nvarchar

12

 

Yes

no

 

student ID

3

s_name

nvarchar

8

 

 

no

 

first name

4

s_pwd

nvarchar

12

 

 

no

 

password

5

s_class

nvarchar

30

 

 

no

 

class

(2) Record data sheet on the computer

It is used to save the data recorded by students on the computer, the data table is named " log ", and the structure is shown in Table 4-2.

Table: 4-2 Recording data table on the computer (log)

Serial number

Column name

type of data

length

Logo

Primary key

Allow empty

Defaults

Description

1

l_id

int

4

Yes

Yes

no

 

Automatic ID

2

s_xh

nvarchar

12

 

 

no

 

student ID

3

l_type

nvarchar

8

 

 

no

 

Types of

4

l_time

datetime

8

 

 

no

(getdate())

time

5

l_pc

nvarchar

20

 

 

no

 

PC name

(3) Abnormal data table

It is used to save the abnormal information of the student computer, the data table is named " exception ", and the structure is shown in Table 4-3.

Table: 4-3 abnormal data table (exception)

Serial number

Column name

type of data

length

Logo

Primary key

Allow empty

Defaults

Description

1

e_id

int

4

Yes

Yes

no

 

Automatic ID

2

e_type

nvarchar

50

 

 

Yes

 

Exception type

3

e_state

nvarchar

8

 

 

Yes

(N'Untreated')

status

4

e_pc

nvarchar

20

 

 

Yes

 

PC name

5

e_time

datetime

8

 

 

Yes

(getdate())

Abnormal occurrence time

(4) Host list data table

It is used to save the list of currently logged-in student computers, the data table is named " list ", and the structure is shown in Table 4-4.

Table: 4-4 Host List Data Table (list)

Serial number

Column name

type of data

length

Logo

Primary key

Allow empty

Defaults

Description

1

l_xh

nvarchar

12

 

 

Yes

 

student ID

2

l_mac

nvarchar

12

 

 

Yes

 

MAC address

3

l_pc

nvarchar

20

 

 

Yes

 

PC name

4

l_time

datetime

8

 

 

Yes

(getdate())

Login time

View design (partial)

From the user's point of view, a view is to view the data in the database from a specific angle. From the inside of the database system, the view is composed of data in one or more tables. From the outside of the database system, the view is like a table. The general operations that can be performed on the table can be applied to the view, such as query , Insert, modify, delete operations, etc. [3]

The logview view creation statement of the system is as follows:

CREATE VIEW dbo.logview AS SELECT dbo.[log].l_time, dbo.[log].s_xh, dbo.student.s_name, dbo.[log].l_type,       dbo.[log].l_pc, dbo.student.s_class FROM dbo.[log] INNER JOIN       dbo.student ON dbo.[log].s_xh = dbo.student.s_xh

Trigger design (partial)

Trigger (trigger) is a special stored procedure , its execution is not called by the program, nor is it started manually, but triggered by events, for example, it will be activated when a table is operated (insert, delete, update) carried out. [4] When an insert operation is performed on the log table, an update of the list table will be triggered, and the list table saves the current host list.

The trigger trig_updatelist creation statement is as follows:

CREATE TRIGGER trig_updatelist ON dbo.[log] FOR insert AS if exists(select l_mac from inserted where l_mac not in (select l_mac from [list])) begin insert into [list](l_pc,l_mac,l_xh) select l_pc,l_mac,s_xh from inserted end else begin delete [list] where l_mac=(select l_mac from inserted) end 

System implementation (partial)

HOOK message hook design

Overview

The student’s boot is to lock the screen, shield the system hot keys, and protect the lock screen program from being closed. Shielding system hot keys requires the use of HOOK technology. Hook is a platform of the Windows message processing mechanism. Applications can set subroutines on it to monitor certain messages of a specified window, and the monitored window can be owned by other processes. Created. [5] When the message arrives, process it before the target window processing function. The hook mechanism allows applications to intercept and process Window messages or specific events. Some hot keys such as ALT+F4, ALT+ESC, etc. can be shielded through HOOK technology, which can effectively protect the lock screen program.

Program related code analysis

Generally speaking, the system-level hook must be a DLL. The code snippet of a keyboard hook DLL (TaskKeyHook.dll) is provided below:

//头文件   //TaskKeyHook.h // #define DLLIMPORT __declspec(dllimport)   DLLIMPORT BOOL DisableTaskKeys(BOOL bEnable, BOOL bBeep); DLLIMPORT BOOL AreTaskKeysDisabled();   //实现文件   // TaskKeyHook.cpp // #define _WIN32_WINNT 0x0500 // for KBDLLHOOKSTRUCT #include <afxwin.h>         // MFC core and standard components   #define DLLEXPORT __declspec(dllexport)   // // App (DLL) object // class CTaskKeyHookDll : public CWinApp { public:      CTaskKeyHookDll()  { }      ~CTaskKeyHookDll() { } } MyDll;     // 下面的代码表示这一部分在此DLL所有实例之间共享 // 低级键盘钩子一定是系统级的钩子 // #pragma data_seg (".mydata") HHOOK g_hHookKbdLL = NULL; // 钩子句柄 BOOL  g_bBeep = FALSE;     // 按下非法键时蜂鸣响铃 #pragma data_seg () #pragma comment(linker, "/SECTION:.mydata,RWS") // 告诉链接器:建立数据共享段   // // 低级键盘钩子 // 截获任务转换键:不传递直接返回 // LRESULT CALLBACK MyTaskKeyHookLL(int nCode, WPARAM wp, LPARAM lp) {      KBDLLHOOKSTRUCT *pkh = (KBDLLHOOKSTRUCT *) lp;        if (nCode==HC_ACTION) {          BOOL bCtrlKeyDown =               GetAsyncKeyState(VK_CONTROL)>>((sizeof(SHORT) * 8) - 1);            if ((pkh->vkCode==VK_ESCAPE && bCtrlKeyDown) || // Ctrl+Esc               // Alt+TAB               (pkh->vkCode==VK_TAB && pkh->flags & LLKHF_ALTDOWN) ||                 // Alt+Esc               (pkh->vkCode==VK_ESCAPE && pkh->flags & LLKHF_ALTDOWN)||               (pkh->vkCode==VK_LWIN || pkh->vkCode==VK_RWIN)) { // 开始菜单                    if (g_bBeep && (wp==WM_SYSKEYDOWN||wp==WM_KEYDOWN))                        MessageBeep(0); // 蜂鸣                    return 1; // 不再往CallNextHookEx传递,直接返回          }      }      return CallNextHookEx(g_hHookKbdLL, nCode, wp, lp); }     // 是否屏蔽任务键序列——也就是说键盘钩子是否安装? // 注:这里假设没有其它钩子做同样的事情 // DLLEXPORT BOOL AreTaskKeysDisabled() {      return g_hHookKbdLL != NULL; }     // 屏蔽任务键:安装低级键盘构 // 返回当前是否屏蔽标志(TRUE/FALSE) // DLLEXPORT BOOL DisableTaskKeys(BOOL bDisable, BOOL bBeep) {      if (bDisable) {          if (!g_hHookKbdLL) {               g_hHookKbdLL = SetWindowsHookEx(WH_KEYBOARD_LL,                    MyTaskKeyHookLL, MyDll.m_hInstance, 0);          }        } else if (g_hHookKbdLL != NULL) {          UnhookWindowsHookEx(g_hHookKbdLL);          g_hHookKbdLL = NULL;      }      g_bBeep = bBeep;        return AreTaskKeysDisabled(); }  

TaskKeyHook outputs two functions: DisableTaskKeys and AreTaskKeysDisabled. The former installs the WH_KEYBOARD_LL hook; the latter determines whether the hook is installed. The processing idea of ​​this keyboard hook is to intercept hot keys such as Alt+Tab, Ctrl+Esc, Alt+Esc, and the Windows key.

Design of full-screen transparent login form for students

Overview

As soon as the student terminal is started, it will automatically lock the student computer in full screen. The student terminal lock screen login interface is shown in Figure 5-1. The realization principle is realized through two dialogs. The parent dialog realizes a full-screen transparent form, and then a child dialog (login box) pops up. The login frame hides the border and fills the background with a brush.

Figure: 5-1 The main window of the laboratory computer room management system

Program related code analysis

The main code snippets of the full-screen transparent login form:

// ClientDlg.cpp : implementation file   void CClientDlg::OnFullScreen() {        LONG style = GetWindowLong(m_hWnd, GWL_STYLE);    //得到窗口风格      ::ShowWindow(m_hWnd, SW_MAXIMIZE);      style = GetWindowLong(m_hWnd, GWL_STYLE);      style &= ~(WS_DLGFRAME | WS_THICKFRAME);      SetWindowLong(m_hWnd, GWL_STYLE, style);          //设置窗口风格      int cx = GetSystemMetrics(SM_CXSCREEN);      int cy = GetSystemMetrics(SM_CYSCREEN);      ::SetWindowPos(m_hWnd, HWND_TOPMOST, -1, -1, cx+3, cy+3, SWP_FRAMECHANGED);//实现全屏显示        ::InvalidateRect(m_hWnd,NULL,TRUE);               //窗口背景要被擦除        SetWindowLong(this->GetSafeHwnd(),GWL_EXSTYLE,          GetWindowLong(this->GetSafeHwnd(),GWL_EXSTYLE)^0x80000);    //窗口加入WS_EX_LAYERED扩展属性      HINSTANCE hInst = LoadLibrary("User32.DLL");      if (hInst)      {          typedef BOOL (WINAPI *MYFUNC)(HWND,COLORREF,BYTE,DWORD);          MYFUNC fun = NULL;          fun = (MYFUNC)GetProcAddress(hInst,"SetLayeredWindowAttributes");    //取得SetLayeredWindowAttributes函数指针          if (fun)               fun(this->GetSafeHwnd(),0,125,2);    //设置窗口为半透明          FreeLibrary(hInst);      }        CTaskKeyMgr::Disable(CTaskKeyMgr::ALL, TRUE); //利用Hook工具类实现热键屏蔽        CLoginDlg dlg=new CLoginDlg();      dlg.DoModal();                   //弹出模式对话框等待用户输出        CTaskKeyMgr::Disable(CTaskKeyMgr::ALL, FALSE); //恢复所有禁止的东西 }

The main code snippets of the login box:

// LoginDlg.cpp : implementation file////填充背景void CLoginDlg::OnPaint() {	CPaintDC dc(this); // device context for painting	CRect   rect;   	GetClientRect(&rect);   	CDC   dcMem;   	dcMem.CreateCompatibleDC(&dc);   	CBitmap   bmpBackground;   	bmpBackground.LoadBitmap(IDB_BITMAP1);  	BITMAP   bitmap;   	bmpBackground.GetBitmap(&bitmap);   	CBitmap   *pbmpOld=dcMem.SelectObject(&bmpBackground);   	dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,   		bitmap.bmWidth,bitmap.bmHeight,SRCCOPY);  }void CLoginDlg::OnLogin() {	// TODO: Add your control notification handler code here	UpdateData(true); 	if ((m_uid == "")||(m_pwd == ""))         //如果用户名为空	{				MessageBoxA("用户名或密码不能为空");		GetDlgItem(IDC_UID)->SetFocus();		return;	}	else	{		if (m_uid.Find(" ")!=-1)		{			MessageBoxA("用户名不能包含空格");			GetDlgItem(IDC_UID)->SetFocus();			return;		}else			if (m_pwd.Find(" ")!=-1)			{				MessageBoxA("密码不能包含空格");				GetDlgItem(IDC_PWD)->SetFocus();				return;			} 	}	//发送用户名和密码到服务端验证	if (CScoketMgr::SendLogin(m_uid,m_pwd))	{		CDialog::OnCancel();	} } BOOL CLoginDlg::PreTranslateMessage(MSG* pMsg) {	// 屏蔽掉RETURN、PAUSE、ESCAPE键,防止登陆框被关闭	if   (pMsg->message==WM_KEYDOWN&&pMsg->wParam==VK_RETURN) 	{       		return TRUE;   	}	if   (pMsg->message==WM_KEYDOWN&&pMsg->wParam==VK_PAUSE) 	{       		return TRUE;   	}	if (pMsg->message==WM_KEYDOWN&&pMsg->wParam==VK_ESCAPE)	{		return TRUE;	} 	return CDialog::PreTranslateMessage(pMsg);}void CLoginDlg::OnClose() {	// 防止登陆框被关闭 	return; } void CLoginDlg::OnUnlock() {	// 解锁	UpdateData(true);	CMD5 md5T;	if (md5T.MD5(m_pwd)==theApp.unlockpwd)       //验证解锁密码		OnCancel();}

Thousands of words omitted here


Download

Download the complete source program + database + paper + instructions for use: https://download.csdn.net/download/frank2102/19414729