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

📄 setwrite.cpp

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

#include "stdafx.h"
#include "LiveController.h"
#include "SetWrite.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSetWrite dialog
CNameManage *wHead = NULL;  //总的头指针
CNameManage *wt=wHead;  
CNameManage *WhiteName;  
int Nwcount = 0;
int Cwcount;

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

void CSetWrite::ShowWhiteName(CNameManage *ph)
{
	CString strTemp;
	LVITEM tempLvi;
	tempLvi.mask = LVIF_IMAGE | LVIF_TEXT;
	tempLvi.stateMask = -1;
	int nIndex=0;
	while (ph)
	{
		// name
		tempLvi.iItem = nIndex;
		tempLvi.iSubItem = 0;
		tempLvi.pszText = (char *)(LPCTSTR)(ph->name);
		m_ctrSetWhiteList.InsertItem(&tempLvi);

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


void CSetWrite::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSetWrite)
	DDX_Control(pDX, IDC_WriteList, m_ctrSetWhiteList);
	DDX_Text(pDX, IDC_addWhiteName, m_addWhiteName);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSetWrite, CDialog)
	//{{AFX_MSG_MAP(CSetWrite)
	ON_BN_CLICKED(IDC_BN_ImportWrite, OnBNImportWrite)
	ON_BN_CLICKED(IDC_BN_ADDWrite, OnBNADDWrite)
	ON_BN_CLICKED(IDC_BN_DEL, OnBnDel)
	ON_NOTIFY(NM_CLICK, IDC_WriteList, OnClickWriteList)
	ON_BN_CLICKED(IDC_BN_InUse, OnBNInUse)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSetWrite message handlers

void CSetWrite::OnBNImportWrite() 
{
	// TODO: Add your control notification handler code here
	CNameManage *head = NULL;	//导入文件的头指针
	CNameManage *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);

		WhiteName = new CNameManage();
		WhiteName->index = i;
		temp.Format("%d",WhiteName->index);
		GetPrivateProfileString(temp,"name","Default",WhiteName->name.GetBuffer(MAX_PATH),MAX_PATH,FileName);
		GetPrivateProfileString(temp,"type","Default",WhiteName->type.GetBuffer(MAX_PATH),MAX_PATH,FileName);

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

BOOL CSetWrite::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( "用户ID" );
	lvcol.iSubItem = 1;
	m_ctrSetWhiteList.InsertColumn( 0, &lvcol );
	m_ctrSetWhiteList.SetColumnWidth( 0, 120);
	lvcol.pszText = _T( "类型" );
	m_ctrSetWhiteList.InsertColumn( 1, &lvcol );
	m_ctrSetWhiteList.SetColumnWidth( 1, 90 );

//   nSelect=-1;
//	GetDlgItem(IDC_BN_Name_DEL)->EnableWindow(FALSE);
	
	DWORD dwStyle = m_ctrSetWhiteList.GetExtendedStyle();
	dwStyle |= LVS_EX_FULLROWSELECT;
	dwStyle |= LVS_EX_GRIDLINES;
    m_ctrSetWhiteList.SetExtendedStyle(dwStyle);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CSetWrite::OnBNADDWrite() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	CNameManage *newname;
	newname = new CNameManage();
	Cwcount = m_ctrSetWhiteList.GetItemCount();

	CString strTemp;
	LVITEM tempLvi;
	tempLvi.mask = LVIF_IMAGE | LVIF_TEXT;
	tempLvi.stateMask = -1;
	CString newtype="1";   //////////////////黑名单类型
	if (m_addWhiteName.IsEmpty())
	{
		AfxMessageBox("用户不能为空,请重新填写!");
	}
	else
	{
		// name
		tempLvi.iItem = m_ctrSetWhiteList.GetItemCount();
		tempLvi.iSubItem = 0;
		tempLvi.pszText = (char *)(LPCTSTR)(m_addWhiteName);
		m_ctrSetWhiteList.InsertItem(&tempLvi);

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



		if ( wHead == NULL)
		{
		
			if (Cwcount==0)
			{
				wHead = newname;
				wt = newname;
				newname->index = Nwcount;
				newname->name = m_addWhiteName;
				newname->type = newtype;
				newname->pNext = NULL;
				Nwcount++;
			}
			else
			{
				newname->index = Nwcount;
				newname->name = m_addWhiteName;
				newname->type = newtype;
				newname->pNext = NULL;
				wt->pNext = newname;
				wt = wt->pNext;
				Nwcount++;
			}
	
		}
		else
		{
			newname->index = Cwcount;
			newname->name = m_addWhiteName;
			newname->pNext = NULL;
			newname->type = newtype;
			wt->pNext = newname;
			wt = wt->pNext;
			Cwcount++;
		}

	}
	m_addWhiteName.Empty();
	UpdateData(FALSE);	
}

void CSetWrite::OnBnDel() 
{
	// TODO: Add your control notification handler code here
	CNameManage *temp = wHead;
	if (wnSelect==0)
	{
		CNameManage *pSave = wHead;
		wHead = wHead->pNext;
		delete pSave;
	}
	else
	{
		for (int i=1;temp->pNext!=NULL;i++)
		{
			if (i==wnSelect)
			{
				CNameManage *pdelete = temp->pNext;
				temp->pNext= temp->pNext->pNext;
				delete pdelete;
				break;
			}
			else
				temp = temp->pNext;
		}

	}

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

	CNameManage *ptemp;
	ptemp = wHead;
	ShowWhiteName(ptemp); ///////////////////////////重新显示
}

void CSetWrite::OnClickWriteList(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	LPNMITEMACTIVATE pNmitem = (LPNMITEMACTIVATE)pNMHDR;
	UINT uFlags;
	wnSelect= m_ctrSetWhiteList.HitTest( CPoint(pNmitem->ptAction), &uFlags );
	if ( wnSelect < 0 )
	{
		GetDlgItem(IDC_BN_DEL)->EnableWindow(FALSE);	
		*pResult = 0;
		return;
	}
	
	GetDlgItem(IDC_BN_DEL)->EnableWindow(TRUE);
	*pResult = 0;
}

void CSetWrite::OnBNInUse() 
{
	// TODO: Add your control notification handler code here
	m_pSetWhiteName_H = wHead;
	m_pSetWhiteName_T= wt;

	wHead = NULL;
	wt = NULL;
	CDialog::EndDialog(IDC_BN_InUse);
}

⌨️ 快捷键说明

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