📄 vfwwnd.cpp
字号:
/*
Module : VFWWnd.cpp
Purpose: Interface for an MFC class which encapsulates the "AviCap" window class
Created: PJN / 26-09-2000
History: PJN / 19-12-2006 1. Updated the copyright details
2. Updated the sample app to clean compile on VC 2005
3. Updated the documentation to use the same style as my web site.
4. Code now uses newer C++ style casts instead of C style casts.
5. Removed CAVICapWnd destructor as it was unused
6. Fixed a bug in CAVICapWnd::SetUserData where the wrong message
was being used.
7. Reviewed all TRACE statements for correctness.
8. Addition of a AVICAPWND_EXT_CLASS preprocessor macro to allow the
class to be more easily added to an extension DLL.
Copyright (c) 2000 - 2006 by PJ Naughter (Web: www.naughter.com, Email: pjna@naughter.com)
All rights reserved.
Copyright / Usage Details:
You are allowed to include the source code in any product (commercial, shareware, freeware or otherwise)
when your product is released in binary form. You are allowed to modify the source code in any way you want
except you cannot modify the copyright details at the top of each module. If you want to distribute source
code with your application, then you are only allowed to distribute versions released by the author. This is
to maintain a single distribution point for the source code.
*/
///////////////////////////////// Includes //////////////////////////////////
#include "stdafx.h"
#include "VFWWnd.h"
//////////////////////////////// Macros / Defines /////////////////////////////
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//Automatically link to the correct import library
#pragma comment(lib, "vfw32.lib")
////////////////////////////// Implementation /////////////////////////////////
IMPLEMENT_DYNAMIC(CAVICapWnd, CWnd)
BEGIN_MESSAGE_MAP(CAVICapWnd, CWnd)
//{{AFX_MSG_MAP(CAVICapWnd)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
CAVICapWnd::CAVICapWnd() : CWnd()
{
}
#ifdef _DEBUG
void CAVICapWnd::AssertValid() const
{
//Just call the base class
CWnd::AssertValid();
}
void CAVICapWnd::Dump(CDumpContext& dc) const
{
//Just call the base class
CWnd::Dump(dc);
}
#endif //_DEBUG
BOOL CAVICapWnd::GetDescription(WORD nIndex, CString& sName, CString sVersion)
{
TCHAR* pszName = sName.GetBuffer(_MAX_PATH);
TCHAR* pszVersion = sVersion.GetBuffer(_MAX_PATH);
BOOL bSuccess = ::capGetDriverDescription(nIndex, pszName, _MAX_PATH, pszVersion, _MAX_PATH);
sName.ReleaseBuffer();
sVersion.ReleaseBuffer();
return bSuccess;
}
//These declarations are need since these functions are not declared in any publically
//available MFC header file
extern void AFXAPI AfxHookWindowCreate(CWnd* pWnd);
extern BOOL AFXAPI AfxUnhookWindowCreate();
BOOL CAVICapWnd::Create(DWORD dwStyle, const CRect& rect, CWnd* pParentWnd, UINT nID)
{
ASSERT(pParentWnd);
AfxHookWindowCreate(this);
HWND hWnd = ::capCreateCaptureWindow(_T(""), dwStyle, rect.left, rect.top, rect.Width(), rect.Height(),
pParentWnd->GetSafeHwnd(), nID);
#ifdef _DEBUG
if (hWnd == NULL)
TRACE(_T("Warning: AVICap Window creation failed: GetLastError returns 0x%8.8X\n"), GetLastError());
#endif
if (!AfxUnhookWindowCreate())
PostNcDestroy(); //Cleanup if CreateWindowEx fails too soon
if (hWnd == NULL)
return FALSE;
ASSERT(hWnd == m_hWnd); //Should have been set in send msg hook
return TRUE;
}
BOOL CAVICapWnd::Abort()
{
return static_cast<BOOL>(SendMessage(WM_CAP_ABORT));
}
BOOL CAVICapWnd::Connect(int nIndex)
{
return static_cast<BOOL>(SendMessage(WM_CAP_DRIVER_CONNECT, static_cast<WPARAM>(nIndex)));
}
BOOL CAVICapWnd::Disconnect()
{
return static_cast<BOOL>(SendMessage(WM_CAP_DRIVER_DISCONNECT));
}
BOOL CAVICapWnd::CaptureSequence()
{
return static_cast<BOOL>(SendMessage(WM_CAP_SEQUENCE));
}
BOOL CAVICapWnd::Stop()
{
return static_cast<BOOL>(SendMessage(WM_CAP_STOP));
}
BOOL CAVICapWnd::GetStatus(CAPSTATUS& status)
{
return static_cast<BOOL>(SendMessage(WM_CAP_GET_STATUS, static_cast<WPARAM>(sizeof(status)), reinterpret_cast<LPARAM>(&status)));
}
BOOL CAVICapWnd::GetCaps(CAPDRIVERCAPS& caps)
{
return static_cast<BOOL>(SendMessage(WM_CAP_DRIVER_GET_CAPS, static_cast<WPARAM>(sizeof(caps)), reinterpret_cast<LPARAM>(&caps)));
}
BOOL CAVICapWnd::GetName(CString& sName)
{
TCHAR* pszName = sName.GetBuffer(_MAX_PATH);
BOOL bSuccess = static_cast<BOOL>(SendMessage(WM_CAP_DRIVER_GET_NAME, _MAX_PATH, reinterpret_cast<LPARAM>(pszName)));
sName.ReleaseBuffer();
return bSuccess;
}
BOOL CAVICapWnd::GetVersion(CString& sVersion)
{
TCHAR* pszVersion = sVersion.GetBuffer(_MAX_PATH);
BOOL bSuccess = static_cast<BOOL>(SendMessage(WM_CAP_DRIVER_GET_NAME, _MAX_PATH, reinterpret_cast<LPARAM>(pszVersion)));
sVersion.ReleaseBuffer();
return bSuccess;
}
BOOL CAVICapWnd::SetOverlay(BOOL bOverlay)
{
return static_cast<BOOL>(SendMessage(WM_CAP_SET_OVERLAY, static_cast<WPARAM>(bOverlay)));
}
BOOL CAVICapWnd::SetPreview(BOOL bPreview)
{
return static_cast<BOOL>(SendMessage(WM_CAP_SET_PREVIEW, static_cast<WPARAM>(bPreview)));
}
BOOL CAVICapWnd::HasOverlay()
{
CAPDRIVERCAPS caps;
return GetCaps(caps) && caps.fHasOverlay;
}
BOOL CAVICapWnd::IsOverlay()
{
CAPSTATUS status;
return GetStatus(status) && status.fOverlayWindow;
}
BOOL CAVICapWnd::IsPreview()
{
CAPSTATUS status;
return GetStatus(status) && status.fLiveWindow;
}
BOOL CAVICapWnd::SetPreviewRate(WORD wPreviewRate)
{
return static_cast<BOOL>(SendMessage(WM_CAP_SET_PREVIEWRATE, static_cast<WPARAM>(wPreviewRate)));
}
BOOL CAVICapWnd::SetScale(BOOL bScale)
{
return static_cast<BOOL>(SendMessage(WM_CAP_SET_SCALE, static_cast<WPARAM>(bScale)));
}
BOOL CAVICapWnd::SetScroll(const CPoint& point)
{
return static_cast<BOOL>(SendMessage(WM_CAP_SET_SCROLL, reinterpret_cast<WPARAM>(&point)));
}
BOOL CAVICapWnd::HasVideoOutputDlg()
{
CAPDRIVERCAPS caps;
return GetCaps(caps) && caps.fHasDlgVideoDisplay;
}
BOOL CAVICapWnd::ShowVideoOutputDlg()
{
return static_cast<BOOL>(SendMessage(WM_CAP_DLG_VIDEODISPLAY));
}
BOOL CAVICapWnd::HasVideoFormatDlg()
{
CAPDRIVERCAPS caps;
return GetCaps(caps) && caps.fHasDlgVideoFormat;
}
BOOL CAVICapWnd::ShowVideoFormatDlg()
{
return static_cast<BOOL>(SendMessage(WM_CAP_DLG_VIDEOFORMAT));
}
BOOL CAVICapWnd::HasVideoSourceDlg()
{
CAPDRIVERCAPS caps;
return GetCaps(caps) && caps.fHasDlgVideoSource;
}
BOOL CAVICapWnd::ShowVideoSourceDlg()
{
return static_cast<BOOL>(SendMessage(WM_CAP_DLG_VIDEOSOURCE));
}
BOOL CAVICapWnd::ShowCompressionDlg()
{
return static_cast<BOOL>(SendMessage(WM_CAP_DLG_VIDEOCOMPRESSION));
}
BOOL CAVICapWnd::GetAudioFormat(WAVEFORMATEX*& pWaveFormat, DWORD& dwSize)
{
BOOL bSuccess = FALSE; //Assume the worst
ASSERT(pWaveFormat == NULL); //Must be called with NULL pointer as we
//will allocate the memory for it
dwSize = static_cast<DWORD>(SendMessage(WM_CAP_GET_AUDIOFORMAT));
if (dwSize)
{
pWaveFormat = reinterpret_cast<WAVEFORMATEX*>(new BYTE[dwSize]);
bSuccess = (SendMessage(WM_CAP_GET_AUDIOFORMAT, dwSize, reinterpret_cast<LPARAM>(pWaveFormat)) != 0);
}
return bSuccess;
}
BOOL CAVICapWnd::SetAudioFormat(WAVEFORMATEX* pWaveFormat)
{
return static_cast<BOOL>(SendMessage(WM_CAP_SET_AUDIOFORMAT, sizeof(WAVEFORMATEX), reinterpret_cast<LPARAM>(pWaveFormat)));
}
BOOL CAVICapWnd::SetAudioFormat(PCMWAVEFORMAT* pWaveFormat)
{
return static_cast<BOOL>(SendMessage(WM_CAP_SET_AUDIOFORMAT, sizeof(PCMWAVEFORMAT), reinterpret_cast<LPARAM>(pWaveFormat)));
}
BOOL CAVICapWnd::GetVideoFormat(BITMAPINFO*& pBitmapInfo)
{
BOOL bSuccess = FALSE; //Assume the worst
ASSERT(pBitmapInfo == NULL); //Must be called with NULL pointer as we
//will allocate the memory for it
DWORD dwSize = static_cast<DWORD>(SendMessage(WM_CAP_GET_VIDEOFORMAT));
if (dwSize)
{
pBitmapInfo = reinterpret_cast<BITMAPINFO*>(new BYTE[dwSize]);
bSuccess = (SendMessage(WM_CAP_GET_VIDEOFORMAT, dwSize, reinterpret_cast<LPARAM>(pBitmapInfo)) != 0);
}
return bSuccess;
}
BOOL CAVICapWnd::SetVideoFormat(BITMAPINFO* pBitmapInfo)
{
return static_cast<BOOL>(SendMessage(WM_CAP_SET_VIDEOFORMAT, sizeof(BITMAPINFO), reinterpret_cast<LPARAM>(pBitmapInfo)));
}
BOOL CAVICapWnd::FileAllocate(DWORD dwSize)
{
return static_cast<BOOL>(SendMessage(WM_CAP_FILE_ALLOCATE, 0, static_cast<LPARAM>(dwSize)));
}
BOOL CAVICapWnd::GetCaptureFile(CString& sFilename)
{
TCHAR* pszFilename = sFilename.GetBuffer(_MAX_PATH);
BOOL bSuccess = static_cast<BOOL>(SendMessage(WM_CAP_FILE_GET_CAPTURE_FILE, _MAX_PATH, reinterpret_cast<LPARAM>(pszFilename)));
sFilename.ReleaseBuffer();
return bSuccess;
}
BOOL CAVICapWnd::SaveAs(const CString& sFilename)
{
return static_cast<BOOL>(SendMessage(WM_CAP_FILE_SAVEAS, 0, reinterpret_cast<LPARAM>(sFilename.operator LPCTSTR())));
}
BOOL CAVICapWnd::SetCaptureFile(const CString& sFilename)
{
return static_cast<BOOL>(SendMessage(WM_CAP_FILE_SET_CAPTURE_FILE, 0, reinterpret_cast<LPARAM>(sFilename.operator LPCTSTR())));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -