Overlay.cpp
资源名称:VC++视频传输.rar [点击查看]
上传用户:hxb_1234
上传日期:2010-03-30
资源大小:8328k
文件大小:4k
源码类别:
VC书籍
开发平台:
Visual C++
- // Overlay.cpp : implementation file
- //
- #include "stdafx.h"
- #include <windows.h>
- #include <mmsystem.h>
- #include "MAV8.h"
- #include "Overlay.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // COverlay
- IMPLEMENT_DYNCREATE(COverlay, CFrameWnd)
- COverlay::COverlay()
- {
- // g_hVFDrv = hVFDrv;
- CFrameWnd::Create(NULL, "Overlay Window");
- }
- COverlay::COverlay(HDRVR hVFDrv, RECT rectOverlay, WORD wSrcWidth, WORD wSrcHeight)
- {
- g_hVFDrv = hVFDrv;
- wOverlaySrcWidth=wSrcWidth;
- wOverlaySrcHeight=wSrcHeight;
- CFrameWnd::Create(NULL, "Video Window",WS_OVERLAPPEDWINDOW, rectOverlay);
- }
- COverlay::~COverlay()
- {
- }
- BEGIN_MESSAGE_MAP(COverlay, CFrameWnd)
- //{{AFX_MSG_MAP(COverlay)
- ON_WM_CREATE()
- ON_WM_MOVE()
- ON_WM_SIZE()
- ON_WM_CLOSE()
- ON_WM_PAINT()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- BOOL COverlay::SetSrc(WORD wSrcWidth, WORD wSrcHeight)
- {
- wOverlaySrcWidth=wSrcWidth;
- wOverlaySrcHeight=wSrcHeight;
- HVFSetOverlaySrc(g_hVFDrv, wOverlaySrcWidth, wOverlaySrcHeight);
- CRect rectOverlay;
- GetWindowRect(rectOverlay);
- SetWindowPos(&wndTop, rectOverlay.left, rectOverlay.top,
- wSrcWidth + GetSystemMetrics(SM_CXFRAME),
- wSrcHeight + GetSystemMetrics(SM_CYFRAME)+12+
- //GetSystemMetrics(SM_CYCAPTION)+GetSystemMetrics(SM_CYMENU),
- GetSystemMetrics(SM_CYCAPTION),
- SWP_SHOWWINDOW);
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // COverlay message handlers
- BOOL COverlay::PreCreateWindow(CREATESTRUCT& cs)
- {
- /*// TODO: Add your specialized code here and/or call the base class
- HBRUSH hBrushMagenta=::CreateSolidBrush(RGB(255, 0, 255));
- HCURSOR hCursor=::LoadCursor(NULL, IDC_ARROW);
- //*** jsm, 1/9/98
- // added LoadIcon
- HICON hIcon = ::LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_TSTLOGO));
- cs.lpszClass=AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW,
- hCursor, hBrushMagenta, hIcon);
- DeleteObject(hBrushMagenta);
- */
- nScreenX=GetSystemMetrics(SM_CXSCREEN);
- nScreenY=GetSystemMetrics(SM_CYSCREEN);
- return CFrameWnd::PreCreateWindow(cs);
- }
- int COverlay::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
- // TODO: Add your specialized creation code here
- HVFSetOverlayWnd(g_hVFDrv, m_hWnd);
- HVFSetOverlaySrc(g_hVFDrv, wOverlaySrcWidth, wOverlaySrcHeight);
- return 0;
- }
- void COverlay::OnMove(int x, int y)
- {
- gnPosX=x;
- gnPosY=y;
- CFrameWnd::OnMove(x, y);
- // TODO: Add your message handler code here
- HVFSetOverlayPos(g_hVFDrv, x, y);
- }
- void COverlay::OnSize(UINT nType, int cx, int cy)
- {
- #define DIVIDEVALUE 40
- // TODO: Add your message handler code here
- if(cx+(cx/DIVIDEVALUE) > nScreenX ||
- cy+(cy/DIVIDEVALUE) > nScreenY){
- // make the window size smaller to avoid the 352 and 360 problem
- CRect rectOverlay;
- rectOverlay.left=0;
- rectOverlay.top=0;
- rectOverlay.right= nScreenX - (nScreenX/DIVIDEVALUE) ;
- rectOverlay.bottom= nScreenY- (nScreenY/DIVIDEVALUE) ;
- SetWindowPos(&wndTop, rectOverlay.left, rectOverlay.top,
- rectOverlay.right, rectOverlay.bottom+12, SWP_SHOWWINDOW);
- } else {
- // make the destination lager than window size, because 360 and 352 problem
- CFrameWnd::OnSize(nType, cx, cy);
- // SetOverlayDst(m_hWnd, cx+(cx/DIVIDEVALUE), cy+(cy/DIVIDEVALUE));
- HVFSetOverlayDst(g_hVFDrv, cx+(cx/DIVIDEVALUE), cy);
- }
- HVFSetOverlayPos(g_hVFDrv, gnPosX, gnPosY);
- }
- void COverlay::OnClose()
- {
- HVFUnloadOverlay (g_hVFDrv);
- CFrameWnd::OnClose();
- }
- void COverlay::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
- if (g_hVFDrv)
- HVFPaintOverlay (g_hVFDrv, &dc.m_ps);
- }