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

📄 simmsnmessengerview.cpp

📁 网络编程
💻 CPP
字号:
// SimMsnMessengerView.cpp : implementation of the CSimMsnMessengerView class
//

#include "stdafx.h"
#include "SimMsnMessenger.h"

#include "SimMsnMessengerDoc.h"
#include "SimMsnMessengerView.h"
 
extern int igLogTimes ;
extern int igConnectTimes ;
extern int igRecvBytes ;
extern int igSendBytes ;
extern char  agCurDir[];
extern time_t	timeBegin;


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSimMsnMessengerView

IMPLEMENT_DYNCREATE(CSimMsnMessengerView, CHtmlView)

BEGIN_MESSAGE_MAP(CSimMsnMessengerView, CHtmlView)
	//{{AFX_MSG_MAP(CSimMsnMessengerView)
	ON_COMMAND(ID_CONNECT, OnConnect)
	ON_COMMAND(ID_LOCK, OnLock)
	ON_COMMAND(ID_DISCONNECT, OnDisconnect)
	ON_COMMAND(ID_DISP_LOG, OnDispLog)
	ON_MESSAGE(WM_MY_MESSAGE,OnMyMessage)
	ON_COMMAND(ID_TEST_FUNS, OnTestFuns)
	ON_WM_TIMER()
	ON_COMMAND(ID_DISP_MainPage, OnDISPMainPage)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSimMsnMessengerView construction/destruction

CSimMsnMessengerView::CSimMsnMessengerView()
{
	// TODO: add construction code here
	m_iClientType=0;  // 0=irc; 1=msn; 2=...
	m_strUser=_T("[IRC_9988]");
	m_strPwd=_T("IRC_9988");
	m_strServer=_T("211.167.73.23");
	m_iServerPort=6667;
	m_iClientDeleted[0]=1;
	m_iClientDeleted[1]=1;
	memset(agCurDir,0x00,1023);
	GetCurrentDirectory(1023,agCurDir);
	//GetModuleFileName来获得应用程序的路径,不过这个函数将连同执行文件名一起返回
}

CSimMsnMessengerView::~CSimMsnMessengerView()
{
}

BOOL CSimMsnMessengerView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CHtmlView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CSimMsnMessengerView drawing

void CSimMsnMessengerView::OnDraw(CDC* pDC)
{
	CSimMsnMessengerDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

void CSimMsnMessengerView::OnInitialUpdate()
{
	CHtmlView::OnInitialUpdate();

	// TODO: This code navigates to a popular spot on the web.
	//  change the code to go where you'd like.
	//Navigate2(_T("http://www.google.com/"),NULL,NULL);
		CString strDispFile;
	strDispFile.Format("file://%s\\html\\main02.htm",agCurDir);
	//FileLog("strDispFile URL=[%s]",(LPCTSTR)strDispFile);
	Navigate2(strDispFile,NULL,NULL);
	 
}

/////////////////////////////////////////////////////////////////////////////
// CSimMsnMessengerView diagnostics

#ifdef _DEBUG
void CSimMsnMessengerView::AssertValid() const
{
	CHtmlView::AssertValid();
}

void CSimMsnMessengerView::Dump(CDumpContext& dc) const
{
	CHtmlView::Dump(dc);
}

CSimMsnMessengerDoc* CSimMsnMessengerView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSimMsnMessengerDoc)));
	return (CSimMsnMessengerDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CSimMsnMessengerView message handlers

void CSimMsnMessengerView::OnConnect() 
{
	// TODO: Add your command handler code here
		//build a client
	FileLog("View::OnConnect m_iClientType=(%d), 0=irc; 1=msn; 2=...",m_iClientType); 
	if( m_iClientType==0 ) // 0=irc; 1=msn; 2=...
	{
	 
	}
	else if( m_iClientType==1 ) // 0=irc; 1=msn; 2=...
	{
		if( m_iClientDeleted[1]!=1  ) delete m_pMsnLoginClient;
		
		{
			igConnectTimes++;
			igLogTimes++;
			m_pMsnLoginClient = new CMsnLoginClient;
			if( m_pMsnLoginClient == NULL )
			{
				//something is wrong here
				FileLog("View::OnConnect,m_pMsnLoginClient == NULL "); 
				return ;
				
			}
			m_iClientDeleted[1]=0;
			
			m_pMsnLoginClient->m_strMyNickName = m_strUser;
			m_pMsnLoginClient->m_strPassword = m_strPwd;
			m_pMsnLoginClient->m_strServerName = m_strServer;
		 	m_pMsnLoginClient->Init();
			SetTimer(1,120000,NULL); 
			
		}
	}
}



void CSimMsnMessengerView::OnLock() 
{
	// TODO: Add your command handler code here
	CString strDispFile;
	strDispFile.Format("file://%s\\html\\main02.htm",agCurDir);
	//FileLog("strDispFile URL=[%s]",(LPCTSTR)strDispFile);
	Navigate2(strDispFile,NULL,NULL);
	 
}

void CSimMsnMessengerView::OnDisconnect() 
{
	
	if( m_iClientDeleted[0]!=1 )
	{	
 
		m_iClientDeleted[0] =1 ;
	}
	if( m_iClientDeleted[1]!=1 )
	{	
		delete m_pMsnLoginClient;
		m_iClientDeleted[1] =1 ;
	}
	OnLock() ;
	// TODO: Add your command handler code here


}

void CSimMsnMessengerView::OnBeforeNavigate2(LPCTSTR lpszURL, DWORD nFlags, LPCTSTR lpszTargetFrameName, CByteArray& baPostedData, LPCTSTR lpszHeaders, BOOL* pbCancel) 
{
	// TODO: Add your specialized code here and/or call the base class
	//FileLog("OnBeforeNavigate2(%s,%d,%s,%s)",lpszURL, nFlags,lpszTargetFrameName, lpszHeaders ) ;
	
	//FileLog("OnBeforeNavigate2[%s]",baPostedData.GetData());
	
	if( strcmp(lpszURL,"http://sim.msnmessenger.com.cn/login.asp") == 0)
	{ 
		//char alFldName[100];
		char alFldValue[1000];
		int ilRet;
   

		memset( alFldValue,0x00,sizeof(alFldValue));
		ilRet= GetValueByName(baPostedData.GetData(),baPostedData.GetSize(),"USER",alFldValue);
		FileLog("Get USER=[%s]",alFldValue);
		m_strUser.Format("%s",alFldValue);

		memset( alFldValue,0x00,sizeof(alFldValue));
		ilRet= GetValueByName(baPostedData.GetData(),baPostedData.GetSize(),"PWD",alFldValue);
		m_strPwd.Format("%s",alFldValue);
		FileLog("Get PWD=[%s]",alFldValue);

		memset( alFldValue,0x00,sizeof(alFldValue));
		ilRet= GetValueByName(baPostedData.GetData(),baPostedData.GetSize(),"SERVER",alFldValue);
		FileLog("Get SERVER=[%s]",alFldValue);
		if( memcmp(alFldValue,"MSN:",4)==0 ) m_iClientType=1;  // 0=irc; 1=msn; 2=...
		else if( memcmp(alFldValue,"IRC:",4)==0 ) m_iClientType=0;  // 0=irc; 1=msn; 2=...
		
		unsigned int i = 0;
		for( i=4; i<strlen(alFldValue);i++)
		{
			if(alFldValue[i]==':') break;
		}
		alFldValue[i]=0x00;

		m_strServer.Format("%s",alFldValue+4);
	
		*pbCancel=TRUE;
		OnConnect();
 
	}
	else if( strcmp(lpszURL,"http://sim.msnmessenger.com.cn/Status.asp") == 0)
	{ 
		//char alFldName[100];
		char alFldValue[1000];
		int ilRet;
   

		memset( alFldValue,0x00,sizeof(alFldValue));
		ilRet= GetValueByName(baPostedData.GetData(),baPostedData.GetSize(),"Nick",alFldValue);
		FileLog("Get Nick=[%s]",alFldValue);
		
		*pbCancel=TRUE;

		if ( m_iClientDeleted[1]==0)
		{
				m_pMsnLoginClient->m_strNick.Format("%s",alFldValue);
				m_pMsnLoginClient->DoUserInput("REA", -1 );
		}
 
	}
	else if( strncmp(lpszURL,"http://sim.msnmessenger.com.cn/OpenUser.asp",43) == 0)
	{ 
		//char alFldName[100];
		char alFldValue[1000];
	 
		memset( alFldValue,0x00,sizeof(alFldValue));
		memcpy(alFldValue,lpszURL+51,strlen(lpszURL)-51);
		FileLog("Get UserNo=[%s]",alFldValue);
		
		*pbCancel=TRUE;


		if ( m_iClientDeleted[1]==0)
		{
			 m_pMsnLoginClient->DoUserInput("OpenUser", atoi(alFldValue) );
		}
	 
	}
	else if( strcmp(lpszURL,"http://sim.msnmessenger.com.cn/UserInput.asp") == 0)
	{ 
		//char alFldName[100];
		char alFldValue[1000], alFldValue2[100];;
		int ilRet;
		memset( alFldValue,0x00,sizeof(alFldValue));
		ilRet= GetValueByName(baPostedData.GetData(),baPostedData.GetSize(),"InputMsg",alFldValue);
		FileLog("Get InputMsg=[%s]",alFldValue);
	
		memset( alFldValue2,0x00,sizeof(alFldValue2));
		ilRet= GetValueByName(baPostedData.GetData(),baPostedData.GetSize(),"UserNo",alFldValue2);
		FileLog("Get UserNo=[%s]",alFldValue2);
		int ilUserNo= atoi(alFldValue2);
		*pbCancel=TRUE;


		if ( m_iClientDeleted[1]==0)
		{
			 m_pMsnLoginClient->m_MsnUser[ilUserNo]->UserInputMsg(alFldValue);
		}
	 
	}
	else if( strcmp(lpszURL,"http://sim.msnmessenger.com.cn/AddUser.asp") == 0)
	{ 
		//char alFldName[100];
		char alFldValue[1000], alFldValue2[100];;
		int ilRet;
		memset( alFldValue,0x00,sizeof(alFldValue));
		ilRet= GetValueByName(baPostedData.GetData(),baPostedData.GetSize(),"Mail",alFldValue);
		FileLog("Get Mail=[%s]",alFldValue);
	
		memset( alFldValue2,0x00,sizeof(alFldValue2));
		ilRet= GetValueByName(baPostedData.GetData(),baPostedData.GetSize(),"cmd",alFldValue2);
		FileLog("Get cmd=[%s]",alFldValue2);
		int ilUserNo= atoi(alFldValue2);
		*pbCancel=TRUE;
		
		if( memcmp( alFldValue2, "DirectTalk",10 ) == 0 )
		{
			if ( m_iClientDeleted[1]==0)
			{    //[LST xiaoi916@hotmail.com 小人 11 1]
				 CString strTmp;
				 strTmp.Format("LST %s %s  11 1",alFldValue,alFldValue);
				 m_pMsnLoginClient->DoLST(strTmp);
					 
			}
		}
		else if( memcmp( alFldValue2, "AddUser",7 ) == 0 )
		{
			if ( m_iClientDeleted[1]==0)
			{    //[LST xiaoi916@hotmail.com 小人 11 1]
				 CString strTmp;
				 strTmp.Format("AddUser %s",alFldValue );
			 	 m_pMsnLoginClient->DoUserInput((LPCTSTR)strTmp, 9999 );
			}
	
		}
		else	if( memcmp( alFldValue2, "DelUser",7 ) == 0 )
		{
			if ( m_iClientDeleted[1]==0)
			{    //[LST xiaoi916@hotmail.com 小人 11 1]
				 CString strTmp;
				 strTmp.Format("DelUser %s",alFldValue );
			 	 m_pMsnLoginClient->DoUserInput((LPCTSTR)strTmp, 9999 );
					 
			}
		}
	}
	else CHtmlView::OnBeforeNavigate2(lpszURL, nFlags,	lpszTargetFrameName, baPostedData, lpszHeaders, pbCancel);
}

void CSimMsnMessengerView::OnDispLog() 
{
	// TODO: Add your command handler code here
	CString strLogFile;
	strLogFile.Format("file://%s\\SimMsn_0.htm",agCurDir);
	//FileLog("strLogFile URL=[%s]",(LPCTSTR)strLogFile);
	Navigate2(strLogFile,NULL,NULL);
}

void CSimMsnMessengerView::OnNavigateComplete2(LPCTSTR strURL) 
{
	// TODO: Add your specialized code here and/or call the base class
	//FileLog("OnNavigateComplete2[%s]",strURL);
	
	CHtmlView::OnNavigateComplete2(strURL);
}

BOOL CSimMsnMessengerView::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	//FileLog("PreTranslateMessage[%d]",pMsg->message);

	if ((pMsg->message == WM_RBUTTONDOWN) ||(pMsg->message == WM_RBUTTONDBLCLK))
	{
		FileLog("PreTranslateMessage[%d]",pMsg->message);
		return TRUE;
	}
	else 
	return CHtmlView::PreTranslateMessage(pMsg);
}

LRESULT CSimMsnMessengerView::OnMyMessage(WPARAM wParam, LPARAM lParam)
{
	FileLog("CSimMsnMessengerView::OnMyMessage( %d, %ld )",wParam, lParam);

	if( lParam == 0 ) m_pMsnLoginClient->DoXFR();
	else if( lParam == 1 )
	{
		 
		CString strDispFile;
		strDispFile.Format("file://%s\\html\\MainPage_0.htm",agCurDir);
		FileLog("strDispFile URL=[%s]",(LPCTSTR)strDispFile);
		Navigate2(strDispFile,NULL,NULL);
	} 
	else if( lParam >= 100 )
	{
		 
		CString strDispFile;
		strDispFile.Format("file://%s\\html\\%ld_user_frm.htm",agCurDir,lParam-100);
		FileLog("strDispFile URL=[%s]",(LPCTSTR)strDispFile);
		Navigate2(strDispFile,NULL,NULL);
	}
	return 0;
}

void CSimMsnMessengerView::OnTestFuns() 
{
	// TODO: Add your command handler code here
	char alTmp1[1000];
	char alTmp2[1000];
	memset(alTmp1,0x00,sizeof(alTmp1));
	memset(alTmp2,0x00,sizeof(alTmp2));
    CMsnLoginClient pMsnLoginClient ;
	pMsnLoginClient.DoHTTPSAuthentication(alTmp1,alTmp2);
	
}

void CSimMsnMessengerView::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	 
	//SetTimer(1,1000,NULL); 
	if( m_iClientDeleted[1]==0 ) m_pMsnLoginClient->DoTimerPNG();
	else KillTimer(1);

	//1:计时器的名称; 1000:时间间隔,单位是毫秒,NULL:使用onTime函数
	//当不需要计时器的时候调用KillTimer(nIDEvent),例如:KillTimer(1);
	CHtmlView::OnTimer(nIDEvent);
}

void CSimMsnMessengerView::OnDISPMainPage() 
{
	// TODO: Add your command handler code here
	CString strLogFile;
	strLogFile.Format("file://%s\\html\\MainPage_0.htm",agCurDir);
	//FileLog("strLogFile URL=[%s]",(LPCTSTR)strLogFile);
	Navigate2(strLogFile,NULL,NULL);
}

⌨️ 快捷键说明

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