⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ncsynsimulaclientprocesswnd.cpp

📁 用VC++开发了一个数控加工的三维仿真程序
💻 CPP
字号:
// NCSynSimulaClientProcessWnd.cpp : 实现文件
//

#include "stdafx.h"
#include "MainFrm.h"
#include "NCSynSimulaSocket.h"
#include "NCMessage.h"
#include "NCSimulaSys.h"
#include "NCSimulaSysView.h"
#include "NCSynSimulaClientProcessWnd.h"


// CNCSynSimulaClientProcessWnd

IMPLEMENT_DYNAMIC(CNCSynSimulaClientProcessWnd, CFrameWnd)

CNCSynSimulaClientProcessWnd::CNCSynSimulaClientProcessWnd(CMainFrame* p)
{
	pMainWnd = p;
}

CNCSynSimulaClientProcessWnd::~CNCSynSimulaClientProcessWnd()
{
}


BEGIN_MESSAGE_MAP(CNCSynSimulaClientProcessWnd, CFrameWnd)
END_MESSAGE_MAP()



// CNCSynSimulaClientProcessWnd 消息处理程序



void CNCSynSimulaClientProcessWnd::OnReceive(CNCSynSimulaSocket* pSocket, CNCMessage& msg)
{
	CString strMsg = msg.m_strMessage;
	if(strMsg == _T("SYNSIMULASERVER-LOGOUT-SUCCESSFUL"))
	{
		theApp.m_Socket_SynSimula->CloseSocket();
		delete theApp.m_Socket_SynSimula;
		theApp.m_Socket_SynSimula = NULL;
		pMainWnd->m_wndTaskPane.m_wndGridCtrl_SynSimulaServer_ClientList.RemoveAll();
		// 此句是为了更新在线客户端列表,让其清空.
		pMainWnd->m_wndTaskPane.m_wndGridCtrl_SynSimulaServer_ClientList.Sort(0);
		pMainWnd->m_wndTaskPane.m_wndGridCtrl_SynSimulaServer_ClientList.SetReadOnly(false);
	}
	if(strMsg == _T("SYNSIMULASERVER-CLOSE"))
	{
		theApp.m_Socket_SynSimula->CloseSocket();
		delete theApp.m_Socket_SynSimula;
		theApp.m_Socket_SynSimula = NULL;
		pMainWnd->m_wndTaskPane.m_wndGridCtrl_SynSimulaServer_ClientList.RemoveAll();
		pMainWnd->m_wndTaskPane.m_wndGridCtrl_SynSimulaServer_ClientList.SetReadOnly(false);
		AfxMessageBox(_T("远程同步仿真服务器被关闭,被迫注销."));
	}
	if(strMsg == _T("SYNSIMULASERVER-CLOSE-LOGOUT-FORCED"))
	{
		theApp.m_Socket_SynSimula->CloseSocket();
		delete theApp.m_Socket_SynSimula;
		theApp.m_Socket_SynSimula = NULL;
		pMainWnd->m_wndTaskPane.m_wndGridCtrl_SynSimulaServer_ClientList.RemoveAll();
		pMainWnd->m_wndTaskPane.m_wndGridCtrl_SynSimulaServer_ClientList.SetReadOnly(false);
		AfxMessageBox(_T("远程同步仿真服务器强迫注销."));
	}
	if(strMsg.Left(18) == _T("LIST-CLIENT-ONLINE"))
	{
		CString strClientList = strMsg.Right(strMsg.GetLength() - 19);
		CArray<CString, CString>m_ArrayStrUserName;
		CArray<CString, CString>m_ArrayStrTag;

		// 分割字符串.
		for(;;)
		{
			int iPos_1 = 0;
			int iPos_2 = 0;
			if(strClientList.Find('|') != -1)
			{
				CString strSplit;
				iPos_1 = strClientList.Find('|');
				strSplit = strClientList.Left(iPos_1);
				strClientList = strClientList.Right(strClientList.GetLength() - iPos_1 -1);

				CString strUserName,strTag;
				iPos_2 = strSplit.Find('*');
				strUserName = strSplit.Left(iPos_2);
				strTag = strSplit.Right(strSplit.GetLength() - iPos_2 - 1);
				m_ArrayStrUserName.Add(strUserName);
				m_ArrayStrTag.Add(strTag); 
			}
			else
			{
				CString strUserName,strTag;
				iPos_2 = strClientList.Find('*');
				strUserName = strClientList.Left(iPos_2);
				strTag = strClientList.Right(strClientList.GetLength() - iPos_2 - 1);
				m_ArrayStrUserName.Add(strUserName);
				m_ArrayStrTag.Add(strTag); 
				break;
			}
		}
		
		// 更新在线客户端GridList控件中项目.
		int i;
		for(i=0;i<m_ArrayStrUserName.GetSize();i++)
		{
			// 检查是否存在,如果不存在则添加.
			bool bExist = false;
			for(int j=0;j<pMainWnd->m_wndTaskPane.m_wndGridCtrl_SynSimulaServer_ClientList.GetRowCount();j++)
			{
				if((CString)pMainWnd->m_wndTaskPane.m_wndGridCtrl_SynSimulaServer_ClientList.GetRow(j)->GetItem(1)->GetValue() == m_ArrayStrUserName[i])
				{
					bExist = true;
					break;
				}
			}
			if(!bExist)
			{
				CBCGPGridRow* pRow = pMainWnd->m_wndTaskPane.m_wndGridCtrl_SynSimulaServer_ClientList.CreateRow(pMainWnd->m_wndTaskPane.m_wndGridCtrl_SynSimulaServer_ClientList.GetColumnCount());	
				pRow->GetItem(0)->SetValue(_T(""));
				pRow->ReplaceItem(0, new CBCGPGridCheckItem (FALSE));
				pRow->GetItem(1)->SetValue((_variant_t)m_ArrayStrUserName[i]);
				pRow->GetItem(1)->AllowEdit(false);
				// 如果是0,表明这些客户端正在同步仿真中,暂时不可以邀请参加同步仿真.
				if(m_ArrayStrTag[i] == _T("0"))
				{
					pRow->GetItem(0)->AllowEdit(true);
					COLORREF color = RGB(255,0,0); 
					pRow->GetItem(0)->SetBackgroundColor(color);
					pRow->GetItem(1)->SetBackgroundColor(color);
				}
				if(m_ArrayStrTag[i] == _T("1"))
				{
					pRow->GetItem(0)->AllowEdit(false);
					COLORREF color = RGB(0,0,255); 
					pRow->GetItem(0)->SetBackgroundColor(color);
					pRow->GetItem(1)->SetBackgroundColor(color);
				}
				
				// 判断是否为当前客户端所使用的用户名,如果是则自动默认为同步仿真的一个客户端.
				if(m_ArrayStrUserName[i] == theApp.m_strNCClientUserID)
				{
					pRow->GetItem(0)->AllowEdit(false);
					pRow->GetItem(0)->SetValue(true);
					pRow->GetItem(0)->SetBackgroundColor(COLORREF(0xAAAAAA));
					pRow->GetItem(1)->SetBackgroundColor(COLORREF(0xAAAAAA));
				}

				pMainWnd->m_wndTaskPane.m_wndGridCtrl_SynSimulaServer_ClientList.AddRow(pRow);
			}
		}

		// 检查是否有项目应该被移除,如果有则移除.
		for(i=pMainWnd->m_wndTaskPane.m_wndGridCtrl_SynSimulaServer_ClientList.GetRowCount()-1;i>=0;i--)
		{
			bool bShouldDel = true;
			for(int j=0;j<m_ArrayStrUserName.GetSize();j++)
			{
				if((CString)pMainWnd->m_wndTaskPane.m_wndGridCtrl_SynSimulaServer_ClientList.GetRow(i)->GetItem(1)->GetValue() == m_ArrayStrUserName[j])
				{
					bShouldDel = false;
					break;
				}
			}
			if(bShouldDel)
			{
				pMainWnd->m_wndTaskPane.m_wndGridCtrl_SynSimulaServer_ClientList.RemoveRow(i);		
			}
		}
	}
	if(strMsg.Left(12) == _T("SYSI-INVITE-"))
	{
		// 分离信息.
		CString strMessage = strMsg.Right(strMsg.GetLength() - 12);
		CString strUserName_Trigger, strContent;

		int iPos;
		iPos = strMessage.Find('|');
		strUserName_Trigger = strMessage.Left(iPos);
		strContent = strMessage.Right(strMessage.GetLength() - iPos - 1);

		// 创建新窗口,并将接受到的NC代码显示在新窗口内.
		theApp.OnFileNew();
		CNCSimulaSysView* pView = (CNCSimulaSysView*)pMainWnd->GetActiveFrame()->GetActiveView();
		pView->GetEditCtrl()->SetWindowTextA(strContent);
	}
	if(strMsg == _T("SYSI-START"))
	{
		pMainWnd->SynSimulaProcess();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -