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

📄 wordlistdlg.cpp

📁 视频播放控制器程序
💻 CPP
字号:
// WordListDlg.cpp : implementation file
//

#include "stdafx.h"
#include "LiveController.h"
#include "WordListDlg.h"
#include "WordManage.h"


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

/////////////////////////////////////////////////////////////////////////////
// CWordListDlg dialog



CWordManage *myword = NULL; //原有文件词汇
CWordManage *pHead = NULL;  //原头指针
CWordManage *p=pHead;

CWordManage *pphead = NULL;    //新建头指针
CWordManage *Createword = NULL;//新建词汇文件
CWordManage *ppp=pphead;

BOOL NewFlag = FALSE; 
int ncount = 0;
CString AddedFileName;
int cccount;
BOOL Releaseflag = FALSE;


CWordListDlg::CWordListDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CWordListDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CWordListDlg)
	m_addword = _T("");
	//}}AFX_DATA_INIT
}

void CWordListDlg::ShowWrodList(CWordManage *ph)
{
	CString strTemp;
	LVITEM tempLvi;
	tempLvi.mask = LVIF_IMAGE | LVIF_TEXT;
	tempLvi.stateMask = -1;
	int nIndex=0;
	while (ph)
	{
		// word
		tempLvi.iItem = nIndex;
		tempLvi.iSubItem = 0;
		tempLvi.pszText = (char *)(LPCTSTR)(ph->word);
		m_ctrWordList.InsertItem(&tempLvi);

		// type
		tempLvi.iSubItem = 1;
		tempLvi.pszText = (char *)(LPCTSTR)(ph->type);
		m_ctrWordList.SetItem( &tempLvi );
		ph = ph->pNext;
		nIndex++;
	}
}


void CWordListDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CWordListDlg)
	DDX_Control(pDX, IDC_LIST_WordLIst, m_ctrWordList);
	DDX_Text(pDX, IDC_Word_ADD, m_addword);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CWordListDlg, CDialog)
	//{{AFX_MSG_MAP(CWordListDlg)
	ON_BN_CLICKED(IDC_BN_WordList_IMPORT, OnBNWordListIMPORT)
	ON_BN_CLICKED(IDC_BN_Word_ADD, OnBNWordADD)
	ON_BN_CLICKED(IDC_BN_Word_DEL, OnBNWordDEL)
	ON_NOTIFY(NM_CLICK, IDC_LIST_WordLIst, OnClickLISTWordLIst)
	ON_BN_CLICKED(IDC_BN_WordList_CREAT, OnBNWordListCREAT)
	ON_BN_CLICKED(IDC_BN_WordList_SAVE, OnBNWordListSAVE)
	ON_BN_CLICKED(IDC_BN_SAVE, OnBnSave)
	ON_BN_CLICKED(IDC_BN_AddIn, OnBNAddIn)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWordListDlg message handlers

BOOL CWordListDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	LVCOLUMN	lvcol;
	lvcol.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT;
	lvcol.fmt = LVCFMT_LEFT;
	lvcol.pszText = _T( "词汇" );
	lvcol.iSubItem = 1;
	m_ctrWordList.InsertColumn( 0, &lvcol );
	m_ctrWordList.SetColumnWidth( 0, 120);
	lvcol.pszText = _T( "类型" );
	m_ctrWordList.InsertColumn( 1, &lvcol );
	m_ctrWordList.SetColumnWidth( 1, 80 );


	
	DWORD dwStyle = m_ctrWordList.GetExtendedStyle();
	dwStyle |= LVS_EX_FULLROWSELECT;
	dwStyle |= LVS_EX_GRIDLINES;
    m_ctrWordList.SetExtendedStyle(dwStyle);

	nSelectDel = -1;
	GetDlgItem(IDC_BN_Word_DEL)->EnableWindow(FALSE);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CWordListDlg::OnBNWordListIMPORT() 
{
	
	if (pHead!=NULL)
	{
		CWordManage *temp=pHead;
		while (temp!=NULL)
		{
			pHead = temp->pNext;
			delete temp;
			temp = pHead;
		}
	}			
	
	m_ctrWordList.DeleteAllItems();
	static char BASED_CODE szFilter[] = "(*.ini)|*.ini||"; 
	CFileDialog filedlg(true,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter,NULL);
	CString temp;
	int i=0;

	if (filedlg.DoModal()==IDOK)
	{
		CString FileName;
		FileName = filedlg.GetPathName();
		FileName = Replacer(FileName);
		AddedFileName = FileName;
		myword = new CWordManage();
		myword->index = i;
		temp.Format("%d",myword->index);
		GetPrivateProfileString(temp,"word","Default",myword->word.GetBuffer(MAX_PATH),MAX_PATH,AddedFileName);
		GetPrivateProfileString(temp,"type","Default",myword->type.GetBuffer(MAX_PATH),MAX_PATH,AddedFileName);
		pHead = myword;
		p = myword;
		i++;
		for (p=pHead;p!=NULL;p=p->pNext)
		{
			myword = new CWordManage();
			myword->index = i;
			myword->pNext = NULL;
			temp.Format("%d",myword->index);
			GetPrivateProfileString(temp,"word","Default",myword->word.GetBuffer(MAX_PATH),MAX_PATH,AddedFileName);
			GetPrivateProfileString(temp,"type","Default",myword->type.GetBuffer(MAX_PATH),MAX_PATH,AddedFileName);
			if (myword->word == "Default")
			{
				delete myword;
				break;
			}
			p->pNext= myword;
			i++;
		}
		cccount = i;
		CWordManage *ptemp;
		ptemp = pHead;
		if (ptemp->word == "Default" && ptemp->type == "Default")
		{
			AfxMessageBox("文件内容为空!");
			m_ctrWordList.DeleteAllItems();
		}
		else
			ShowWrodList(ptemp);  //将文件内容显示在列表中
	}
	else
		return;
}

void CWordListDlg::OnBNWordADD() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if (NewFlag==TRUE )
	{
		if (pHead == NULL)
		{
			Releaseflag = TRUE;
		}
	/////////////////新建后pHead不为空,则释放pHead///////////////////////////////
		if (Releaseflag == FALSE && pHead != NULL)
		{
			CWordManage *temp=pHead;
			while (temp!=NULL)
			{
				pHead = temp->pNext;
				delete temp;
				temp = pHead;
			}
			Releaseflag = TRUE;
		}
	
	}


	CWordManage *newword;
	newword = new CWordManage();

	CString strTemp;
	LVITEM tempLvi;
	tempLvi.mask = LVIF_IMAGE | LVIF_TEXT;
	tempLvi.stateMask = -1;
	CString newtype="1";   //////////////////过滤词汇的类型
	if (m_addword.IsEmpty())
	{
		AfxMessageBox("用户不能为空,请重新填写!");
	}
	else
	{
		// word
		tempLvi.iItem = m_ctrWordList.GetItemCount();
		tempLvi.iSubItem = 0;
		tempLvi.pszText = (char *)(LPCTSTR)(m_addword);
		m_ctrWordList.InsertItem(&tempLvi);

		// type
		tempLvi.iSubItem = 1;
		tempLvi.pszText = (char *)(LPCTSTR)(newtype);
		m_ctrWordList.SetItem( &tempLvi );



		if (NewFlag==TRUE && pHead == NULL)
		{
		
			if (ncount==0)
			{
				pHead = newword;
				p = newword;
				newword->index = ncount;
				newword->word = m_addword;
				newword->type = newtype;
				newword->pNext = NULL;
				ncount++;
			}
			else
			{
				newword->index = ncount;
				newword->word = m_addword;
				newword->type = newtype;
				newword->pNext = NULL;
				p->pNext = newword;
				p = p->pNext;
				ncount++;
			}
	
		}
		else
		{
			newword->index = cccount;
			newword->word = m_addword;
			newword->pNext = NULL;
			newword->type = "1";
			p->pNext = newword;
			p = p->pNext;
			cccount++;
		}

	}

	m_addword.Empty();
	UpdateData(FALSE);	

}

void CWordListDlg::OnBNWordDEL() 
{
	// TODO: Add your control notification handler code here
	
	CWordManage *temp = pHead;
	if (nSelectDel==0)
	{
		CWordManage *pSave = pHead;
		pHead = pHead->pNext;
		delete pSave;
	}
	else
	{
		for (int i=1;temp->pNext!=NULL;i++)
		{
			if (i==nSelectDel)
			{
				CWordManage *pdelete = temp->pNext;
				temp->pNext= temp->pNext->pNext;
				delete pdelete;
				break;
			}
			else
				temp = temp->pNext;
		}

	}



	m_ctrWordList.DeleteAllItems();////////////////清空列表

	CWordManage *ptemp;
	ptemp = pHead;
	ShowWrodList(ptemp); ///////////////////////////重新显示
 
}

void CWordListDlg::OnClickLISTWordLIst(NMHDR* pNMHDR, LRESULT* pResult) 
{
	LPNMITEMACTIVATE pNmitem = (LPNMITEMACTIVATE)pNMHDR;
	UINT uFlags;
	nSelectDel = m_ctrWordList.HitTest( CPoint(pNmitem->ptAction), &uFlags );
	if ( nSelectDel < 0 )
	{
		GetDlgItem(IDC_BN_Word_DEL)->EnableWindow(FALSE);	
		*pResult = 0;
		return;
	}
	
	GetDlgItem(IDC_BN_Word_DEL)->EnableWindow(TRUE);
}

