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

📄 securechatdlg.cpp

📁 提供加密的c/s 聊天程序。用到对称加密算法和非对称加密算法
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CSecureChatDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CSecureChatDlg::OnOK() 
{
	// TODO: Add extra validation here

}

void CSecureChatDlg::OnSimplelibtest() 
{

	AfxBeginThread(CSecureChatDlg::ThreadWrapperLibTestDemo, (void*)this,
		THREAD_PRIORITY_NORMAL);
}

void CSecureChatDlg::OnRsatest() 
{
	UpdateData();
	m_iKeyByteSize=m_iKeyLength;
 AfxBeginThread(CSecureChatDlg::ThreadWrapperRSAdemo, (void*)this,
		THREAD_PRIORITY_NORMAL);

}

void CSecureChatDlg::OnDhtest() 
{
	UpdateData();
	m_iKeyByteSize=m_iKeyLength;
	AfxBeginThread(CSecureChatDlg::ThreadWrapperDHdemo, (void*)this,
		THREAD_PRIORITY_NORMAL);	
	
}

void CSecureChatDlg::OnGeneratekey() 
{
	UpdateData();
	m_iKeyByteSize=m_iKeyLength;
	if ( m_RandomDlg.DoModal()==IDOK )
	{
	  AfxBeginThread(CSecureChatDlg::ThreadWrapperDSAdemo, (void*)this,
		THREAD_PRIORITY_NORMAL);
	}
}


UINT CSecureChatDlg::ThreadWrapperRSAdemo(LPVOID pParam)
{
	CSecureChatDlg* pThis=NULL;
	pThis = reinterpret_cast<CSecureChatDlg*>(pParam);
	if(pThis)
	{
		pThis->PerformRSATest();
	
	}
	return 0;
}


UINT CSecureChatDlg::ThreadWrapperDHdemo(LPVOID pParam)
{
	CSecureChatDlg* pThis=NULL;
	pThis = reinterpret_cast<CSecureChatDlg*>(pParam);
	if(pThis)
	{
		pThis->PerformDHTest();
		
	}
	return 0;
}

UINT CSecureChatDlg::ThreadWrapperDSAdemo(LPVOID pParam)
{
	CSecureChatDlg* pThis=NULL;
	pThis = reinterpret_cast<CSecureChatDlg*>(pParam);
	if(pThis)
	{
		pThis->PerformDSATest();
		
	}
	return 0;
}

UINT CSecureChatDlg::ThreadWrapperLibTestDemo(LPVOID pParam)
{
	CSecureChatDlg* pThis=NULL;
	pThis = reinterpret_cast<CSecureChatDlg*>(pParam);
	if(pThis)
	{
		pThis->PerformSimpleLibTest();
		
	}
	return 0;
}


void CSecureChatDlg::PerformRSATest()
{
	m_cProcessLock.Lock();
	m_cLogg.Clear();
	MyCryptLib c;
	c.DemoRSA(&m_cLogg,m_iKeyByteSize);
	m_cProcessLock.Unlock();
	
}

void CSecureChatDlg::PerformSimpleLibTest()
{
	m_cProcessLock.Lock();
	m_cLogg.Clear();
	MyCryptLib c;
	c.DemoSimpleTest(&m_cLogg);
	m_cProcessLock.Unlock();
	
}

void CSecureChatDlg::PerformDSATest()
{
	m_cProcessLock.Lock();
	m_cLogg.Clear();
	MyCryptLib c;
	c.DemoDSA(&m_cLogg,	m_iKeyByteSize,m_RandomDlg.m_raw_pool,_POOL_SIZE_);
	m_cProcessLock.Unlock();
}


void CSecureChatDlg::PerformDHTest()
{
	m_cProcessLock.Lock();
	m_cLogg.Clear();
	MyCryptLib c;
	c.DemoDiffieHellman(&m_cLogg,m_iKeyByteSize);
	m_cProcessLock.Unlock();	
}

void CSecureChatDlg::OnSelchangeToptap(NMHDR* pNMHDR, LRESULT* pResult) 
{
	SetDemoMode(m_cTab.GetCurFocus()==1);	
	*pResult = 0;
}

void CSecureChatDlg::OnStartstopserver() 
{
	UpdateData(TRUE);
	if(m_iocp.IsStarted())
	{
		m_cStartStopBtn.SetWindowText("Start");
		StopTheServer();
		m_cUserList.EnableWindow(FALSE);
	}else
	{
		m_cStartStopBtn.SetWindowText("Stop");
		StartTheServer();
		m_cUserList.EnableWindow();
	}	
}

void CSecureChatDlg::OnClickUserlist(NMHDR* pNMHDR, LRESULT* pResult) 
{
	ITEMINFO* pItem=NULL;
	
	pItem=m_cUserList.GetSelectedItem();
	
	if ( pItem!=NULL) 
	{ 
		m_iCurrenClientID=pItem->m_ID;
		m_cBtnDisconnect.EnableWindow();

	
	}else
	{
		//m_iCurrentClientID=0;
		int SItem=m_cUserList.GetNextItem(-1,LVNI_SELECTED);
		if ( SItem!=-1 )
			m_cUserList.SetItemState(SItem,LVNI_ALL, LVIF_TEXT | LVIF_IMAGE | LVIF_STATE);
		
		m_cBtnDisconnect.EnableWindow(FALSE);
	}
	*pResult = 0;
}

void CSecureChatDlg::OnDisconnect() 
{
	
	if ( m_iCurrenClientID>0 )
	{
		
		UpdateData(TRUE);
		m_iocp.DisconnectClient(m_iCurrenClientID);
		
		// Deselect The selected Item in the other list.
		int SItem=m_cUserList.GetNextItem(-1,LVNI_SELECTED);
		if ( SItem!=-1 )
		{
			m_cUserList.SetItemState(SItem,LVNI_ALL, LVIF_TEXT | LVIF_IMAGE | LVIF_STATE);
		}
		m_cUserList.SetFocus();
		m_cBtnDisconnect.EnableWindow(FALSE);
		
	}

	
}

void CSecureChatDlg::OnDisconnectall() 
{
	UpdateData(TRUE);
	m_iocp.DisconnectAll();	
	// Deselect The selected Item in the other list.
	int SItem=m_cUserList.GetNextItem(-1,LVNI_SELECTED);
	if ( SItem!=-1 )
		m_cUserList.SetItemState(SItem,LVNI_ALL, LVIF_TEXT | LVIF_IMAGE | LVIF_STATE);
	m_cUserList.SetFocus();
}

void CSecureChatDlg::OnSendtxt() 
{
	UpdateData(TRUE);
	m_iocp.SendTextMessage(m_sMessage);
}

void CSecureChatDlg::OnClearlog() 
{
	m_cLogg.Clear();
}


/*
 * Used to Update the content in the Userlist with an interval of 	
 * 500 ms. 
 *
 */

void CSecureChatDlg::UpdateList()
{

	ClientContext *pContext=NULL;
	ITEMINFO* pItem=NULL;
	BOOL bStatusChanged=FALSE;

	// m_cUserList.SetFocus();	
	// Select all of the items that are completely visible.
	int n = m_cUserList.GetTopIndex();
	int nLast = min((n + m_cUserList.GetCountPerPage()+1),m_cUserList.GetItemCount()) ; // To also get partial stuff.  
	for (;n < nLast;n++)
	{
		
		pItem=(ITEMINFO*)m_cUserList.GetItemData(n);
		if(pItem!=NULL)
		{
		  	m_iocp.m_ContextMapLock.Lock();
			pContext=NULL;
			pContext=m_iocp.m_ContextMap[pItem->m_ID];
			if ( pContext!=NULL && pContext->m_bUpdateList )
			{
				pContext->m_bUpdateList=FALSE;
				pItem->m_sName=pContext->m_sUsername;
				m_cUserList.Update(n);
				TRACE("%i (%i) \r\n",n,pItem->m_ID);
			}
			m_iocp.m_ContextMapLock.Unlock();
		} 	
	}	
}



void CSecureChatDlg::OnTimer(UINT nIDEvent) 
{
	UpdateList();
	CDialog::OnTimer(nIDEvent);
}

void CSecureChatDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	KillTimer(m_ihTimer);
	m_iocp.m_StatusLock.Lock();
	m_iocp.m_hWnd=NULL;
	m_iocp.m_StatusLock.Unlock();
}


void CSecureChatDlg::OnChangeNrofio() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

void CSecureChatDlg::OnChangeMaxconnect() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

void CSecureChatDlg::OnChangePortnr() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

void CSecureChatDlg::OnChangeAddress() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

void CSecureChatDlg::OnChangeKeysize() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

⌨️ 快捷键说明

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