📄 testdlg.cpp
字号:
// testDlg.cpp : implementation file
//
#include "stdafx.h"
#include "test.h"
#include "testDlg.h"
#include "BakList.h"
#include "ChanList.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestDlg dialog
CTestDlg::CTestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTestDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_hEpg = NULL;
m_pepgmsgproc = NULL;
bDay = TRUE;
}
void CTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTestDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
//{{AFX_MSG_MAP(CTestDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_COPY_CHAN, OnCopyChan)
ON_LBN_SELCHANGE(IDC_SEL_CHAN, OnSelchangeSelChan)
ON_COMMAND_RANGE(IDC_CUR_DAY, IDC_CUR_EPG, DealCommandRange)
ON_COMMAND_RANGE(IDC_PREV_CHAN, IDC_NEXT_CHAN, DealCommandChanUpDown)
ON_COMMAND_RANGE(IDC_EXPORT_CHAN, IDC_INPORT_CHAN, DealCommandExInport)
ON_BN_CLICKED(IDC_FAV, OnFav)
ON_BN_CLICKED(IDC_CHAN_EDIT, OnChanEdit)
ON_LBN_SELCHANGE(IDC_LIB_CHAN, OnSelcancelLibChan)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestDlg message handlers
BOOL CTestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
CString s;
#ifdef _DEBUG
s = "tmepgd.dll";
#else
s = "tmepg.dll";
#endif
m_hEpg = LoadLibrary(s);
if(m_hEpg)
m_pepgmsgproc =(MsgCallbackProc) GetProcAddress(m_hEpg, "MsgProc");
DealEpg(WM_MSG_EPG, MAKELONG(0, WM_MSG_INIT), 0, 0);
FillLibChan();
FillCurChan();
CButton *pbwnd = (CButton *)GetDlgItem(IDC_CUR_EPG);
if(bDay)
{
pbwnd =(CButton *) GetDlgItem(IDC_CUR_DAY);
}
pbwnd ->SetCheck(TRUE);
//
FillCurChanEpg(IDC_SEL_CHAN);
return TRUE; // return TRUE unless you set the focus to a control
}
void CTestDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CTestDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CTestDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
LRESULT CTestDlg::DealEpg(UINT msg, UINT nID, WPARAM wParam, LPARAM lParam)
{
if(m_pepgmsgproc)
return m_pepgmsgproc(msg, nID, wParam, lParam);
return 0L;
}
void CTestDlg::OnDestroy()
{
DealEpg(WM_MSG_EPG, MAKELONG(0, WM_MSG_SHUT), 0, 0);
CDialog::OnDestroy();
// TODO: Add your message handler code here
}
void CTestDlg::FillCurChan()
{
CListBox *plbwnd = (CListBox *)GetDlgItem(IDC_SEL_CHAN);
CButton *pbtwnd = (CButton *)GetDlgItem(IDC_FAV);
BOOL bFav = FALSE;
if(pbtwnd->GetCheck())
bFav = TRUE;
plbwnd->ResetContent();
LPChancel pchan;
LONG lret, ln;
ln = 0;
lret = DealEpg(WM_MSG_EPG, MAKELONG(WM_CHAN_LIST, WM_EPG_GET)
,(WPARAM) bFav, (LPARAM )&pchan);
CString s;
for(int i= 0; i< lret; i++)
{
s.Format("%s,%s", pchan[i].szName, pchan[i].tvFName);
plbwnd->AddString(s);
}
if(lret>0)
plbwnd->SetCurSel(0);
}
void CTestDlg::FillLibChan()
{
CListBox *plbwnd = (CListBox *)GetDlgItem(IDC_LIB_CHAN);
plbwnd->ResetContent();
LPChancel pchan;
LONG lret, ln;
ln = 0;
lret = DealEpg(WM_MSG_EPG, MAKELONG(WM_CHAN_LIST_LIB, WM_EPG_GET)
,(WPARAM) &ln, (LPARAM )&pchan);
CString s;
for(int i= 0; i< ln; i++)
{
s.Format("%s,%s", pchan[i].szName, pchan[i].tvFName);
plbwnd->AddString(s);
}
}
void CTestDlg::FillCurChanEpg(int nID)
{
CListBox *plbwnd = (CListBox *)GetDlgItem(nID);
LPEpgInfo pepg;
Chancel chan;
ZeroMemory(&chan, sizeof(Chancel));
LONG lret, ln;
CString s;
ln = 0;
WORD wcmd;
if(bDay)
wcmd = WM_EPG_CUR_DAY;
else
wcmd = WM_EPG_CUR;
chan.m_nNum = plbwnd->GetCurSel();
s.Empty();
plbwnd->GetText(chan.m_nNum, s);
ln = s.Find(',');
if(ln>=0)
s = s.Right(s.GetLength() - ln -1);
strcpy(chan.tvFName, s.LockBuffer());
lret = DealEpg(WM_MSG_EPG, MAKELONG(wcmd, WM_EPG_GET)
,(WPARAM) &chan, (LPARAM )&pepg);
plbwnd = (CListBox *)GetDlgItem(IDC_EPG_LIST);
plbwnd->ResetContent();
for(int i= 0; i< lret; i++)
{
CTime t(pepg[i].startTime);
s = t.Format("%Y-%m-%d %H:%M:%S");
s += pepg[i].szprogname;
plbwnd->AddString(s);
}
}
void CTestDlg::OnCopyChan()
{
// TODO: Add your control notification handler code here
}
void CTestDlg::OnSelchangeSelChan()
{
// TODO: Add your control notification handler code here
nID = IDC_SEL_CHAN;
FillCurChanEpg(IDC_SEL_CHAN);
}
void CTestDlg::DealCommandRange(UINT nID)
{
switch(nID)
{
case IDC_CUR_EPG:
bDay = FALSE;
break;
case IDC_CUR_DAY:
bDay = TRUE;
break;
}
FillCurChanEpg(nID);
}
void CTestDlg::DealCommandChanUpDown(UINT nID)
{
CListBox *plbpwnd = (CListBox*)GetDlgItem(IDC_SEL_CHAN);
int ncnt, nsel;
ncnt = plbpwnd->GetCount();
nsel = plbpwnd->GetCurSel();
switch(nID)
{
case IDC_PREV_CHAN:
nsel --;
if(nsel == -1)
nsel = ncnt -1;
break;
case IDC_NEXT_CHAN:
nsel ++;
nsel %= ncnt;
break;
}
plbpwnd->SetCurSel(nsel);
FillCurChanEpg(IDC_SEL_CHAN);
}
void CTestDlg::OnFav()
{
// TODO: Add your control notification handler code here
FillCurChan();
}
void CTestDlg::DealCommandExInport(UINT nID)
{
CBakList dlg;
int n;
switch(nID)
{
case IDC_EXPORT_CHAN:
DealEpg(WM_MSG_EPG, MAKELONG(WM_BAK_CUR, WM_EPG_DONE), 0, 0);
break;
case IDC_INPORT_CHAN:
dlg.m_pfn = m_pepgmsgproc;
if(dlg.DoModal() == IDOK)
{
n = DealEpg(WM_MSG_EPG, MAKELONG(WM_REVSER_CHAN, WM_EPG_DONE), 1, dlg.nsel);
FillCurChan();
}
break;
}
}
void CTestDlg::OnChanEdit()
{
// TODO: Add your control notification handler code here
CChanList dlg;
dlg.m_pfn = m_pepgmsgproc;
dlg.DoModal();
FillCurChan();
FillLibChan();
}
void CTestDlg::OnSelcancelLibChan()
{
// TODO: Add your control notification handler code here
nID = IDC_LIB_CHAN;
FillCurChanEpg(IDC_LIB_CHAN);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -