www.pudn.com > aa.rar > CTitleOverlayProp.cpp


// 
// CTitleOverlayProp.cpp 
// 
 
#include  
 
// Eliminate two expected level 4 warnings from the Microsoft compiler. 
// The class does not have an assignment or copy operator, and so cannot 
// be passed by value.  This is normal.  This file compiles clean at the 
// highest (most picky) warning level (-W4). 
#pragma warning(disable: 4511 4512) 
 
#include  
#include  
#include  
#include  
#include  
#include  
#include  
 
#include "Resource.h"            // ids used in the dialog 
#include "CTitleOverlayProp.h"    // our own class 
#include "OverlayDefs.h" 
 
// 
// CreateInstance 
// 
// Override CClassFactory method. 
// Set lpUnk to point to an IUnknown interface on a new NullIPProperties object 
// Part of the COM object instantiation mechanism 
// 
CUnknown * WINAPI CTitleOverlayProp::CreateInstance(LPUNKNOWN lpunk, HRESULT *phr) 
{ 
	CUnknown *punk = new CTitleOverlayProp(lpunk, phr); 
	if (punk == NULL)  
	{ 
		*phr = E_OUTOFMEMORY; 
	} 
	return punk; 
} 
 
// Constructs and initialises a object 
CTitleOverlayProp::CTitleOverlayProp(LPUNKNOWN pUnk, HRESULT *phr) 
    : CBasePropertyPage(NAME("Title Overlay Property Page"),pUnk, 
        IDD_FILTER_PROP, IDS_INFO) 
{ 
	ASSERT(phr); 
	mIOverlay      = NULL; 
	mIsFontChanged = FALSE; 
} // CGraphInfoProp 
 
 
// Override CBasePropertyPage method. 
// Handles the messages for our property window 
BOOL CTitleOverlayProp::OnReceiveMessage(HWND hwnd, 
                                        UINT uMsg, 
                                        WPARAM wParam, 
                                        LPARAM lParam) 
{ 
    switch (uMsg) 
    { 
        case WM_INITDIALOG: 
        { 
			// Get windows' handles 
			m_hOverlayType    = GetDlgItem(hwnd, IDC_COMBO_OVERLAY_TYPE); 
			m_hEditTilte      = GetDlgItem(hwnd, IDC_EDIT_TITLE); 
			m_hEditStartX     = GetDlgItem(hwnd, IDC_EDIT_STARTX); 
			m_hEditStartY     = GetDlgItem(hwnd, IDC_EDIT_STARTY); 
			m_hEditStartTime  = GetDlgItem(hwnd, IDC_EDIT_STARTTIME); 
			m_hEditEndTime    = GetDlgItem(hwnd, IDC_EDIT_ENDTIME); 
			m_hEditColorR     = GetDlgItem(hwnd, IDC_EDIT_COLORR); 
			m_hEditColorG     = GetDlgItem(hwnd, IDC_EDIT_COLORG); 
			m_hEditColorB     = GetDlgItem(hwnd, IDC_EDIT_COLORB); 
			break; 
        } 
 
        case WM_COMMAND: 
        { 
			if (HIWORD(wParam) == BN_CLICKED) 
			{ 
				switch (LOWORD(wParam)) 
				{ 
					case IDC_BUTTON_CHANGE_FONT: 
						OnButtonChangeFont(); 
						break; 
				} 
			} 
			SetDirty(); 
            break; 
        } 
 
    } 
    return CBasePropertyPage::OnReceiveMessage(hwnd,uMsg,wParam,lParam); 
} // OnReceiveMessage 
 
 
// Override CBasePropertyPage method. 
// Notification of which object this property page should display. 
// We query the object for the IFltTrace interface. 
HRESULT CTitleOverlayProp::OnConnect(IUnknown *pUnknown) 
{ 
	HRESULT hr = pUnknown->QueryInterface(IID_ITitleOverlay, (void **) &mIOverlay); 
	if (FAILED(hr)) 
	{ 
		return E_NOINTERFACE; 
	} 
	ASSERT(mIOverlay); 
 
	return NOERROR; 
} // OnConnect 
 
 
// Override CBasePropertyPage method. 
// Release the private interface, release the upstream pin. 
HRESULT CTitleOverlayProp::OnDisconnect() 
{ 
	// Release of Interface 
	if (mIOverlay == NULL) 
		return E_UNEXPECTED; 
	mIOverlay->Release(); 
	mIOverlay = NULL; 
 
	return NOERROR; 
} // OnDisconnect 
 
 
// We are being activated 
HRESULT CTitleOverlayProp::OnActivate() 
{ 
	FillOverlayTypeComboBox(); 
	ReflectOverlayType(); 
	ReflectOverlayStyle(); 
	ReflectTitle(); 
	ReflectTitleStartPosition(); 
	ReflectTitleDuration(); 
	ReflectTitleColor(); 
	ReflectTitleFont(); 
	return NOERROR; 
} // Activate 
 
 
// Changes made should be kept 
HRESULT CTitleOverlayProp::OnApplyChanges() 
{ 
	EnterOverlayType();  // This must be first invoked!! 
	EnterOverlayStyle(); 
	EnterTitle(); 
	EnterTitleStartPosition(); 
	EnterTitleDuration(); 
	EnterTitleColor(); 
	EnterTitleFont(); 
	return NOERROR; 
} // OnApplyChanges 
 
