www.pudn.com > VirtualVCR-src-v2.6.9.zip > FlowMeterProp.cpp


/* 
	Virtual VCR 
    Copyright (C) 2002  Shaun Faulds 
 
    This program is free software; you can redistribute it and/or modify 
    it under the terms of the GNU General Public License as published by 
    the Free Software Foundation; either version 2 of the License, or 
    (at your option) any later version. 
 
    This program is distributed in the hope that it will be useful, 
    but WITHOUT ANY WARRANTY; without even the implied warranty of 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    GNU General Public License for more details. 
 
    You should have received a copy of the GNU General Public License 
    along with this program; if not, write to the Free Software 
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
 
	Acknowledgments: 
	This application and associated filters are based on the examples 
	from the Microsoft DirectX DirectShow SDK. 
*/ 
 
#include  
 
#pragma warning(disable: 4511 4512) 
 
#include  
#include  
#include  
#include  
#include  
#include  
#include  
 
#include "resource.h" 
#include "FlowMeterUIDs.h" 
#include "iFlowMeter.h" 
#include "FlowMeterProp.h" 
 
// 
// CreateInstance 
// 
// Override CClassFactory method. 
// Set lpUnk to point to an IUnknown interface on a new FlowMeterProperties object 
// Part of the COM object instantiation mechanism 
// 
CUnknown * WINAPI FlowMeterProperties::CreateInstance(LPUNKNOWN lpunk, HRESULT *phr) 
{ 
 
    CUnknown *punk = new FlowMeterProperties(lpunk, phr); 
    if (punk == NULL) 
	{ 
        *phr = E_OUTOFMEMORY; 
    } 
    return punk; 
 
} 
 
 
// 
// Constructs and initialises a FlowMeterProperties object 
// 
FlowMeterProperties::FlowMeterProperties(LPUNKNOWN pUnk, HRESULT *phr) 
    : CBasePropertyPage(NAME("Flow Meter Property Page"),pUnk 
	, IDD_PROPERTIESPAGE, IDS_TITLE) 
    , m_pINullIPP(NULL) 
{ 
    ASSERT(phr); 
 
} // (constructor) 
 
 
// 
// SetDirty 
// 
// Sets m_hrDirtyFlag and notifies the property page site of the change 
// 
/* 
void FlowMeterProperties::SetDirty() 
{ 
 
    m_bDirty = TRUE; 
    if (m_pPageSite) 
    { 
        m_pPageSite->OnStatusChange(PROPPAGESTATUS_DIRTY); 
    } 
 
} // SetDirty 
*/ 
 
// 
// OnReceiveMessage 
// 
// Override CBasePropertyPage method. 
// Handles the messages for our property window 
// 
BOOL FlowMeterProperties::OnReceiveMessage(HWND hwnd, 
                                        UINT uMsg, 
                                        WPARAM wParam, 
                                        LPARAM lParam) 
{ 
 
    switch (uMsg) 
    { 
        case WM_INITDIALOG: 
        { 
			SendMessage(GetDlgItem(hwnd,IDC_SAMPLEOVER_SPIN), 
				UDM_SETRANGE, 0, MAKELPARAM(1000, 1)); 
 
			TCHAR  Cwidth[32]; 
			LONGLONG data = 0; 
			ASSERT(m_pINullIPP); 
 
			m_pINullIPP->get_FlowData(&data); 
			FormatByteNumber(data, Cwidth); 
			SetDlgItemText(hwnd, IDC_FlowMeter_Bytes, Cwidth); 
 
			m_pINullIPP->get_TransformCount(&data); 
			wsprintf(Cwidth, TEXT("%d"), data); 
			SetDlgItemText(hwnd, IDC_FlowMeter_Samples, Cwidth); 
 
			double samples = 0; 
			m_pINullIPP->get_SamplesPerSecond(&samples); 
			_stprintf(Cwidth, TEXT("%f"), samples); 
			SetDlgItemText(hwnd, IDC_SAMPLEPERSECOND, Cwidth);	 
 
            return (LRESULT) 1; 
        } 
 
        case WM_COMMAND: 
        { 
			switch(HIWORD(wParam)) 
			{ 
	  			case EN_CHANGE: 
				{ 
					switch(LOWORD(wParam)) 
					{ 
						case IDC_SAMPLEOVER: 
						{ 
							TCHAR Cwidth[32]; 
							bool update = false; 
							int newValue = GetDlgItemInt(hwnd, IDC_SAMPLEOVER, NULL, FALSE); 
							if(newValue < 1) 
							{ 
								newValue = 1; 
								update = true; 
							} 
							else if(newValue > 1000) 
							{ 
								newValue = 1000; 
								update = true; 
							} 
 
							if(update) 
							{ 
								wsprintf(Cwidth, TEXT("%d"), newValue); 
								SetDlgItemText(hwnd, IDC_SAMPLEOVER, Cwidth); 
							} 
 
							break; 
						} 
					} 
					break; 
				} 
				case BN_CLICKED: 
				{ 
					switch(LOWORD(wParam)) 
					{ 
						case ID_RESET: 
						{ 
							LONGLONG dataFlow = 0; 
							ASSERT(m_pINullIPP); 
							m_pINullIPP->resetALL(); 
							return (LRESULT) 1; 
						} 
					} 
				} 
			} 
        } 
 
		case WM_CREATE: 
		{ 
			SetTimer(hwnd, 1, 250, NULL); 
			return (LRESULT) 1; 
		} 
 
		case WM_TIMER: 
		{ 
 
			TCHAR Cwidth[32]; 
			 
			LONGLONG data = 0; 
			ASSERT(m_pINullIPP); 
			m_pINullIPP->get_FlowData(&data); 
			FormatByteNumber(data, Cwidth); 
			SetDlgItemText(hwnd, IDC_FlowMeter_Bytes, Cwidth); 
			 
			m_pINullIPP->get_TransformCount(&data); 
			wsprintf(Cwidth, TEXT("%d"), data); 
			SetDlgItemText(hwnd, IDC_FlowMeter_Samples, Cwidth); 
 
			double samples = 0; 
			m_pINullIPP->get_SamplesPerSecond(&samples); 
			_stprintf(Cwidth, TEXT("%f"), samples); 
			SetDlgItemText(hwnd, IDC_SAMPLEPERSECOND, Cwidth);		 
		 
			return (LRESULT) 1; 
		} 
 
    } 
    return CBasePropertyPage::OnReceiveMessage(hwnd,uMsg,wParam,lParam); 
 
} // OnReceiveMessage 
 
 
// 
// OnConnect 
// 
// Override CBasePropertyPage method. 
// Notification of which object this property page should display. 
 
HRESULT FlowMeterProperties::OnConnect(IUnknown *pUnknown) 
{ 
 
    ASSERT(m_pINullIPP == NULL); 
 
    HRESULT hr = pUnknown->QueryInterface(IID_IFlowMeter, (void **) &m_pINullIPP); 
    if (FAILED(hr)) 
    { 
        return E_NOINTERFACE; 
    } 
 
	ASSERT(m_pINullIPP); 
 
    return NOERROR; 
 
} // OnConnect 
 
 
// 
// OnDisconnect 
// 
// Override CBasePropertyPage method. 
// 
HRESULT FlowMeterProperties::OnDisconnect() 
{ 
    // Release of Interface 
 
    if (m_pINullIPP == NULL) 
        return E_UNEXPECTED; 
    m_pINullIPP->Release(); 
    m_pINullIPP = NULL; 
 
    return NOERROR; 
 
} // OnDisconnect 
 
 
// 
// Activate 
// 
// We are being activated 
// 
HRESULT FlowMeterProperties::OnActivate() 
{ 
 
    return NOERROR; 
 
} // Activate 
 
 
// 
// OnApplyChanges 
// 
// Changes made should be kept. 
// 
HRESULT FlowMeterProperties::OnApplyChanges() 
{ 
 
    return NOERROR; 
 
} // OnApplyChanges 
 
 
/* 
	Format byte number for display groups 
	000,000,000,000 etc 
*/ 
BOOL FlowMeterProperties::FormatByteNumber(LONGLONG number, TCHAR* buff) 
{ 
	TCHAR tempBuff[60]; 
	char intBuff[3]; 
	int bufferOffset = 0; 
 
	int LowNumber = 0; 
	while(number > 0) 
	{ 
		LowNumber = number % 10; 
		_stprintf(intBuff, TEXT("%.1d"), LowNumber); 
		tempBuff[bufferOffset++] = intBuff[0]; 
		if(number > 10 && (bufferOffset == 3 || bufferOffset == 7 || bufferOffset == 11 || bufferOffset == 15)) 
			tempBuff[bufferOffset++] = ','; 
		number = number / 10; 
	} 
 
	bufferOffset--; 
 
	for(int x = 0; x <= bufferOffset; x++) 
	{ 
		buff[x] = tempBuff[bufferOffset - x]; 
	} 
 
	buff[bufferOffset+1] = 0; 
 
	return true; 
}