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

📄 formchathist.cpp

📁 本人买的<<VC++项目开发实例>>源代码配套光盘.
💻 CPP
字号:
// FormChatHist.cpp : implementation file
//

#include "stdafx.h"
#include "netmsg.h"
#include "FormChatHist.h"

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

/////////////////////////////////////////////////////////////////////////////
// CFormChatHist dialog


//##ModelId=3E361E25010B
CFormChatHist::CFormChatHist(CWnd* pParent /*=NULL*/)
	: CDialog(CFormChatHist::IDD, pParent)
{
	//{{AFX_DATA_INIT(CFormChatHist)
	m_strMsg = _T("");
	//}}AFX_DATA_INIT
}


//##ModelId=3E361E250129
void CFormChatHist::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFormChatHist)
	DDX_Control(pDX, IDC_LIST_MSG, m_listMsg);
	DDX_Control(pDX, IDC_LIST_FRIENDS, m_listFriends);
	DDX_Text(pDX, IDC_EDIT_MSG, m_strMsg);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CFormChatHist, CDialog)
	//{{AFX_MSG_MAP(CFormChatHist)
	ON_BN_CLICKED(IDC_CLOSE, OnClose)
	ON_LBN_SELCHANGE(IDC_LIST_FRIENDS, OnSelchangeListFriends)
	ON_LBN_SELCHANGE(IDC_LIST_MSG, OnSelchangeListMsg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFormChatHist message handlers

//##ModelId=3E361E250183
void CFormChatHist::OnOK() 
{	
	//CDialog::OnOK();
}

//##ModelId=3E361E25018E
void CFormChatHist::OnCancel() 
{
	TRACE("OnCancel(). \n");
	//CDialog::OnCancel();
}

//##ModelId=3E361E250170
void CFormChatHist::PostNcDestroy() 
{	
	CDialog::PostNcDestroy();
	delete this;
}

//##ModelId=3E361E250198
void CFormChatHist::OnClose() 
{
	this->DestroyWindow();	
}

//##ModelId=3E361E2501A2
BOOL CFormChatHist::OnInitDialog() 
{
	extern CNetMsgApp theApp;

	CDialog::OnInitDialog();
	//加入朋友们聊天的文件
	TCHAR lpszOldPath[MAX_PATH];	
	::GetCurrentDirectory(MAX_PATH, lpszOldPath);
	::SetCurrentDirectory(theApp.get_WorkDIR() + "Chat\\");
	
	m_listFriends.ResetContent();
	m_listFriends.Dir(DDL_READWRITE, _T("*.*"));
	
	::SetCurrentDirectory(lpszOldPath);


	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

//##ModelId=3E396ED1007F
void CFormChatHist::OnSelchangeListFriends()
{	
	extern CNetMsgApp theApp;
	TRACE("OnSelchangeListFriends()\n");
	//0. 确认选择的有效性。
	int nIndex = m_listFriends.GetCurSel();
	if (nIndex != LB_ERR)
	{
		//1. 取得文件名字
		CString strItem;
		m_listFriends.GetText(nIndex, strItem);
		CString strFileName = theApp.get_WorkDIR() + "Chat\\" + strItem;
		//2. 读出文件内容
		try
		{
			CStdioFile file(strFileName, CFile::modeRead | CFile::shareDenyNone | CFile::typeText);
			CString strLine;
			m_listMsg.ResetContent();	//clear the listbox
			while (file.ReadString(strLine))
			{
				m_listMsg.AddString(strLine);
			}
		}
		catch(CFileException &e)
		{
			e.ReportError();		
		}
		//3. 显示到ListBox中
		
	}
}

//##ModelId=3E396ED1008A
void CFormChatHist::OnSelchangeListMsg() 
{
	m_strMsg = "";
	int nIndex = m_listMsg.GetCurSel();
	if (nIndex != LB_ERR)
	{
		m_listMsg.GetText(nIndex, m_strMsg);
	}
	
	UpdateData(FALSE);
}

⌨️ 快捷键说明

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