// 
// Sets m_hrDirtyFlag and notifies the property page site of the change 
void CTitleOverlayProp::SetDirty() 
{ 
    m_bDirty = TRUE; 
    if (m_pPageSite) 
    { 
        m_pPageSite->OnStatusChange(PROPPAGESTATUS_DIRTY); 
    } 
} // SetDirty 
 
void CTitleOverlayProp::FillOverlayTypeComboBox(void) 
{ 
	const char * szType[] =  
	{ 
		"None", "Static", "System Time", "Scroll Top", "Scroll Bottom" 
	}; 
	int enType[] =  
	{ 
		OT_NONE, OT_STATIC, OT_SYSTIME, OT_SCROLL_TOP, OT_SCROLL_BOTTOM 
	}; 
	const int nCount = sizeof(szType) / sizeof(szType[0]); 
 
	// Reset the combo box content 
	SendMessage(m_hOverlayType, CB_RESETCONTENT, 0, 0); 
	for (int i = 0; i < nCount; i++) 
	{ 
		SendMessage(m_hOverlayType, CB_ADDSTRING, 0, (LPARAM)szType[i]); 
		SendMessage(m_hOverlayType, CB_SETITEMDATA, i, (LPARAM)enType[i]); 
	} 
} 
 
int CTitleOverlayProp::GetOverlayTypeComboIndex(int inType) 
{ 
	// Set the first item selected 
	int  nCount = SendMessage(m_hOverlayType, CB_GETCOUNT, 0, 0); 
	for (int i = 0; i < nCount; i++) 
	{ 
		int nItemData = (int) SendMessage(m_hOverlayType, CB_GETITEMDATA, i, 0); 
		if (nItemData == inType) 
		{ 
			return i; 
		} 
	} 
	return 0; 
} 
 
void CTitleOverlayProp::ReflectOverlayType(void) 
{ 
	long   overlayType = 0; 
	mIOverlay->get_TitleOverlayType(&overlayType); 
	SendMessage(m_hOverlayType, CB_SETCURSEL, GetOverlayTypeComboIndex(overlayType), 0); 
} 
 
void CTitleOverlayProp::ReflectOverlayStyle(void) 
{ 
	BOOL  usingCover = TRUE; 
	mIOverlay->get_TitleOverlayStyle(&usingCover); 
	CheckRadioButton(m_hwnd, IDC_RADIO_BYCOVER, IDC_RADIO_BYREVERSE,  
		usingCover ? IDC_RADIO_BYCOVER : IDC_RADIO_BYREVERSE); 
} 
 
void CTitleOverlayProp::ReflectTitle(void) 
{ 
	int  titleLength = 0; 
	mIOverlay->get_Title(NULL, &titleLength); 
	if (titleLength > 0) 
	{ 
		char * szTitle = new char[titleLength]; 
		mIOverlay->get_Title(szTitle, &titleLength); 
		SetWindowText(m_hEditTilte, szTitle); 
		delete[] szTitle; 
	} 
} 
 
void CTitleOverlayProp::ReflectTitleStartPosition(void) 
{ 
	POINT   startPos; 
	mIOverlay->get_TitleStartPosition(&startPos); 
	char    szPoint[100]; 
	sprintf(szPoint, "%d", startPos.x); 
	SetWindowText(m_hEditStartX, szPoint); 
	sprintf(szPoint, "%d", startPos.y); 
	SetWindowText(m_hEditStartY, szPoint); 
} 
 
void CTitleOverlayProp::ReflectTitleDuration(void) 
{ 
	double  startTime = 0, endTime = 0;  
	mIOverlay->get_TitleDuration(&startTime, &endTime); 
	char    szDuration[100]; 
	sprintf(szDuration, "%.2f", startTime); 
	SetWindowText(m_hEditStartTime, szDuration); 
	sprintf(szDuration, "%.2f", endTime); 
	SetWindowText(m_hEditEndTime, szDuration); 
} 
 
void CTitleOverlayProp::ReflectTitleColor(void) 
{ 
	BYTE  colorR, colorG, colorB;	 
	mIOverlay->get_TitleColor(&colorR, &colorG, &colorB); 
	char  szColor[100]; 
	sprintf(szColor, "%d", colorR); 
	SetWindowText(m_hEditColorR, szColor); 
	sprintf(szColor, "%d", colorG); 
	SetWindowText(m_hEditColorG, szColor); 
	sprintf(szColor, "%d", colorB); 
	SetWindowText(m_hEditColorB, szColor); 
	mTitleColor = RGB(colorR, colorG, colorB); 
} 
 
