📄 videownd.cpp
字号:
/*
VIS H.323 Video Conference System
--Sample for VIS H.323 DLL Library 2.1 Release
For more information,visit our homepage
[http://www.115studio.com]
or mail to us for tech support and bug report
[support@115studio.com]
2000-2004 115Studio
2004-04-05
*/
// VideoWnd.cpp : implementation file
//
#include "stdafx.h"
#include "VISConf.h"
#include "VideoWnd.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CVideoBuffer::CVideoBuffer()
{
m_buf=NULL;
m_w=0;
m_h=0;
}
CVideoBuffer::~CVideoBuffer()
{
CleanUpBuffer();
}
BYTE *CVideoBuffer::GetBuffer(int w,int h)
{
m_mutex.Lock();
void *ptr=NULL;
if(w==0||(w==m_w&&h==m_h))
{
ptr=m_buf;
goto RET;
}
if(m_buf)
{
ptr=HeapReAlloc(GetProcessHeap(),0,m_buf,w*h*3);
if(ptr==NULL)
{
HeapFree(GetProcessHeap(),0,m_buf);
}
}
else
{
ptr=HeapAlloc(GetProcessHeap(),0,w*h*3);
}
if(ptr==NULL)
goto RET;
m_buf=ptr;
m_w=w;
m_h=h;
memset(m_buf,0,w*h*3);
RET:
if(!ptr)
m_mutex.Unlock();
return (BYTE*)ptr;
}
void CVideoBuffer::ReleaseBuffer()
{
if(m_buf)
m_mutex.Unlock();
}
void CVideoBuffer::CleanUpBuffer()
{
m_mutex.Lock();
if(m_buf)
{
HeapFree(GetProcessHeap(),0,m_buf);
m_buf=NULL;
m_w=0;
m_h=0;
}
m_mutex.Unlock();
}
/////////////////////////////////////////////////////////////////////////////
// CVideoWnd
CVideoWnd::CVideoWnd()
{
memset(&m_bmi,0,sizeof(m_bmi));
m_bmi.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
m_bmi.bmiHeader.biPlanes=1;
m_bmi.bmiHeader.biBitCount=24;
m_bSizeChanged=FALSE;
}
CVideoWnd::~CVideoWnd()
{
}
BEGIN_MESSAGE_MAP(CVideoWnd, CWnd)
//{{AFX_MSG_MAP(CVideoWnd)
ON_WM_ERASEBKGND()
ON_WM_LBUTTONDBLCLK()
ON_WM_CLOSE()
ON_WM_CREATE()
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVideoWnd message handlers
BOOL CVideoWnd::OnEraseBkgnd(CDC* pDC)
{
BYTE *ptr=m_buffer.GetBuffer();
if(ptr)
{
if(m_bSizeChanged)
{
m_bSizeChanged=FALSE;
CRect rcWnd,rcClient;
GetWindowRect(rcWnd);
GetClientRect(rcClient);
//Make the client area fit video size
SetWindowPos(0,0,0,m_bmi.bmiHeader.biWidth+rcWnd.Width()-rcClient.Width(),m_bmi.bmiHeader.biHeight+rcWnd.Height()-rcClient.Height(),SWP_NOMOVE);
}
else
{
CRect rc;
GetClientRect(&rc);
DrawDibDraw(m_hDrawDIB,pDC->GetSafeHdc(),0,0,rc.Width(),rc.Height(),&m_bmi.bmiHeader,ptr,0,0,m_bmi.bmiHeader.biWidth,m_bmi.bmiHeader.biHeight,DDF_NOTKEYFRAME);
}
m_buffer.ReleaseBuffer();
return TRUE;
}
else
return CWnd::OnEraseBkgnd(pDC);
}
BOOL CVideoWnd::Create(CWnd *pParentWnd, DWORD dwExStyle, LPCTSTR lpszWindowName, DWORD dwStyle, int x, int y, int nWidth, int nHeight)
{
CString ClassName;
ClassName=AfxRegisterWndClass(
CS_VREDRAW | CS_HREDRAW|CS_DBLCLKS,
::LoadCursor(NULL, IDC_ARROW),
(HBRUSH) ::GetStockObject(BLACK_BRUSH),
NULL);
if(ClassName.IsEmpty())
return FALSE;
HWND parent=NULL;
if(pParentWnd)
parent=pParentWnd->m_hWnd;
return CWnd::CreateEx(dwExStyle,ClassName,lpszWindowName,dwStyle,x,y,nWidth,nHeight,parent,NULL);
}
BYTE * CVideoWnd::GetBuffer(int w, int h)
{
BYTE *ptr=NULL;
if(m_hWnd&&IsWindowVisible())
{
ptr=m_buffer.GetBuffer(w,h);
if(ptr)
{
if(w!=m_bmi.bmiHeader.biWidth||h!=m_bmi.bmiHeader.biHeight)
{
m_bmi.bmiHeader.biWidth=w;
m_bmi.bmiHeader.biHeight=h;
m_bSizeChanged=TRUE;
}
m_bmi.bmiHeader.biWidth=w;
m_bmi.bmiHeader.biHeight=h;
//We don't call ReleaseBuffer() here, and call it later
}
}
return ptr;
}
BOOL CVideoWnd::ReleaseBuffer()
{
m_buffer.ReleaseBuffer();
if(m_hWnd)
InvalidateRect(NULL);
return TRUE;
}
void CVideoWnd::OnLButtonDblClk(UINT nFlags, CPoint point)
{
if(m_bmi.bmiHeader.biWidth>0)
{
CRect rcWnd,rcClient;
GetWindowRect(rcWnd);
GetClientRect(rcClient);
//make the client area fit video size
SetWindowPos(0,0,0,m_bmi.bmiHeader.biWidth+rcWnd.Width()-rcClient.Width(),m_bmi.bmiHeader.biHeight+rcWnd.Height()-rcClient.Height(),SWP_NOMOVE);
}
CWnd::OnLButtonDblClk(nFlags, point);
}
void CVideoWnd::OnClose()
{
//Don't close and let parent close it
CWnd *MainWnd=::AfxGetApp()->GetMainWnd();
if(MainWnd)
MainWnd->SendMessage(UM_CHILD_CLOSE,(WPARAM)m_hWnd,0);
}
int CVideoWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
CRect rcWnd,rcClient;
GetWindowRect(rcWnd);
GetClientRect(rcClient);
//make the client rectangle fit video size
SetWindowPos(0,0,0,176+rcWnd.Width()-rcClient.Width(),144+rcWnd.Height()-rcClient.Height(),SWP_NOMOVE);
memset(&m_bmi,0,sizeof(m_bmi));
m_bmi.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
m_bmi.bmiHeader.biPlanes=1;
m_bmi.bmiHeader.biBitCount=24;
m_hDrawDIB=DrawDibOpen();
return 0;
}
void CVideoWnd::OnDestroy()
{
CWnd::OnDestroy();
m_buffer.CleanUpBuffer();
DrawDibClose(m_hDrawDIB);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -