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

📄 statisticsdlg.cpp

📁 Microsoft WinCE 6.0 BSP FINAL release source code for use with the i.MX27ADS TO2 WCE600_FINAL_MX27_S
💻 CPP
字号:
/*
 * Copyright (C) 2004, MOTOROLA, INC. All Rights Reserved
 * THIS SOURCE CODE IS CONFIDENTIAL AND PROPRIETARY AND MAY NOT
 * BE USED OR DISTRIBUTED WITHOUT THE WRITTEN PERMISSION OF
 * MOTOROLA, INC.
 *
 *  Copyright (C) 2004-2006, Freescale Semiconductor, Inc. All Rights Reserved.
 *  THIS SOURCE CODE, AND ITS USE AND DISTRIBUTION, IS SUBJECT TO THE TERMS
 *  AND CONDITIONS OF THE APPLICABLE LICENSE AGREEMENT
 *
 *  File:			APPS/CAMAPP/StatisticsDlg.cpp
 *  Purpose:		This file defines the member functions of the Statistics Dialog class
 *				as well as the DialogProc for the dialog.
 *  Notes:
 *
 *  Author:		Peng Zhuo
 *  Date:			12/27/2004
 *
 *  Modifications:
 *  MM/DD/YYYY		Initials     		Change description 
*/

/*********************************************************************
 INCLUDE FILES  
*********************************************************************/
#include <windows.h>
#include <commctrl.h>

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

/*********************************************************************
 GLOBAL DEFINITIONS  
*********************************************************************/

/*********************************************************************
 GLOBAL OR STATIC VARIABLES  
*********************************************************************/

/*********************************************************************
 STATIC FUNCTION PROTOTYPES  
*********************************************************************/
/********************************************************************
 *
 *  FUNCTION:	StatisticsDialogProc
 *
 *  DESCRIPTION:	This function handles the dialog messages for the CStatisticsDlg dialog box.
 *
 *  PARAMETERS:	HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam
 *
 *  RETURNS:		TRUE if successfully, otherwise return FALSE
 *
 ********************************************************************/
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);
			}
			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;*/
		    
		case WM_CLOSE:
		    	DestroyWindow(hWndDlg);
		    	return TRUE;

		case WM_DESTROY:
			if (NULL != pStatisticsDlg)
			{
			    	delete pStatisticsDlg;
			    	pStatisticsDlg = NULL;
			}
		    	return TRUE;
		    
		case SD_SHOW:
		    	if( pStatisticsDlg )
		    	{
		        	pStatisticsDlg->Show(static_cast<int>(wParam));
		    	}
		    	return TRUE;
		    
		case SD_UPDATE:
		    	pStatisticsDlg->Update(reinterpret_cast<stats_t*>(wParam));
		    	return TRUE;
	}

	return FALSE;
}

/*********************************************************************
 EXPORTED FUNCTIONS
*********************************************************************/
/********************************************************************
 *
 *  FUNCTION:	CStatisticsDlg
 *
 *  DESCRIPTION:	Constructor of CStatisticsDlg class
 *
 *  PARAMETERS:	None
 *
 *  RETURNS:		None
 *
 ********************************************************************/
CStatisticsDlg::CStatisticsDlg()
{
	m_hWnd = NULL;
	m_hListView = NULL;
	
	m_dFrameRate = 0.0;
 	m_dActualRate = 0.0;
	m_bFRChanged = TRUE;
   	m_bARChanged = TRUE;
	m_iFRIndex = -1;
   	m_iARIndex= -1;

}


/********************************************************************
 *
 *  FUNCTION:	~CStatisticsDlg
 *
 *  DESCRIPTION:	Destructor of CStatisticsDlg class
 *
 *  PARAMETERS:	None
 *
 *  RETURNS:		None
 *
 ********************************************************************/
CStatisticsDlg::~CStatisticsDlg()
{
	Fini();
}


/********************************************************************
 *
 *  FUNCTION:	init
 *
 *  DESCRIPTION:	Initialize the CStatisticsDlg class
 *
 *  PARAMETERS:	HWND hWnd
 *
 *  RETURNS:		TRUE if initialize successfully, otherwise return FALSE
 *
 ********************************************************************/
BOOL  CStatisticsDlg::Init(HWND hWnd)
{
	m_hWnd = hWnd;
	m_hWndParent = ::GetParent(m_hWnd);
    	m_hListView = GetDlgItem(m_hWnd, IDC_LIST_STATISTICS);
	if (NULL == m_hWnd || NULL == m_hWndParent)
	{
	    	return false;
	}

	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;
}

/********************************************************************
 *
 *  FUNCTION:	Fini
 *
 *  DESCRIPTION:	Release all Resources acquired by the CStatisticsDlg class
 *
 *  PARAMETERS:	None
 *
 *  RETURNS:		TRUE if successfully, otherwise return FALSE
 *
 ********************************************************************/
 BOOL  CStatisticsDlg::Fini()
{
	BOOL bResult = FALSE;

	if (NULL != m_hWnd)
	{
	  	DestroyWindow(m_hWnd);
	  	bResult = TRUE;
	}
	
	if (NULL != m_hWndParent)
	{
	    	PostMessage(m_hWndParent, SD_CLOSED, NULL, NULL);
	    	m_hWndParent = NULL;
	}

	return bResult;
}


/********************************************************************
 *
 *  FUNCTION:	RefreshItem
 *
 *  DESCRIPTION:	Refresh 2 items
 *
 *  PARAMETERS:	int     iIndex,
 *                      	TCHAR * pszTitle,
 *              		TCHAR * pszText,
 *             		HDC     hdc,
 *  RETURNS:		None
 *
 ********************************************************************/
void CStatisticsDlg::RefreshItem(int     iIndex,
                                 TCHAR * pszTitle,
                                 TCHAR * pszText,
                                 HDC     hdc)
{
    LVITEM item;
    int    itemNumber = 0;

    item.mask      = LVIF_TEXT;
    item.iSubItem  = 0;
    item.state     = 0;
    item.stateMask = 0;

    item.iItem   = iIndex;
    item.pszText = pszTitle;
    if (-1 != ListView_SetItem(m_hListView, &item))
        itemNumber++;

    /*if (GetTextExtentExPoint(hdc, item.pszText, _tcslen(item.pszText), 0, NULL, NULL, &size)
        && size.cx > cx)
        cx = size.cx;*/

    item.iItem   = iIndex + 1;
    item.pszText = pszText;
    if (-1 != ListView_SetItem(m_hListView, &item))
        itemNumber++;
/*
    if (GetTextExtentExPoint(hdc, item.pszText, _tcslen(item.pszText), 0, NULL, NULL, &size)
        && size.cx > cx)
        cx = size.cx;

    if (cx > m_iMaxWidth)
        m_iMaxWidth = cx;*/
}


/********************************************************************
 *
 *  FUNCTION:	InsertTwoItems
 *
 *  DESCRIPTION:	insert 2 items to list view
 *
 *  PARAMETERS:	int iIndex
 *
 *  RETURNS:		None
 *
 ********************************************************************/
void CStatisticsDlg::InsertTwoItems(int iIndex)
{
    LVITEM item;

    item.mask      = LVIF_TEXT;
    item.pszText   = L"";
    item.iSubItem  = 0;
    item.state     = 0;
    item.stateMask = 0;
    item.iItem     = iIndex;

    ListView_InsertItem(m_hListView, &item);
    ListView_InsertItem(m_hListView, &item);
}


/********************************************************************
 *
 *  FUNCTION:	Refresh
 *
 *  DESCRIPTION:	This function copies what is currently in member variables into the
 * 				associated edit box on the dialog.
 *
 *  PARAMETERS:	None
 *
 *  RETURNS:		None
 *
 ********************************************************************/

void CStatisticsDlg::Refresh()
{
	TCHAR szBuf[20];
	HDC   hdc = NULL;

	int   itemNumber = 0;

	hdc = ::GetDC(m_hListView);

	if (-1 == m_iFRIndex && m_bFRChanged && 0.0 != m_dFrameRate)
	{
	    	m_iFRIndex = itemNumber;
	    	InsertTwoItems(m_iFRIndex);
	}
	
	itemNumber += 2;

	if (0.0 != m_dFrameRate && m_bFRChanged)
	{
	    wsprintf(szBuf, TEXT("%.2f"), m_dFrameRate);
	    RefreshItem(m_iFRIndex, L"Desired Frame Rate:", szBuf, hdc);
	}

	if (-1 == m_iARIndex && m_bARChanged && 0.0 != m_dActualRate)
	{
	    m_iARIndex = itemNumber;
	    InsertTwoItems(m_iARIndex);
	}

	if (0.0 != m_dActualRate && m_bARChanged)
	{
	    wsprintf(szBuf, L"%.2f", m_dActualRate);
	    RefreshItem(m_iARIndex, L"Frame Rate:", szBuf, hdc);
	}
}


/********************************************************************
 *
 *  FUNCTION:	Update
 *
 *  DESCRIPTION:	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.
 *
 *  PARAMETERS:	stats_t *pStats
 *
 *  RETURNS:		None
 *
 ********************************************************************/
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;
    }

    Refresh();

    return;
}


/********************************************************************
 *
 *  FUNCTION:	Show
 *
 *  DESCRIPTION:	This function will cause the dialog to be shown or hidden.
 *
 *  PARAMETERS:	int iShowCmd
 *
 *  RETURNS:		TRUE if successfully, otherwise return FALSE
 *
 ********************************************************************/
BOOL CStatisticsDlg::Show(int iShowCmd)
{
	BOOL  bResult = FALSE;

	if (NULL == m_hWnd)
	{
	    	return bResult;
	}

	if (FALSE == ShowWindow(m_hWnd, iShowCmd))
	{
	    	bResult = FALSE;
	}
	else
	{
	    	bResult = TRUE;
	}

	m_bFRChanged = true;
	m_bARChanged = true;

	m_iFRIndex = -1;
	m_iARIndex = -1;

	ListView_DeleteAllItems(m_hListView);
    	Refresh();
    
    	return bResult;
}

/*
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;
}*/
/*********************************************************************
 END OF FILE
*********************************************************************/

⌨️ 快捷键说明

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