void CTitleOverlayProp::ReflectTitleColor(BYTE inR, BYTE inG, BYTE inB) 
{ 
	char  szColor[100]; 
	sprintf(szColor, "%d", inR); 
	SetWindowText(m_hEditColorR, szColor); 
	sprintf(szColor, "%d", inG); 
	SetWindowText(m_hEditColorG, szColor); 
	sprintf(szColor, "%d", inB); 
	SetWindowText(m_hEditColorB, szColor); 
} 
 
void CTitleOverlayProp::ReflectTitleFont(void) 
{ 
	mIOverlay->get_TitleFont(&mTitleFont); 
} 
 
void CTitleOverlayProp::EnterOverlayType(void) 
{ 
	int nSelected = SendMessage(m_hOverlayType, CB_GETCURSEL, 0, 0); 
	int nType     = SendMessage(m_hOverlayType, CB_GETITEMDATA, nSelected, 0); 
	mIOverlay->put_TitleOverlayType(nType); 
} 
 
void CTitleOverlayProp::EnterOverlayStyle(void) 
{ 
	int  nChecked = IsDlgButtonChecked(m_hwnd, IDC_RADIO_BYCOVER); 
	mIOverlay->put_TitleOverlayStyle(nChecked); 
} 
 
void CTitleOverlayProp::EnterTitle(void) 
{ 
	char szTitle[2000]; 
	if (GetWindowText(m_hEditTilte, szTitle, 2000)) 
	{ 
		mIOverlay->put_Title(szTitle, strlen(szTitle)); 
	} 
	else 
	{ 
		mIOverlay->put_Title("", 0); 
	} 
} 
 
void CTitleOverlayProp::EnterTitleStartPosition(void) 
{ 
	POINT   startPos;	 
	char    szPos[100]; 
	GetWindowText(m_hEditStartX, szPos, 100); 
	startPos.x = atoi(szPos); 
	GetWindowText(m_hEditStartY, szPos, 100); 
	startPos.y = atoi(szPos); 
	mIOverlay->put_TitleStartPosition(startPos); 
} 
 
void CTitleOverlayProp::EnterTitleDuration(void) 
{ 
	char    szDuration[100]; 
	GetWindowText(m_hEditStartTime, szDuration, 100); 
	double startTime = atof(szDuration); 
	GetWindowText(m_hEditEndTime, szDuration, 100); 
	double endTime   = atof(szDuration); 
	mIOverlay->put_TitleDuration(startTime, endTime); 
} 
 
void CTitleOverlayProp::EnterTitleColor(void) 
{ 
	BYTE  colorR = 0, colorG = 0, colorB = 0;	 
	char  szColor[100]; 
	GetWindowText(m_hEditColorR, szColor, 100); 
	colorR = atoi(szColor); 
	GetWindowText(m_hEditColorG, szColor, 100); 
	colorG = atoi(szColor); 
	GetWindowText(m_hEditColorB, szColor, 100); 
	colorB = atoi(szColor); 
	mIOverlay->put_TitleColor(colorR, colorG, colorB); 
} 
 
void CTitleOverlayProp::EnterTitleFont(void) 
{ 
	if (mIsFontChanged) 
	{ 
		mIOverlay->put_TitleFont(mTitleFont); 
	} 
} 
 
void CTitleOverlayProp::OnButtonChangeFont(void) 
{ 
	// Update the RGB values 
	BYTE  colorR = 0, colorG = 0, colorB = 0;	 
	char  szColor[100]; 
	GetWindowText(m_hEditColorR, szColor, 100); 
	colorR = atoi(szColor); 
	GetWindowText(m_hEditColorG, szColor, 100); 
	colorG = atoi(szColor); 
	GetWindowText(m_hEditColorB, szColor, 100); 
	colorB = atoi(szColor); 
	mTitleColor = RGB(colorR, colorG, colorB); 
 
	CHOOSEFONT    cf; 
	// Initialize CHOOSEFONT 
	ZeroMemory(&cf, sizeof(CHOOSEFONT)); 
	cf.lStructSize = sizeof(CHOOSEFONT); 
	cf.hInstance   = g_hInst; 
	cf.hwndOwner   = m_hwnd; 
	cf.lpLogFont   = &mTitleFont; 
	cf.rgbColors   = mTitleColor; 
	cf.Flags       = CF_SCREENFONTS | CF_EFFECTS | CF_INITTOLOGFONTSTRUCT; 
	if (ChooseFont(&cf))  
	{ 
		mIsFontChanged = TRUE; 
		// Update the text color 
		mTitleColor    = cf.rgbColors; 
		ReflectTitleColor(GetRValue(mTitleColor), GetGValue(mTitleColor), GetBValue(mTitleColor)); 
	} 
}