📄 channeldlg.cpp
字号:
// ChannelDlg.cpp : implementation file
//
#include "stdafx.h"
#include <stdlib.h>
#include <string.h>
#include "XmlEncapsulate.h"
#include "XMLGENERATE.h"
#include "ChannelDlg.h"
#include "ProgramDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern HANDLE b;
extern char DigNameTag[DIGITAL_PROGRAM_ARRY_LENGTH][MAX_LENGTH]; // digital name array
/////////////////////////////////////////////////////////////////////////////
// CChannelDlg dialog
CChannelDlg::CChannelDlg(CWnd* pParent /*=NULL*/)
: CDialog(CChannelDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CChannelDlg)
m_strType = _T("");
//}}AFX_DATA_INIT
}
void CChannelDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CChannelDlg)
DDX_Control(pDX, IDC_LIST_CHANNEL, m_listChannel);
DDX_Control(pDX, IDC_COMBO_TYPE, m_ctrType);
DDX_Control(pDX, IDC_BUTTON_Program, m_bntProgram);
DDX_CBString(pDX, IDC_COMBO_TYPE, m_strType);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CChannelDlg, CDialog)
//{{AFX_MSG_MAP(CChannelDlg)
ON_BN_CLICKED(IDC_BUTTON_Program, OnBUTTONProgram)
ON_CBN_SELCHANGE(IDC_COMBO_TYPE, OnSelchangeComboType)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_VALIDATE, OnEndLabelEditVariableCriteria)
ON_MESSAGE(WM_SET_ITEMS, PopulateComboList)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChannelDlg message handlers
BOOL CChannelDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
// Initialization of the combo boxes
// Type combo box
m_ctrType.AddString("全部");
m_ctrType.AddString("电视类型");
m_ctrType.AddString("广播类型");
// Initialization of the list box
m_listChannel.InsertColumn(0,"Channel Tag");
m_listChannel.InsertColumn(1,"Channel Name");
m_listChannel.InsertColumn(2,"Service Type");
m_listChannel.InsertColumn(3,"Sound Value");
m_listChannel.SetColumnWidth(0,100);
m_listChannel.SetColumnWidth(1,160);
m_listChannel.SetColumnWidth(2,100);
m_listChannel.SetColumnWidth(3,100);
m_listChannel.SetReadOnlyColumns(0); // read only
m_listChannel.SetReadOnlyColumns(2);
// Set the rule of modification
CString strValidChars;
strValidChars = "";
m_listChannel.SetColumnValidEditCtrlCharacters(strValidChars,1);//none control edit
m_listChannel.SetComboColumns(3,TRUE);
m_listChannel.EnableVScroll();
m_listChannel.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
// Set the button and text box status
m_ctrType.SetCurSel(0);
m_bntProgram.EnableWindow(TRUE);
RefreshData();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CChannelDlg::OnBUTTONProgram()
{
// TODO: Add your control notification handler code here
int index = m_listChannel.GetSelectionMark();
if( index < 0 )
{
MessageBox("请选择一条记录");
return ;
}
CString tag = m_listChannel.GetItemText( index, 0 );
CString name = m_listChannel.GetItemText( index, 1 );
CProgramDlg Dlg;
Dlg.m_ChanName = name;
Dlg.m_ChanTag = tag;
if( -1 == Dlg.DoModal() )
{
return ;
}
}
void CChannelDlg::OnSelchangeComboType()
{
// TODO: Add your control notification handler code here
RefreshData();
}
void CChannelDlg::RefreshData()
{
m_listChannel.DeleteAllItems();
m_listChannel.SetRedraw(FALSE);
UpdateData(TRUE);
int index = m_ctrType.GetCurSel();
m_ctrType.GetLBText(index, m_strType);
int maxlen, maxlen1, maxlen2;
int type;
char temp[2];
XmlGETi( b, "F_Video_Type", "totalNum", &maxlen1 );
XmlGETi( b, "F_Broadcast_Type", "totalNum", &maxlen2 );
if( m_strType == "电视类型" )
{
type = Video_Type;
maxlen = maxlen1;
}
else if( m_strType == "广播类型" )
{
type = Broadcast_Type;
maxlen = maxlen2;
}
else
{
maxlen = maxlen1 + maxlen2;
for( int i = 0; i < maxlen; i++ )
{
DIGITAL_PGROGRAM DigChan;
char Sname[SERVEICE_NAME_LENGTH];
XmlGETDigChan( b, DigNameTag[i], &DigChan );
XmlGETs( b, DigNameTag[i], "cServiceName", Sname, SERVEICE_NAME_LENGTH );
m_listChannel.InsertItem( LVIF_TEXT|LVIF_STATE, i, DigNameTag[i],
LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED, 0, 0 );
m_listChannel.SetItemText( i, 1, Sname );
char* typena =
( ( DigChan.ucServiceType - '0' ) == 0 ) ? "广播频道" : "电视频道";
m_listChannel.SetItemText( i, 2, typena );
_itoa( ( DigChan.ucSoundValue - '0' ), temp, 10 );
m_listChannel.SetItemText( i, 3, temp );
}
m_listChannel.SetRedraw(TRUE);
return ;
}
int* DigAdd = ( int* ) malloc ( maxlen * sizeof( int ) );
XmlGETFastList( b, DigAdd, maxlen, type );
for( int i = 0; i < maxlen; i++ )
{
DIGITAL_PGROGRAM DigChan;
char Sname[SERVEICE_NAME_LENGTH];
XmlGETDigChan( b, DigNameTag[DigAdd[i] - 1], &DigChan );
XmlGETs( b, DigNameTag[DigAdd[i] - 1], "cServiceName", Sname, SERVEICE_NAME_LENGTH );
m_listChannel.InsertItem( i, DigNameTag[DigAdd[i] - 1] );
m_listChannel.SetItemText( i, 1, Sname );
char* typena =
( ( DigChan.ucServiceType - '0' ) == 0 ) ? "广播频道" : "电视频道";
m_listChannel.SetItemText( i, 2, typena );
_itoa( ( DigChan.ucSoundValue - '0' ), temp, 10 );
m_listChannel.SetItemText( i, 3, temp );
}
free(DigAdd);
m_listChannel.SetRedraw(TRUE);
}
LRESULT CChannelDlg::OnEndLabelEditVariableCriteria(WPARAM wParam, LPARAM lParam)
{
LV_DISPINFO* pDispInfo = (LV_DISPINFO*)lParam;
// TODO: Add your control notification handler code here
int index = pDispInfo->item.iItem;
CString tag = m_listChannel.GetItemText( index, 0 );
CString change = m_listChannel.GetItemText( index, pDispInfo->item.iSubItem );
if( change.GetLength() > SERVEICE_NAME_LENGTH )
{
MessageBox( "请输入少于22个字符" );
RefreshData();
return 0;
}
if( pDispInfo->item.iSubItem == 1 )
{
char cname[SERVEICE_NAME_LENGTH];
strcpy( cname, (LPCTSTR)change );
XmlMODs( b, (LPCTSTR)tag, "cServiceName", cname );
}
else if( pDispInfo->item.iSubItem == 3 )
{
char cflag;
strcpy( &cflag, (LPCTSTR)change );
XmlMODi( b, (LPCTSTR)tag, "ucSoundValue", cflag );
}
else
{
RefreshData();
return 0;
}
XmlWriteFile( b );
return 1;
}
LRESULT CChannelDlg::PopulateComboList(WPARAM wParam, LPARAM lParam)
{
// Get the Combobox window pointer
CComboBox* pInPlaceCombo = static_cast<CComboBox*> (GetFocus());
// Get the inplace combbox top left
CRect obWindowRect;
pInPlaceCombo->GetWindowRect(&obWindowRect);
CPoint obInPlaceComboTopLeft(obWindowRect.TopLeft());
// Get the active list
// Get the control window rect
// If the inplace combobox top left is in the rect then
// The control is the active control
m_listChannel.GetWindowRect(&obWindowRect);
int iColIndex = ( int )wParam;
CString index;
CStringList* pComboList = reinterpret_cast<CStringList*>(lParam);
pComboList->RemoveAll();
if (obWindowRect.PtInRect(obInPlaceComboTopLeft))
{
if(iColIndex == 3)
{
for( int i = 0; i < 64; i++ )
{
index.Format("%d", i);
pComboList->AddTail(index);
}
}
}
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -