📄 clientdlg.cpp
字号:
sockSrv=socket(AF_INET,SOCK_STREAM,0);
SOCKADDR_IN addrSrv;
addrSrv.sin_addr.S_un.S_addr=htonl(INADDR_ANY);
addrSrv.sin_family =AF_INET;
addrSrv.sin_port=htons(6001);
bind(sockSrv,(SOCKADDR*)&addrSrv,sizeof(SOCKADDR));
listen(sockSrv,1);
////////////开启线程/////////////
CWinThread* hHandle;
hHandle=AfxBeginThread(waitmsg,(LPVOID)sockSrv);
}
void CClientDlg::OnClass()
{
SetWindowPos(&wndNoTopMost, 0, 0, 0, 0,SWP_NOSIZE | SWP_NOMOVE);
static l_counter=0;
HBITMAP hBitmap;
l_counter++;
if(l_counter>9)
{
glbshutdown();
}
currenttime=CTime::GetCurrentTime();
sockClient=socket(AF_INET,SOCK_STREAM,0);
addrSrv.sin_addr.S_un.S_addr=inet_addr("127.0.0.1");
addrSrv.sin_family =AF_INET;
addrSrv.sin_port=htons(6000);
int ret = connect(sockClient,(SOCKADDR*)&addrSrv,sizeof(SOCKADDR));
if(ret == SOCKET_ERROR)
{
MessageBox("与服务器连接遇到错误,请稍后重试","错误",MB_ICONERROR | MB_OK);
return ;
}
char sendbuf[2];
sprintf(sendbuf,"%d",1);
sendbuf[1]='\0';
ret = send(sockClient, sendbuf, strlen(sendbuf)+1, 0);
if(ret!=2)
{
MessageBox("与服务器连接遇到错误,请稍后重试!","错误",MB_ICONERROR|MB_OK);
return ;
}
char buff[2];
ret = recv(sockClient, buff, 2, 0);
if(ret == 0){
MessageBox("与服务器连接遇到错误,请稍后重试!","错误",MB_ICONERROR|MB_OK);
return ;
}
buff[ret] = '\0';
char tag=buff[0];
switch(tag)
{
case '0': tagofuse=true;tagofsj=1;m_trayIcon.SetIcon(IDI_ICON1);l_counter=0;CTaskKeyMgr::Disable(CTaskKeyMgr::ALL, FALSE);::ShowWindow(m_hWnd,SW_HIDE);break;
case 'b':
hBitmap=::LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_PICNOCLASS));
m_cl.SetBitmap(hBitmap);
//default: MessageBox("test","onclass",MB_OK);
}
}
void CClientDlg::OnCancel()
{
// MessageBox("alt+f4","test",MB_OK);
// exit(1);
//CTaskKeyMgr::Disable(CTaskKeyMgr::ALL, FALSE);
}
void CClientDlg::OnCloseWindow()
{
SetWindowPos(&wndTopMost, 0, 0, 0, 0,SWP_NOSIZE | SWP_NOMOVE);
CTaskKeyMgr::Disable(CTaskKeyMgr::TASKBAR,TRUE);
CTaskKeyMgr::Disable(CTaskKeyMgr::TASKKEYS,TRUE);
CTaskKeyMgr::Disable(CTaskKeyMgr::TASKMGR,TRUE);
::ShowWindow(m_hWnd,SW_SHOW);
m_trayIcon.SetIcon(0);
tagofuse=false;
tagofmsg=true;
ClipCursor(&rect);
}
int CClientDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
m_trayIcon.SetNotificationWnd(this, WM_MY_TRAY_NOTIFICATION);
m_trayIcon.SetIcon(0);
return 0;
}
LRESULT CClientDlg::OnTrayNotification(WPARAM uID, LPARAM lEvent)
{
return m_trayIcon.OnTrayNotification(uID, lEvent);
}
void CClientDlg::OnExit()
{
/////////////下机/////////////////
sockClient=socket(AF_INET,SOCK_STREAM,0);
addrSrv.sin_addr.S_un.S_addr=inet_addr("127.0.0.1");
addrSrv.sin_family =AF_INET;
addrSrv.sin_port=htons(6000);
int choice=MessageBox("你确认要下机吗?","确认",MB_YESNO|MB_ICONQUESTION);
if(choice==IDYES)
{
/////////////////向服务器发送下机消息//////////
int ret = connect(sockClient,(SOCKADDR*)&addrSrv,sizeof(SOCKADDR));
if(ret == SOCKET_ERROR)
{
MessageBox("下机失败,请到管理员处询问\n","错误",MB_ICONERROR | MB_OK);
return ;
}
char sendbuf[2];
sprintf(sendbuf,"%d",3);
sendbuf[1]='\0';
ret = send(sockClient, sendbuf, strlen(sendbuf)+1, 0);
if(ret!=2)
{
MessageBox("下机失败,请到管理员处询问\n","错误",MB_ICONERROR|MB_OK);
return ;
}
////////////下机成功后////////////////////
///////////////锁定桌面///////////////////
CStatic *mcl = (CStatic*)GetDlgItem(IDC_PICCL);
CStatic *mte = (CStatic*)GetDlgItem(IDC_PICTE);
CStatic *msxuehao=(CStatic*)GetDlgItem(IDC_SXUEHAO);
CStatic *mspassword = (CStatic*)GetDlgItem(IDC_SPASSWORD);
CStatic *mxuehao = (CStatic*)GetDlgItem(IDC_XUEHAO);
CStatic *mpassword = (CStatic*)GetDlgItem(IDC_PASSWORD);
CStatic *msj = (CStatic*)GetDlgItem(IDC_SJ);
// CStatic *mzy = (CStatic*)GetDlgItem(IDC_ZY);
msj->ShowWindow(SW_HIDE);
msj->EnableWindow(false);
msxuehao->ShowWindow(SW_HIDE);
mspassword->ShowWindow(SW_HIDE);
mxuehao->ShowWindow(SW_HIDE);
mpassword->ShowWindow(SW_HIDE);
mcl->ShowWindow(SW_SHOW);
mte->ShowWindow(SW_SHOW);
tagofhand=true;
CTaskKeyMgr::Disable(CTaskKeyMgr::TASKBAR,TRUE);
CTaskKeyMgr::Disable(CTaskKeyMgr::TASKKEYS,TRUE);
CTaskKeyMgr::Disable(CTaskKeyMgr::TASKMGR,TRUE);
::ShowWindow(m_hWnd,SW_SHOW);
m_trayIcon.SetIcon(0);
tagofuse=false;
ClipCursor(&rect);
}
else
return;
}
void CClientDlg::OnView()
{
/////////////查看上机情况/////////////////
if(tagofsj==0)
{
sockClient=socket(AF_INET,SOCK_STREAM,0);
addrSrv.sin_addr.S_un.S_addr=inet_addr("127.0.0.1");
addrSrv.sin_family =AF_INET;
addrSrv.sin_port=htons(6000);
int ret = connect(sockClient,(SOCKADDR*)&addrSrv,sizeof(SOCKADDR));
if(ret == SOCKET_ERROR)
{
MessageBox("网络连接失败,请稍后重试!","错误",MB_ICONERROR | MB_OK);
return ;
}
CString str;
str +="5";
str += char(glbxuehao.GetLength());
str += glbxuehao;
str += char(0);
char* buf = str.GetBuffer(0);
ret = send(sockClient, buf, str.GetLength(), 0);
if(ret!=str.GetLength())
{
MessageBox("网络连接失败,请稍后重试!","错误",MB_ICONERROR|MB_OK);
return ;
}
char buff[5];
ret = recv(sockClient, buff, 5, 0);
if(ret == 0)
{
MessageBox("网络连接失败,请稍后重试!","错误",MB_ICONERROR|MB_OK);
return ;
}
buff[ret] = '\0';
CString mtime=currenttime.Format("%#H时%#M分%#S秒");////////////////////上机时刻
int itime=atoi(buff);
int ih,im;
ih=itime/60;
im=itime%60;
CString *pmsg,*ptime;
pmsg=new CString;
ptime=new CString;
ptime->Format("%d小时%d分",ih,im);
pmsg->Format("你于%s上机,卡上还剩%s",mtime,*ptime);
MessageBox(*pmsg,"自由上机",MB_OK|MB_ICONINFORMATION);
delete pmsg,ptime;
}
else if(tagofsj==1)
{ CString *pmsg=new CString;
CString mtime=currenttime.Format("%#H时%#M分%#S秒");
pmsg->Format("你于%s上机",mtime);
MessageBox(*pmsg,"教学上机",MB_OK|MB_ICONINFORMATION);
delete pmsg;
}
else if(tagofsj==2)
{
CString *pmsg=new CString;
CString mtime=currenttime.Format("%#H时%#M分%#S秒");
pmsg->Format("您于%s上机",mtime);
MessageBox(*pmsg,"教师上机",MB_OK|MB_ICONINFORMATION);
delete pmsg;
}
}
void CClientDlg::OnChangePwd()
{
/////////////更改密码/////////////////
if(tagofsj==0)
{
CChangePwdDlg dlg;
dlg.DoModal();
}
else
MessageBox("非自由上机!","提醒",MB_OK|MB_ICONINFORMATION);
}
void CClientDlg::OnAbout()
{
CAboutDlg dlg;
dlg.DoModal();
}
void CClientDlg::OnTimer(UINT nIDEvent)
{
/////////////////负责关机////////////////
if(!tagofuse)
{
glbshutdown();
}
CDialog::OnTimer(nIDEvent);
}
void CClientDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
m_Width=cx;
m_Height=cy;
Invalidate();
}
void CClientDlg::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
///////////////测试时用的,以后要删除////////////////////
CTaskKeyMgr::Disable(CTaskKeyMgr::ALL, FALSE);
SendMessage(WM_CLOSE);
exit(0);
CDialog::OnLButtonDblClk(nFlags, point);
}
void CClientDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
ClipCursor(&rect);
if(tagofhand)
{
CEdit *mEdit = (CEdit*)GetDlgItem(IDC_XUEHAO);
mEdit->SetFocus();
HBITMAP hBitmap;
CWnd *pWndsj=GetDlgItem(IDC_PICSJ);
pWndsj->GetWindowRect(&rectsj);
CWnd *pWndcl=GetDlgItem(IDC_PICCL);
pWndcl->GetWindowRect(&rectcl);
CWnd *pWndte=GetDlgItem(IDC_PICTE);
pWndte->GetWindowRect(&rectte);
if(rectsj.PtInRect(point)||rectte.PtInRect(point)||rectcl.PtInRect(point))
tagofmouse=true;
else
tagofmouse=false;
if(rectsj.PtInRect(point))//////////////鼠标移到上机处
{
if(tsi2)
{
hBitmap = ::LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_SJ2));
m_sj.SetBitmap(hBitmap);
tsi2=false;
tsi1=true;
}
}
else
{
if(tsi1)
{
hBitmap = ::LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_SJ1));
m_sj.SetBitmap(hBitmap);
tsi1=false;
tsi2=true;
}
}
if(rectte.PtInRect(point))//////////////鼠标移到上机处
{
if(tte2)
{
hBitmap = ::LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_TE2));
m_te.SetBitmap(hBitmap);
tte1=true;
tte2=false;
}
}
else
if(tte1)
{
hBitmap = ::LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_TE1));
m_te.SetBitmap(hBitmap);
tte1=false;
tte2=true;
}
if(rectcl.PtInRect(point))//////////////
{
if(tcl2)
{
hBitmap = ::LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_CL2));
m_cl.SetBitmap(hBitmap);
tcl1=true;
tcl2=false;
}
}
else
{
if(tcl1)
{
hBitmap = ::LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_CL1));
m_cl.SetBitmap(hBitmap);
tcl1=false;
tcl2=true;
}
}
}
else
tagofmouse=false;
CDialog::OnMouseMove(nFlags, point);
}
BOOL CClientDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
if(tagofmouse)
{ //int i=MAKEINTRESOURCE(32649);
::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_HAND));
return TRUE;
}
return CDialog::OnSetCursor(pWnd, nHitTest, message);
}
void CClientDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(tagofhand)
{
CWnd *pWndsj=GetDlgItem(IDC_PICSJ);
pWndsj->GetWindowRect(&rectsj);
CWnd *pWndcl=GetDlgItem(IDC_PICCL);
pWndcl->GetWindowRect(&rectcl);
CWnd *pWndte=GetDlgItem(IDC_PICTE);
pWndte->GetWindowRect(&rectte);
if(rectsj.PtInRect(point))
{
////////////显示输入框/隐藏图片//////////
HBITMAP hBitmap = ::LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_PICNOTICE));
m_sj.SetBitmap(hBitmap);
CStatic *mcl = (CStatic*)GetDlgItem(IDC_PICCL);
CStatic *mte = (CStatic*)GetDlgItem(IDC_PICTE);
CStatic *msxuehao=(CStatic*)GetDlgItem(IDC_SXUEHAO);
CStatic *mspassword = (CStatic*)GetDlgItem(IDC_SPASSWORD);
CStatic *mxuehao = (CStatic*)GetDlgItem(IDC_XUEHAO);
CStatic *mpassword = (CStatic*)GetDlgItem(IDC_PASSWORD);
CStatic *msj = (CStatic*)GetDlgItem(IDC_SJ);
//CStatic *mzy = (CStatic*)GetDlgItem(IDC_ZY);
// CStatic *mchoose = (CStatic*)GetDlgItem(IDC_CHOOSE);
mcl->ShowWindow(false);
msj->EnableWindow(true);
//mcl->EnableWindow(0);
mte->ShowWindow(SW_HIDE);
msxuehao->ShowWindow(SW_SHOW);
mspassword->ShowWindow(SW_SHOW);
mxuehao->ShowWindow(SW_SHOW);
mpassword->ShowWindow(SW_SHOW);
// msj->ShowWindow(SW_SHOW);
tagofhand=false;
}
else if(rectte.PtInRect(point))//////////////按下鼠标在教师上机处
{
tagofhand=false;
OnTeacher();
tagofhand=false;
}
else if(rectcl.PtInRect(point))//////////////按下鼠标在教学上机处
{
tagofhand=false;
OnClass();
tagofhand=false;
//MessageBox("test","test",MB_OK);
//tagofhand=false;
}
}
else
{
CStatic *mcl = (CStatic*)GetDlgItem(IDC_PICCL);
CStatic *mte = (CStatic*)GetDlgItem(IDC_PICTE);
CStatic *msxuehao=(CStatic*)GetDlgItem(IDC_SXUEHAO);
CStatic *mspassword = (CStatic*)GetDlgItem(IDC_SPASSWORD);
CStatic *mxuehao = (CStatic*)GetDlgItem(IDC_XUEHAO);
CStatic *mpassword = (CStatic*)GetDlgItem(IDC_PASSWORD);
CStatic *msj = (CStatic*)GetDlgItem(IDC_SJ);
// CStatic *mzy = (CStatic*)GetDlgItem(IDC_ZY);
msj->ShowWindow(SW_HIDE);
msj->EnableWindow(false);
msxuehao->ShowWindow(SW_HIDE);
mspassword->ShowWindow(SW_HIDE);
mxuehao->ShowWindow(SW_HIDE);
mpassword->ShowWindow(SW_HIDE);
mcl->ShowWindow(SW_SHOW);
mte->ShowWindow(SW_SHOW);
tagofhand=true;
}
CDialog::OnLButtonUp(nFlags, point);
}
void CClientDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
//
if(nChar == VK_RETURN)
MessageBox("altdown","test",MB_OK);
CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CClientDlg::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
if(nChar == VK_RETURN)
MessageBox("altdown","test",MB_OK);
CDialog::OnChar(nChar, nRepCnt, nFlags);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -