www.pudn.com > ActiveH263_V1.00.rar > ActiveH263Ctl.cpp


// ActiveH263Ctl.cpp : Implementation of the CActiveH263Ctrl ActiveX Control class. 
 
#include "stdafx.h" 
#include "ActiveH263.h" 
#include "ActiveH263Ctl.h" 
#include "ActiveH263Ppg.h" 
 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
//全局变量声明 
CString filename; 
CWinThread * pthread0; 
CWinThread * pthread1; 
 
IMPLEMENT_DYNCREATE(CActiveH263Ctrl, COleControl) 
 
 
///////////////////////////////////////////////////////////////////////////// 
// Message map 
 
BEGIN_MESSAGE_MAP(CActiveH263Ctrl, COleControl) 
	//{{AFX_MSG_MAP(CActiveH263Ctrl) 
	// NOTE - ClassWizard will add and remove message map entries 
	//    DO NOT EDIT what you see in these blocks of generated code ! 
	//}}AFX_MSG_MAP 
	ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties) 
END_MESSAGE_MAP() 
 
 
///////////////////////////////////////////////////////////////////////////// 
// Dispatch map 
 
BEGIN_DISPATCH_MAP(CActiveH263Ctrl, COleControl) 
	//{{AFX_DISPATCH_MAP(CActiveH263Ctrl) 
	DISP_FUNCTION(CActiveH263Ctrl, "StartWrite", StartWrite, VT_EMPTY, VTS_NONE) 
	DISP_FUNCTION(CActiveH263Ctrl, "StartDecoder", StartDecoder, VT_EMPTY, VTS_NONE) 
	DISP_FUNCTION(CActiveH263Ctrl, "Stop", Stop, VT_EMPTY, VTS_NONE) 
	//}}AFX_DISPATCH_MAP 
	DISP_FUNCTION_ID(CActiveH263Ctrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE) 
END_DISPATCH_MAP() 
 
 
///////////////////////////////////////////////////////////////////////////// 
// Event map 
 
BEGIN_EVENT_MAP(CActiveH263Ctrl, COleControl) 
	//{{AFX_EVENT_MAP(CActiveH263Ctrl) 
	// NOTE - ClassWizard will add and remove event map entries 
	//    DO NOT EDIT what you see in these blocks of generated code ! 
	//}}AFX_EVENT_MAP 
END_EVENT_MAP() 
 
 
///////////////////////////////////////////////////////////////////////////// 
// Property pages 
 
// TODO: Add more property pages as needed.  Remember to increase the count! 
BEGIN_PROPPAGEIDS(CActiveH263Ctrl, 1) 
	PROPPAGEID(CActiveH263PropPage::guid) 
END_PROPPAGEIDS(CActiveH263Ctrl) 
 
 
///////////////////////////////////////////////////////////////////////////// 
// Initialize class factory and guid 
 
IMPLEMENT_OLECREATE_EX(CActiveH263Ctrl, "ACTIVEH263.ActiveH263Ctrl.1", 
	0x91391f67, 0xc773, 0x4ce6, 0xa8, 0x9a, 0x45, 0x30, 0, 0x2b, 0xc0, 0x72) 
 
 
///////////////////////////////////////////////////////////////////////////// 
// Type library ID and version 
 
IMPLEMENT_OLETYPELIB(CActiveH263Ctrl, _tlid, _wVerMajor, _wVerMinor) 
 
 
///////////////////////////////////////////////////////////////////////////// 
// Interface IDs 
 
const IID BASED_CODE IID_DActiveH263 = 
		{ 0x4fe9b2a5, 0x7004, 0x407d, { 0xab, 0xe0, 0xd, 0x20, 0x15, 0xfe, 0x2c, 0xee } }; 
const IID BASED_CODE IID_DActiveH263Events = 
		{ 0xe4568701, 0x7f6d, 0x4b69, { 0xa2, 0x4, 0x37, 0xa8, 0xae, 0x2, 0x9d, 0x49 } }; 
 
 
///////////////////////////////////////////////////////////////////////////// 
// Control type information 
 
static const DWORD BASED_CODE _dwActiveH263OleMisc = 
	OLEMISC_ACTIVATEWHENVISIBLE | 
	OLEMISC_SETCLIENTSITEFIRST | 
	OLEMISC_INSIDEOUT | 
	OLEMISC_CANTLINKINSIDE | 
	OLEMISC_RECOMPOSEONRESIZE; 
 
IMPLEMENT_OLECTLTYPE(CActiveH263Ctrl, IDS_ACTIVEH263, _dwActiveH263OleMisc) 
 
 
///////////////////////////////////////////////////////////////////////////// 
// CActiveH263Ctrl::CActiveH263CtrlFactory::UpdateRegistry - 
// Adds or removes system registry entries for CActiveH263Ctrl 
UINT WriteThread(LPVOID lpParam) 
{ 
	CActiveH263Ctrl *pDlg=(CActiveH263Ctrl *)lpParam; 
	char *readfilename; 
	readfilename="C:\\picture.263"; 
	if((pDlg->WTrfp=fopen(readfilename,"rb+"))==NULL) 
	{ 
		AfxMessageBox("读文件出错! 在当前目录下找不到picture.263文件。"); 
		return 1; 
	} 
	unsigned char input[2049]; 
	while(!feof(pDlg->WTrfp)) 
	{ 
		for (int i=0;i<2048;i++) 
			input[i]=fgetc(pDlg->WTrfp); 
		input[2048]=0; 
		pDlg->m_263lib.q.put(input); 
		Sleep(1); 
	} 
	fclose(pDlg->WTrfp); 
	return 0; 
} 
 
UINT DecoderThread(LPVOID lpParam) 
{ 
	CActiveH263Ctrl *pDlg=(CActiveH263Ctrl *)lpParam; 
	pDlg->m_263lib.main(); 
	return 0; 
} 
 
BOOL CActiveH263Ctrl::CActiveH263CtrlFactory::UpdateRegistry(BOOL bRegister) 
{ 
	// TODO: Verify that your control follows apartment-model threading rules. 
	// Refer to MFC TechNote 64 for more information. 
	// If your control does not conform to the apartment-model rules, then 
	// you must modify the code below, changing the 6th parameter from 
	// afxRegApartmentThreading to 0. 
 
	if (bRegister) 
		return AfxOleRegisterControlClass( 
			AfxGetInstanceHandle(), 
			m_clsid, 
			m_lpszProgID, 
			IDS_ACTIVEH263, 
			IDB_ACTIVEH263, 
			afxRegApartmentThreading, 
			_dwActiveH263OleMisc, 
			_tlid, 
			_wVerMajor, 
			_wVerMinor); 
	else 
		return AfxOleUnregisterClass(m_clsid, m_lpszProgID); 
} 
 
 
///////////////////////////////////////////////////////////////////////////// 
// CActiveH263Ctrl::CActiveH263Ctrl - Constructor 
 
CActiveH263Ctrl::CActiveH263Ctrl() 
{ 
	InitializeIIDs(&IID_DActiveH263, &IID_DActiveH263Events); 
	hWnd=GetSafeHwnd(); 
	m_263lib.mainhWnd=hWnd; 
	m_263lib.testdisplay(); 
	// TODO: Initialize your control's instance data here. 
} 
 
 
///////////////////////////////////////////////////////////////////////////// 
// CActiveH263Ctrl::~CActiveH263Ctrl - Destructor 
 
CActiveH263Ctrl::~CActiveH263Ctrl() 
{ 
	// TODO: Cleanup your control's instance data here. 
} 
 
 
///////////////////////////////////////////////////////////////////////////// 
// CActiveH263Ctrl::OnDraw - Drawing function 
 
void CActiveH263Ctrl::OnDraw( 
			CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid) 
{ 
	// TODO: Replace the following code with your own drawing code. 
//	pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH))); 
//	pdc->Ellipse(rcBounds); 
//	pthread1=AfxBeginThread(WriteThread,this,THREAD_PRIORITY_NORMAL); 
} 
 
 
///////////////////////////////////////////////////////////////////////////// 
// CActiveH263Ctrl::DoPropExchange - Persistence support 
 
void CActiveH263Ctrl::DoPropExchange(CPropExchange* pPX) 
{ 
	ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor)); 
	COleControl::DoPropExchange(pPX); 
 
	// TODO: Call PX_ functions for each persistent custom property. 
 
} 
 
 
///////////////////////////////////////////////////////////////////////////// 
// CActiveH263Ctrl::OnResetState - Reset control to default state 
 
void CActiveH263Ctrl::OnResetState() 
{ 
	COleControl::OnResetState();  // Resets defaults found in DoPropExchange 
 
	// TODO: Reset any other control state here. 
} 
 
 
///////////////////////////////////////////////////////////////////////////// 
// CActiveH263Ctrl::AboutBox - Display an "About" box to the user 
 
void CActiveH263Ctrl::AboutBox() 
{ 
	CDialog dlgAbout(IDD_ABOUTBOX_ACTIVEH263); 
	dlgAbout.DoModal(); 
} 
 
 
///////////////////////////////////////////////////////////////////////////// 
// CActiveH263Ctrl message handlers 
 
void CActiveH263Ctrl::StartWrite()  
{ 
	// TODO: Add your dispatch handler code here 
	pthread1=AfxBeginThread(WriteThread,this,THREAD_PRIORITY_NORMAL); 
} 
 
void CActiveH263Ctrl::StartDecoder()  
{ 
	// TODO: Add your dispatch handler code here 
	pthread0=AfxBeginThread(DecoderThread,this,THREAD_PRIORITY_NORMAL); 
} 
 
void CActiveH263Ctrl::Stop()  
{ 
	// TODO: Add your dispatch handler code here 
	if(!TerminateThread(pthread0->m_hThread,0)) 
		AfxMessageBox("结束播放线程出错"); 
/*	DWORD lpExitCode; 
    GetExitCodeThread(pthread1->m_hThread,&lpExitCode); 
	if(lpExitCode==STILL_ACTIVE) 
	{ 
		if(!TerminateThread(pthread1->m_hThread,0)) 
			AfxMessageBox("结束写LOOP线程出错"); 
		else 
			fclose(WTrfp); 
	}*/ 
	CDC* pdc; 
	pdc = GetDC(); 
	CGdiObject * pold = pdc->SelectStockObject(BLACK_BRUSH); 
	CRect arry=CRect(4,4,356,292); 
	pdc->FillRect(arry,NULL); 
	ValidateRect(&arry); 
}