void CWordListDlg::OnBNWordListCREAT() 
{
	// TODO: Add your control notification handler code here

	NewFlag = TRUE;
	m_ctrWordList.DeleteAllItems();

	CFileDialog dlg(FALSE, "ini",NULL,OFN_OVERWRITEPROMPT|OFN_HIDEREADONLY,
   "文本文件(*.ini)|*.ini||", this);
	dlg.m_ofn.lpstrTitle = _T("保存过滤词汇文件");

	CString fileName;
	if (dlg.DoModal() == IDOK)
	{
		// 实现存盘
		fileName = dlg.GetPathName();
		fileName =Replacer(fileName);
		AddedFileName=fileName;
	

		CFile file(fileName, CFile::modeCreate|CFile::modeReadWrite|CFile::shareExclusive);
		CArchive ar(&file, CArchive::store|CArchive::bNoFlushOnDelete);
		ar.Close();		
		file.Close();
	}
	else
		return;
}

void CWordListDlg::OnBNWordListSAVE() 
{
	// TODO: Add your control notification handler code here
}

void CWordListDlg::OnBnSave() 
{
	// TODO: Add your control notification handler code here
	////////////////////将列表中的值加入进链表//////////////////
	int i=0;
	Createword = new CWordManage();
	Createword->index = i;
	Createword->word = m_ctrWordList.GetItemText(i,0);
	Createword->type = m_ctrWordList.GetItemText(i,1);
	pphead = Createword;
	ppp = Createword;
	i++;
	for (ppp=pphead;ppp!=NULL;ppp=ppp->pNext)
	{
		Createword = new CWordManage();
		Createword->index = i;
		Createword->pNext = NULL;
		Createword->word = m_ctrWordList.GetItemText(i,0);
		Createword->type = m_ctrWordList.GetItemText(i,1);
		if (i==m_ctrWordList.GetItemCount())
		{
			delete Createword;
			break;
		}
		ppp->pNext= Createword;
		i++;
	}
	////////////////////////////////////////////////////////////////////


	CFile file;
	file.Open(AddedFileName,CFile::modeCreate|CFile::modeWrite);   
	file.Close();


	int j =0;
	CWordManage *tt=pphead;
	while (tt)
	{
		tt->index = j;
		CString tmp;
		tmp.Format("%d",tt->index);
		WritePrivateProfileString(tmp,"word",tt->word,AddedFileName);
		WritePrivateProfileString(tmp,"type",tt->type,AddedFileName);
		tt = tt->pNext;
		j++;
	}

	///////////////将整个链表释放掉/////////////////////////////////////////
	if (pHead!=NULL)
	{
		CWordManage *temp=pHead;
		while (temp!=NULL)
		{
			pHead = temp->pNext;
			delete temp;
			temp = pHead;
		}
	}
	////////////////////////////////////////////////////////////////////////

	AfxMessageBox("文件保存成功!");
}

void CWordListDlg::OnBNAddIn() 
{
	// TODO: Add your control notification handler code here
	
	CWordManage *head = NULL;//导入文件的头指针
	CWordManage *q = head;   //功能如p
	CString temp;
	static char BASED_CODE szFilter[] = "(*.ini)|*.ini||"; 
	CFileDialog filedlg(true,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter,NULL);
	int i = 0;
	if (filedlg.DoModal()==IDOK)
	{
		CString FileName;
		FileName = filedlg.GetPathName();
		FileName = Replacer(FileName);

		myword = new CWordManage();
		myword->index = i;
		temp.Format("%d",myword->index);
		GetPrivateProfileString(temp,"word","Default",myword->word.GetBuffer(MAX_PATH),MAX_PATH,FileName);
		GetPrivateProfileString(temp,"type","Default",myword->type.GetBuffer(MAX_PATH),MAX_PATH,FileName);

		head = myword;
		q = myword;
		i++;
		for (q=head;q!=NULL;q=q->pNext)
		{
			myword = new CWordManage();
			myword->index = i;
			myword->pNext = NULL;
			temp.Format("%d",myword->index);
			GetPrivateProfileString(temp,"word","Default",myword->word.GetBuffer(MAX_PATH),MAX_PATH,FileName);
			GetPrivateProfileString(temp,"type","Default",myword->type.GetBuffer(MAX_PATH),MAX_PATH,FileName);
			if (myword->word == "Default")
			{
				delete myword;
				break;
			}
			q->pNext = myword;
			i++;
		}
		if (pHead == NULL)
		{
			pHead = head;
			p = q;
		}
		else
		{
			p->pNext = head;//导入与原有连接起来
			p = q;
		}	
		m_ctrWordList.DeleteAllItems();
		CWordManage *ptemp;
		ptemp = pHead;
		if (ptemp->word == "Default" && ptemp->type == "Default")
		{
			AfxMessageBox("文件内容为空!");
			m_ctrWordList.DeleteAllItems();
		}
		else
			ShowWrodList(ptemp);  //将文件内容显示在列表中
	}
	else
		return;
}

⌨️ 快捷键说明

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