// ViewLine.cpp : 实现文件 // #include "stdafx.h" #include "VoiceStation.h" #include "ViewLine.h" #include "Line.h" #include "DeviceMgr.h" #include "DisplayWnd.h" // CViewLine IMPLEMENT_DYNAMIC(CViewLine, CListCtrl) CViewLine::CViewLine(void) { } CViewLine::~CViewLine(void) { } /***************************************************************** **【函数名称】 __transType2String **【函数功能】 转换线路类型为字符串 **【参数】 **【返回值】 ****************************************************************/ LPCTSTR CViewLine::__transType2String( UINT Type ) { switch(Type) { case DEV_VS_TYPE_AUDIO: return _T("模拟放音"); case DEV_VS_TYPE_RECANA: return _T("模拟录音"); case DEV_VS_TYPE_RECDIG: return _T("数字录音"); case DEV_VS_TYPE_RECIPRR: return _T("IP录音"); default: return _T("未知类型"); } } /***************************************************************** **【函数名称】 __indexItem **【函数功能】 索引资源 **【参数】 **【返回值】 ****************************************************************/ int CViewLine::__indexItem( UINT ResId ) { int Count = GetItemCount(); for (int i=0; i < Count; ++i) { if (GetItemData(i) == ResId) return i; } return -1; } /***************************************************************** **【函数名称】 __addRes **【函数功能】 向List中添加资源 **【参数】 **【返回值】 ****************************************************************/ int CViewLine::__addRes( UINT ResId ) { int Index = GetItemCount(); CString strResID; strResID.Format(_T("%d"), ResId); Index = InsertItem(Index, strResID); SetItemData(Index, ResId); return Index; } /***************************************************************** **【函数名称】 __delRes **【函数功能】 删除资源 **【参数】 **【返回值】 ****************************************************************/ void CViewLine::__delRes( UINT ResId ) { int Index = __indexItem(ResId); if (Index != -1) { // 界面删除行 DeleteItem(Index); } } /***************************************************************** **【函数名称】 create **【函数功能】 控件初始化 **【参数】 **【返回值】 ****************************************************************/ bool CViewLine::create( CDisplayWnd* pWnd ) { ASSERT(pWnd != NULL); CString Name; Name.LoadString(IDS_STR_VIEW_LINE); // 创建pane if (!m_Pane.Create(Name, pWnd, CRect(0, 0, 400, 400), TRUE, IDS_STR_VIEW_LINE, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_TOP | CBRS_FLOAT_MULTI)) { TRACE0("创建设备资源窗口失败"); return false; } m_Pane.EnableDocking(CBRS_ALIGN_ANY); //创建控件 if(!Create(WS_CHILD | WS_VISIBLE | WS_VSCROLL | LVS_REPORT | LVS_SORTASCENDING, CRect(0, 0, 0, 0), &m_Pane, IDC_LIST_LINE)) { TRACE0("创建设备资源控件失败\n"); return false; } SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES); InsertColumn(COLUMN_RES_ID, _T("线路ID"), LVCFMT_LEFT, 140); InsertColumn(COLUMN_RES_IPO_ID, _T("匹配ID"), LVCFMT_LEFT, 140); InsertColumn(COLUMN_RES_TYPE, _T("类型"), LVCFMT_LEFT, 140); InsertColumn(COLUMN_RES_STATE, _T("状态"), LVCFMT_LEFT, 140); pWnd->OnNewPane(&m_Pane); return true; } /***************************************************************** **【函数名称】 onLineStateUpdated **【函数功能】 线路状态更新处理函数 **【参数】 **【返回值】 ****************************************************************/ void CViewLine::onLineStateUpdated( int LineId ) { CLine* pLine = CDeviceMgr::GetInstance().findLineByID(LineId); ASSERT(pLine != NULL); if(pLine == NULL) return; int Index = __indexItem(LineId); if (Index == -1) // 未找到对应线路,则先创建 Index = __addRes(LineId); // 创建线路 ASSERT(Index != -1); CString Data; Data.Format(_T("%d"), pLine->assoIpoId()); SetItemText(Index, COLUMN_RES_IPO_ID, Data); Data = __transType2String(pLine->type()); SetItemText(Index, COLUMN_RES_TYPE, Data); Data = pLine->getState(); SetItemText(Index, COLUMN_RES_STATE, Data); } /***************************************************************** **【函数名称】 newSize **【函数功能】 调整控件大小 **【参数】 **【返回值】 ****************************************************************/ void CViewLine::newSize( CRect& Rect ) { if(IsWindow(GetSafeHwnd())) SetWindowPos(NULL, Rect.left, Rect.top, Rect.Width(), Rect.Height(), SWP_NOACTIVATE | SWP_NOZORDER); } BEGIN_MESSAGE_MAP(CViewLine, CListCtrl) END_MESSAGE_MAP() // CViewLine 消息处理程序