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

📄 chanlist.cpp

📁 得到本周内的电视节目预告! f
💻 CPP
字号:
// ChanList.cpp : implementation file
//

#include "stdafx.h"
#include "test.h"
#include "ChanList.h"

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

/////////////////////////////////////////////////////////////////////////////
// CChanList dialog
static LRESULT  WINAPI callbMsgProc(UINT msg, UINT nID, WPARAM wParam, LPARAM lParam);

CChanList *pchan = NULL;
CChanList::CChanList(CWnd* pParent /*=NULL*/)
	: CDialog(CChanList::IDD, pParent)
{
	//{{AFX_DATA_INIT(CChanList)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_pfn = NULL;
}


void CChanList::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CChanList)
	DDX_Control(pDX, IDC_CHAN_LIST, m_chanls);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CChanList, CDialog)
	//{{AFX_MSG_MAP(CChanList)
	ON_BN_CLICKED(IDC_SEARCH, OnSearch)
	ON_NOTIFY(LVN_ITEMCHANGED, IDC_CHAN_LIST, OnItemchangedChanList)
	ON_CBN_SELCHANGE(IDC_LIB_CHAN, OnSelchangeLibChan)
	ON_BN_CLICKED(IDC_SET_CHAN, OnSetChan)
	ON_BN_CLICKED(IDC_ADD_CHAN, OnAddChan)
	ON_BN_CLICKED(IDC_DEL_CHAN, OnDelChan)
	ON_BN_CLICKED(IDC_MOVE_UP, OnMoveUp)
	ON_BN_CLICKED(IDC_MOVE_DOWN, OnMoveDown)
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_OK, OnOk)
	ON_BN_CLICKED(IDC_CANCEL, OnCancel)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CChanList message handlers

BOOL CChanList::OnInitDialog() 
{
	CDialog::OnInitDialog();
	pchan = this;

	DealEpg(WM_MSG_EPG, MAKELONG(WM_DEFINE_CALLBACK, WM_EPG_SET), 0, (LPARAM)callbMsgProc);

	DWORD dwStytle	= m_chanls.GetExtendedStyle();
	dwStytle |= LVS_EX_FULLROWSELECT;
	dwStytle |= LVS_EX_FLATSB ;
	dwStytle |= LVS_EX_GRIDLINES;
	dwStytle |= LVS_EX_HEADERDRAGDROP;
	m_chanls.SetExtendedStyle(dwStytle);	

	// TODO: Add extra initialization here
	m_chanls.InsertColumn(0, "状态", LVCFMT_RIGHT, 50);
	m_chanls.InsertColumn(1, "名称", LVCFMT_RIGHT, 90);
	m_chanls.InsertColumn(2, "频率", LVCFMT_RIGHT, 70);
	m_chanls.InsertColumn(3, "编号", LVCFMT_RIGHT, 30);
	m_chanls.InsertColumn(4, "文件名", LVCFMT_RIGHT, 100);
	FillChanList();
	LibChanComm();
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
void CChanList::FillChanList()
{
	LPChancel pchan;
	LONG lret, ln;
	ln = 0;
	lret = DealEpg(WM_MSG_EPG, MAKELONG(WM_CHAN_LIST, WM_EPG_GET)
		,(WPARAM) 0, (LPARAM )&pchan);
	
	CString s;
	m_chanls.DeleteAllItems();
	for(int i= 0; i< lret; i++)
	{
		if(pchan[i].tvFav)
			m_chanls.InsertItem(i, "喜好");
		else
			m_chanls.InsertItem(i, "一般");
		m_chanls.SetItemText(i, 1, pchan[i].szName);
		s.Format("%ld", pchan[i].lfrequent);
		m_chanls.SetItemText(i, 2, s);
		s.Format("%d", pchan[i].m_nNum);
		m_chanls.SetItemText(i, 3, s);
		m_chanls.SetItemText(i, 4, pchan[i].tvFName);
	}
//	if(lret>0)
//		m_chanls.SetCurSel(0);

}
LRESULT CChanList::DealEpg(UINT msg, UINT nID, WPARAM wParam, LPARAM lParam)
{
	if(m_pfn)
		return m_pfn(msg, nID, wParam, lParam);
	return 0L;
}

void CChanList::OnSearch() 
{
	LPChancel pchan;
	LONG lret, ln;
	ln = 0;
	lret = DealEpg(WM_MSG_EPG, MAKELONG(WM_SEARCH_START, WM_EPG_DONE), 0, 0);
	lret = DealEpg(WM_MSG_EPG, MAKELONG(WM_REVSER_CHAN, WM_EPG_DONE), 1, 3);
	lret = DealEpg(WM_MSG_EPG, MAKELONG(WM_LIST_CHAN, WM_EPG_GET)
		,(WPARAM) 1, (LPARAM )&pchan);
	
	CString s;
	m_chanls.DeleteAllItems();
	for(int i= 0; i< lret; i++)
	{
		if(pchan[i].tvFav)
			m_chanls.InsertItem(i, "喜好");
		else
			m_chanls.InsertItem(i, "一般");
		m_chanls.SetItemText(i, 1, pchan[i].szName);
		s.Format("%ld", pchan[i].lfrequent);
		m_chanls.SetItemText(i, 2, s);
		s.Format("%d", i);
		m_chanls.SetItemText(i, 3, s);
	}
	//	if(lret>0)
	//		m_chanls.SetCurSel(0);
	//填充库中名称列表

}

void CChanList::OnItemchangedChanList(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
	// TODO: Add your control notification handler code here
	CString s;
	s = m_chanls.GetItemText(pNMListView->iItem, 3);
	
	//取得名称等内容
	s = m_chanls.GetItemText(pNMListView->iItem, 1);
	CWnd *pwnd = GetDlgItem(IDC_CHAN_NAME);
	pwnd ->SetWindowText(s);

	s = m_chanls.GetItemText(pNMListView->iItem, 4);
	pwnd = GetDlgItem(IDC_CHAN_FNAME);
	pwnd ->SetWindowText(s);
	
	s = m_chanls.GetItemText(pNMListView->iItem, 2);
	pwnd = GetDlgItem(IDC_FREQUEN);
	pwnd ->SetWindowText(s);

	CButton *pbwnd = (CButton *)GetDlgItem(IDC_FAV);
	s = m_chanls.GetItemText(pNMListView->iItem, 0);
	if(s.CompareNoCase("一般") == 0)
		pbwnd ->SetCheck(FALSE);
	else
		pbwnd ->SetCheck(TRUE);
	*pResult = 0;
}
void CChanList::LibChanComm()
{
	
	CString s;
	CComboBox *pcmbwnd = (CComboBox *)GetDlgItem(IDC_LIB_CHAN);

	VectorString *vec = NULL;
	DealEpg(WM_MSG_EPG, MAKELONG(WM_EPG_FILE, WM_EPG_GET)
		,0, (LPARAM )&vec);
	if(vec == NULL)
		return;
	int n = vec->size();
	for(int i= 0; i< n; i++)
	{
		pcmbwnd->AddString((*vec)[i].c_str());
	}
	if(n > 0)
		pcmbwnd->SetCurSel(0);
}

void CChanList::OnSelchangeLibChan() 
{
	// TODO: Add your control notification handler code here
	CComboBox *pcmbwnd = (CComboBox *)GetDlgItem(IDC_LIB_CHAN);
	CString s;

	int nsel = pcmbwnd->GetCurSel();

	pcmbwnd->GetLBText(nsel, s);

	CWnd *pwnd = GetDlgItem(IDC_CHAN_FNAME);
	pwnd ->SetWindowText(s);	
}

void CChanList::OnSetChan() 
{
	// TODO: Add your control notification handler code here
	Chancel chan;
	ZeroMemory(&chan ,sizeof(Chancel));
	GetChanInfo(&chan);
	chan.m_nNum = m_chanls.GetNextItem(-1, LVNI_SELECTED);
	
	long lRet;
//	strcpy(chan.tvFName, "01.txt");
	lRet = DealEpg(WM_MSG_EPG, MAKELONG(WM_CHAN_EDIT, WM_EPG_DONE), 0, (LPARAM)&chan);
	
	FillChanList();
}
void CChanList::GetChanInfo(LPChancel pchan)
{
	CString s;
	CWnd *pwnd = GetDlgItem(IDC_CHAN_NAME);
	pwnd->GetWindowText(s);
	strcpy(pchan->szName, s.LockBuffer());

	pwnd = GetDlgItem(IDC_FREQUEN);
	pwnd->GetWindowText(s);
	pchan->lfrequent = atol(s);

	CButton *pbwnd = (CButton *)GetDlgItem(IDC_FAV);
	pchan->tvFav = pbwnd->GetCheck();

	//取得频道对应的文件名信息
	pwnd = GetDlgItem(IDC_CHAN_FNAME);
	pwnd->GetWindowText(s);
	strcpy(pchan->tvFName, s.LockBuffer());

	pchan->RegCode = 1;
}

void CChanList::OnAddChan() 
{
	Chancel chan;
	ZeroMemory(&chan ,sizeof(Chancel));
	GetChanInfo(&chan);
	chan.m_nNum = m_chanls.GetItemCount();
	
	long lRet;
	lRet = DealEpg(WM_MSG_EPG, MAKELONG(WM_CHAN_ADD, WM_EPG_DONE), 0, (LPARAM)&chan);	
	
	FillChanList();
}

void CChanList::OnDelChan() 
{
	Chancel chan;
	ZeroMemory(&chan ,sizeof(Chancel));
	GetChanInfo(&chan);
	chan.m_nNum = m_chanls.GetNextItem(-1, LVNI_SELECTED);
	
	long lRet;
	lRet = DealEpg(WM_MSG_EPG, MAKELONG(WM_CHAN_DEL, WM_EPG_DONE), 0, (LPARAM)&chan);
	
	FillChanList();
}

void CChanList::OnMoveUp() 
{
	// TODO: Add your control notification handler code here
	Chancel chan;
	ZeroMemory(&chan ,sizeof(Chancel));
	GetChanInfo(&chan);
	chan.m_nNum = m_chanls.GetNextItem(-1, LVNI_SELECTED);
	
	long lRet;
	lRet = DealEpg(WM_MSG_EPG, MAKELONG(WM_CHAN_UP, WM_EPG_DONE), 0, (LPARAM)&chan);
	
	FillChanList();	
}

void CChanList::OnMoveDown() 
{
	// TODO: Add your control notification handler code here
	Chancel chan;
	ZeroMemory(&chan ,sizeof(Chancel));
	GetChanInfo(&chan);
	chan.m_nNum = m_chanls.GetNextItem(-1, LVNI_SELECTED);
	
	long lRet;
	lRet = DealEpg(WM_MSG_EPG, MAKELONG(WM_CHAN_DOWN, WM_EPG_DONE), 0, (LPARAM)&chan);
	
	FillChanList();
}

LRESULT WINAPI callbMsgProc(UINT msg, UINT nID, WPARAM wParam, LPARAM lParam)
{
	return pchan->MsgProc(msg, nID, wParam, lParam);
}

void CChanList::OnDestroy() 
{
	CDialog::OnDestroy();
	DealEpg(WM_MSG_EPG, MAKELONG(WM_DESOTRY_CALLBACK, WM_EPG_SET), 0, 0);	
	// TODO: Add your message handler code here
	pchan = NULL;
}
LRESULT CChanList::MsgProc(UINT msg, UINT nID, WPARAM wParam, LPARAM lParam)
{
	//
	AfxMessageBox("have receive messge");
	return 0l;
}

void CChanList::OnOk() 
{
	// TODO: Add your control notification handler code here
	DealEpg(WM_MSG_EPG, MAKELONG(WM_CHAN_UPDATE, WM_EPG_DONE), 0, 0);	
	CDialog::OnOK();
}

void CChanList::OnCancel() 
{
	// TODO: Add your control notification handler code here
	DealEpg(WM_MSG_EPG, MAKELONG(WM_CHAN_CANCEL, WM_EPG_DONE), 0, 0);	
	CDialog::OnCancel();
}

⌨️ 快捷键说明

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