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

📄 statisticsdlg.cpp

📁 media player 控件源码 用EVC编译可以进行对WINCE下media player控制
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
///////////////////////////////////////////////////////////////////////////////
// File: StatisticsDlg.cpp
//
// Desc: This file defines the member functions of the Statistics Dialog class
//       as well as the DialogProc for the dialog.
//
///////////////////////////////////////////////////////////////////////////////

#include <windows.h>
#include <tchar.h>
#include <nsplay.h>

#include "StatisticsDlg.h"
#include "PlayerWindow.h"
#include "resource.h"

#include "aygshell_helper.h"

static const int REGKEY_SIZE = 80;

extern bool g_bSmallScreen;

///////////////////////////////////////////////////////////////////////////////
// Name: StatisticsDialogProc()
// Desc: This function handles dialog messages for the Statistics dialog box.
///////////////////////////////////////////////////////////////////////////////
BOOL CALLBACK StatisticsDialogProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    static CStatisticsDlg *pStatisticsDlg = NULL;
    
    switch (uMsg)
    {
    case WM_INITDIALOG:
        pStatisticsDlg = new CStatisticsDlg;
        
        if (NULL == pStatisticsDlg || false == pStatisticsDlg->Init(hWndDlg))
        {
            DestroyWindow(hWndDlg);
        }
        else if( g_bSmallScreen && g_AygshellHelper.Loaded() )
        {
            SHINITDLGINFO shidi;
            shidi.dwMask = SHIDIM_FLAGS;
            shidi.dwFlags = SHIDIF_SIZEDLGFULLSCREEN | SHIDIF_SIPDOWN | SHIDIF_DONEBUTTON;
            shidi.hDlg = hWndDlg;
            g_AygshellHelper.SHInitDialog( &shidi );
        }
        return TRUE;
        
    case WM_COMMAND:
        switch (LOWORD(wParam))
        {
        case IDCANCEL:
        case IDOK:
        case ID_DLG_CLOSE:
            DestroyWindow(hWndDlg);
            return TRUE;
        }
        return FALSE;

    case WM_NOTIFY:
        if( pStatisticsDlg )
        {
            return pStatisticsDlg->HandleNotifyMsg(hWndDlg, uMsg, wParam, lParam);
        }
        break;
        
    // The WM_CLOSE message is sent when the "X" button is pressed.
    case WM_CLOSE:
        DestroyWindow(hWndDlg);
        return 0;

    case WM_DESTROY:
        if (NULL != pStatisticsDlg)
        {
            delete pStatisticsDlg;
            pStatisticsDlg = NULL;
        }
        return TRUE;
        
    // This message is sent from the parent window to tell the dialog to
    // show itself.
    case SD_SHOW:
        if( pStatisticsDlg )
        {
            pStatisticsDlg->Show(static_cast<int>(wParam));
        }
        return TRUE;
        
    // This message is sent from the parent window to force the dialog to
    // update the fields in the display.
    case SD_UPDATE:
        pStatisticsDlg->Update(reinterpret_cast<CStatisticsDlg::stats_t*>(wParam));
        return TRUE;
    }
    
    return FALSE;
}

CStatisticsDlg::CStatisticsDlg() : m_dFrameRate(0.0),
    m_dActualRate(0.0),
    m_lFramesDropped(0),
    m_lBandwidth(0),
    m_lSourceProtocol(0),
    m_lReceivedPackets(0),
    m_lRecoveredPackets(0),
    m_lLostPackets(0),
    m_lDroppedAudioPackets(0),
    m_szErrorCorrection(NULL),
    m_szFilename(NULL),
    m_hWnd(NULL),
    m_hWndParent(NULL),
    m_hListView(NULL),
    m_hFont(NULL),
    m_iMaxWidth(0),
    m_iFRIndex(-1),
    m_iARIndex(-1),
    m_iFDIndex(-1),
    m_iBWIndex(-1),
    m_iSPIndex(-1),
    m_iRCIndex(-1),
    m_iRPIndex(-1),
    m_iLPIndex(-1),
    m_iECIndex(-1),
    m_iFNIndex(-1),
    m_iMIIndex(-1),
    m_bFRChanged(true),
    m_bARChanged(true),
    m_bFDChanged(true),
    m_bBWChanged(true),
    m_bSPChanged(true),
    m_bRCChanged(true),
    m_bRPChanged(true),
    m_bLPChanged(true),
    m_bECChanged(true),
    m_bFNChanged(true)
{
    LOGFONT logfont;
    memset(&logfont, 0, sizeof (logfont));
    logfont.lfWeight = FW_SEMIBOLD;
    logfont.lfHeight = -11;
    m_hFont = CreateFontIndirect(&logfont);
}

CStatisticsDlg::~CStatisticsDlg()
{
    (void)Fini();

    if (m_hFont)
        DeleteObject(m_hFont);
}

BOOL CStatisticsDlg::HandleNotifyMsg(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    BOOL fHandled = FALSE;
    NMHDR * pnmh = (NMHDR*)lParam;
    NMLISTVIEW *pnmlv = (NMLISTVIEW*)lParam;

    if (NM_CUSTOMDRAW == pnmh->code
        && m_hListView == pnmh->hwndFrom)
    {
        NMLVCUSTOMDRAW *pcd = (NMLVCUSTOMDRAW*)lParam;

        if (CDDS_PREPAINT == pcd->nmcd.dwDrawStage)
        {
            SetWindowLong(hWndDlg, DWL_MSGRESULT, CDRF_NOTIFYITEMDRAW);
            fHandled = TRUE;
        }
        else if (CDDS_ITEMPREPAINT == pcd->nmcd.dwDrawStage)
        {
            if (0 == (pcd->nmcd.dwItemSpec % 2) && m_hFont)
            {
                SelectObject(pcd->nmcd.hdc, m_hFont);
                SetWindowLong(hWndDlg, DWL_MSGRESULT, CDRF_NEWFONT);
            }

            fHandled = TRUE;
        }
    }
    else if (LVN_DELETEALLITEMS == pnmh->code)
    {
        //
        // Suppress LVN_DELETEITEM notifications
        //
        SetWindowLong(hWndDlg, DWL_MSGRESULT, TRUE);
        fHandled = TRUE;
    }

    return fHandled;
}

///////////////////////////////////////////////////////////////////////////////
// Name: CStatisticsDlg::Init()
// Desc: This function intializes the StatisticsDlg class.
///////////////////////////////////////////////////////////////////////////////
bool CStatisticsDlg::Init(HWND hWnd)
{
    m_hWnd       = hWnd;
    m_hWndParent = ::GetParent(m_hWnd);
    m_hListView = GetDlgItem(m_hWnd, IDC_STATISTICS_LIST);

    if (NULL == m_hWnd || NULL == m_hWndParent)
    {
        return false;
    }

    //
    // Check to see if the screen is small
    //
    if (g_bSmallScreen)
    {
        RECT rcWorkArea;
        RECT rcWnd, rcList;

        GetWindowRect(m_hWnd,      &rcWnd);
        GetWindowRect(m_hListView, &rcList);

        if (!SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWorkArea, 0))
        {
            HDC hdc = ::GetDC(NULL);

            rcWorkArea.left = 0;
            rcWorkArea.top  = 0;

            rcWorkArea.right  = GetDeviceCaps(hdc, HORZRES);
            rcWorkArea.bottom = GetDeviceCaps(hdc, VERTRES) - GetSystemMetrics(SM_CYMENU);

            ::ReleaseDC(NULL, hdc);
        }

        MoveWindow(m_hWnd,
                   rcWorkArea.left,
                   rcWorkArea.top,
                   rcWorkArea.right,
                   rcWorkArea.bottom,
                   TRUE);

        rcWorkArea.left   += rcList.left - rcWnd.left;
        rcWorkArea.right  -= rcList.left - rcWnd.left;
        rcWorkArea.right  += rcList.right - rcWnd.right - 2*GetSystemMetrics(SM_CXDLGFRAME);

        rcWorkArea.top    += rcList.top  - rcWnd.top - GetSystemMetrics(SM_CYCAPTION);
        rcWorkArea.bottom -= rcList.top  - rcWnd.top;
        rcWorkArea.bottom += rcList.bottom - rcWnd.bottom;

        MoveWindow(m_hListView,
                   rcWorkArea.left,
                   rcWorkArea.top,
                   rcWorkArea.right,
                   rcWorkArea.bottom,
                   TRUE);
    }

    LVCOLUMN column;
    int i = 0;

    RECT rect;
    GetClientRect(m_hListView, &rect);
    column.mask = LVCF_FMT | LVCF_WIDTH;
    column.fmt  = LVCFMT_LEFT;
    column.cx   = rect.right - rect.left;
    column.iSubItem = 0;
    column.iOrder   = 0;
    column.iImage   = 0;
    int result = ListView_InsertColumn(m_hListView, 0, &column);

    ListView_SetExtendedListViewStyle(m_hListView, LVS_EX_GRIDLINES);

    return true;
}

///////////////////////////////////////////////////////////////////////////////
// Name: CStatisticsDlg::Fini()
// Desc: This function closes the Statistics dialog (if necessary) and signals
//       the parent window that it has closed.
///////////////////////////////////////////////////////////////////////////////
bool CStatisticsDlg::Fini()
{
    bool bResult = false;
    
    if (NULL != m_hWndParent)
    {
        PostMessage(m_hWndParent, SD_CLOSED, NULL, NULL);
        m_hWndParent = NULL;
    }

    if (NULL != m_szErrorCorrection)
    {
        delete[] m_szErrorCorrection;
        m_szErrorCorrection = NULL;
    }

    if (NULL != m_szFilename)
    {
        delete [] m_szFilename;
        m_szFilename = NULL;
    }

    return bResult;
}

///////////////////////////////////////////////////////////////////////////////
// Name: CStatisticsDlg::Show()
// Desc: This function will cause the dialog to be shown or hidden.
///////////////////////////////////////////////////////////////////////////////
bool CStatisticsDlg::Show(int iShowCmd)
{
    bool  bResult = false;
    
    // Simple error check
    if (NULL == m_hWnd)
    {
        return bResult;
    }
    
    if (FALSE == ShowWindow(m_hWnd, iShowCmd))
    {
        bResult = false;
    }
    else
    {
        bResult = true;
    }

    m_bFNChanged = true;
    m_bFRChanged = true;
    m_bARChanged = true;
    m_bFDChanged = true;
    m_bBWChanged = true;
    m_bSPChanged = true;
    m_bRCChanged = true;
    m_bRPChanged = true;
    m_bLPChanged = true;
    m_bECChanged = true;
    m_bADChanged = true;

    m_iFRIndex = -1;
    m_iARIndex = -1;
    m_iFDIndex = -1;
    m_iBWIndex = -1;
    m_iSPIndex = -1;
    m_iRCIndex = -1;
    m_iRPIndex = -1;
    m_iLPIndex = -1;
    m_iECIndex = -1;
    m_iFNIndex = -1;
    m_iMIIndex = -1;
    m_iADIndex = -1;

    Refresh();
    
    return bResult;
}

///////////////////////////////////////////////////////////////////////////////
// Name: CStatisticsDlg::Update()
// Desc: This function is called when a SD_UPDATE message is received by the
//       dialog.  It update the member variables associated with the edit
//       boxes in the dialog.
///////////////////////////////////////////////////////////////////////////////
void CStatisticsDlg::Update(stats_t *pStats)
{
    // Save this property set
    if (m_dFrameRate != pStats->dFrameRate)
    {
        m_dFrameRate = pStats->dFrameRate;
        m_bFRChanged = true;
    }
    
    if (m_dActualRate != pStats->dActualRate)
    {
        m_dActualRate = pStats->dActualRate;
        m_bARChanged  = true;
    }
    
    if (m_lFramesDropped != pStats->lFramesDropped)
    {
        m_lFramesDropped = pStats->lFramesDropped;
        m_bFDChanged     = true;
    }
    
    if (m_lBandwidth != pStats->lBandwidth)
    {
        m_lBandwidth = pStats->lBandwidth;
        m_bBWChanged = true;
    }
    
    if (m_lSourceProtocol != pStats->lSourceProtocol)
    {
        m_lSourceProtocol = pStats->lSourceProtocol;
        m_bSPChanged      = true;
    }
    
    if (m_lReceivedPackets != pStats->lReceivedPackets)
    {
        m_lReceivedPackets = pStats->lReceivedPackets;
        m_bRCChanged       = true;
    }
    
    if (m_lRecoveredPackets != pStats->lRecoveredPackets)
    {
        m_lRecoveredPackets = pStats->lRecoveredPackets;
        m_bRPChanged        = true;
    }
    
    if (m_lLostPackets != pStats->lLostPackets)
    {
        m_lLostPackets = pStats->lLostPackets;
        m_bLPChanged   = true;
    }
    
    if (m_lDroppedAudioPackets != pStats->lDroppedAudioPackets)
    {
        m_lDroppedAudioPackets = pStats->lDroppedAudioPackets;
        m_bADChanged   = true;
    }

    if (!(NULL != m_szErrorCorrection && NULL != pStats->szErrorCorrection
        && 0 == _tcscmp(m_szErrorCorrection, pStats->szErrorCorrection)))
    {
        if (NULL != m_szErrorCorrection)
        {
            delete[] m_szErrorCorrection;
            m_szErrorCorrection = NULL;
        }
        
        if (NULL != pStats->szErrorCorrection)
        {
            m_szErrorCorrection = new TCHAR[_tcslen(pStats->szErrorCorrection) + 1];

            if (NULL != m_szErrorCorrection)
            {
                _tcscpy(m_szErrorCorrection, pStats->szErrorCorrection);
            }
        }

        m_bECChanged = true;
    }

    if (!(NULL != m_szFilename && NULL != pStats->szFilename
          && 0 == _tcscmp(m_szFilename, pStats->szFilename)))
    {
        if (NULL != m_szFilename)
        {
            delete [] m_szFilename;
            m_szFilename = NULL;
        }

        if (NULL != pStats->szFilename)

⌨️ 快捷键说明

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