资源简介
专门为教学用MFC6.0写一个录屏程序,是基于对话框的,直接编译就可以运行,不足之处是保存为avi,存储量巨大,望真正需要的朋友下载使用,欢迎批评指正。
代码片段和文件信息
#include “StdAfx.h“
#include “avifile.h“
#ifndef __countof
#define __countof(x) ((sizeof(x)/sizeof(x[0])))
#endif
CAviFile:: CAviFile(LPCSTR lpszFileName /* =_T(“Output.avi“) */
DWORD dwCodec /* = mmioFOURCC(‘M‘‘P‘‘G‘‘4‘) */
DWORD dwframeRate /* = 1 */)
{
AVIFileInit();
m_hHeap=NULL;
m_hAviDC=NULL;
m_lpBits=NULL;
m_lSample=NULL;
m_pAviFile=NULL;
m_pAviStream=NULL;
m_pAviCompressedStream=NULL;
m_dwFCCHandler = dwCodec;
m_dwframeRate = dwframeRate;
_tcscpy(m_szFileName lpszFileName);
_tcscpy(m_szErrMsg _T(“Method Succeeded“));
m_szErrMsg[__countof(m_szErrMsg)-1] = _T(‘\0‘);
pAppendframe[0]= &CAviFile::AppendDummy; // VC8 requires & for Function Pointer; Remove it if your compiler complains;
pAppendframe[1]= &CAviFile::AppendframeFirstTime;
pAppendframe[2]= &CAviFile::AppendframeUsual;
pAppendframeBits[0]=&CAviFile::AppendDummy;
pAppendframeBits[1]=&CAviFile::AppendframeFirstTime;
pAppendframeBits[2]=&CAviFile::AppendframeUsual;
m_nAppendFuncSelector=1; //0=Dummy 1=FirstTime 2=Usual
}
CAviFile::~CAviFile(void)
{
ReleaseMemory();
AVIFileExit();
}
void CAviFile::ReleaseMemory()
{
m_nAppendFuncSelector=0; //Point to DummyFunction
if(m_hAviDC)
{
DeleteDC(m_hAviDC);
m_hAviDC=NULL;
}
if(m_pAviCompressedStream)
{
AVIStreamRelease(m_pAviCompressedStream);
m_pAviCompressedStream=NULL;
}
if(m_pAviStream)
{
AVIStreamRelease(m_pAviStream);
m_pAviStream=NULL;
}
if(m_pAviFile)
{
AVIFileRelease(m_pAviFile);
m_pAviFile=NULL;
}
if(m_lpBits)
{
HeapFree(m_hHeapHEAP_NO_SERIALIZEm_lpBits);
m_lpBits=NULL;
}
if(m_hHeap)
{
HeapDestroy(m_hHeap);
m_hHeap=NULL;
}
}
void CAviFile::SetErrorMessage(LPCTSTR lpszErrorMessage)
{
_tcsncpy(m_szErrMsg lpszErrorMessage __countof(m_szErrMsg)-1);
}
HRESULT CAviFile::InitMovieCreation(int nframeWidth int nframeHeight int nBitsPerPixel)
{
int nMaxWidth=GetSystemMetrics(SM_CXSCREEN)nMaxHeight=GetSystemMetrics(SM_CYSCREEN);
m_hAviDC = CreateCompatibleDC(NULL);
if(m_hAviDC==NULL)
{
SetErrorMessage(“Unable to Create Compatible DC“);
return E_FAIL;
}
if(nframeWidth > nMaxWidth) nMaxWidth= nframeWidth;
if(nframeHeight > nMaxHeight) nMaxHeight = nframeHeight;
m_hHeap=HeapCreate(HEAP_NO_SERIALIZE nMaxWidth*nMaxHeight*4 0);
if(m_hHeap==NULL)
{
SetErrorMessage(“Unable to Create Heap“);
return E_FAIL;
}
m_lpBits=HeapAlloc(m_hHeap HEAP_ZERO_MEMORY|HEAP_NO_SERIALIZE nMaxWidth*nMaxHeight*4);
if(m_lpBits==NULL)
{
SetErrorMessage(“Unable to Allocate Memory on Heap“);
return E_FAIL;
}
if(FAILED(AVIFileOpen(&m_pAviFile m_szFileName OF_CREATE|OF_WRITE NULL)))
{
SetErrorMessage(“Unable to Create the Movie File“);
return E_FAIL;
}
ZeroMemory(&m_AviStreamInfosizeof(AVISTREAMINFO));
m_AviStreamInfo.fccType = streamtypeVIDEO;
m_AviStreamInfo.fccHandler = m_dwFCCHandler;
m_AviStr
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 7127 2011-03-14 21:45 MyScreenRecorder\AviFile.cpp
文件 3564 2015-06-06 12:09 MyScreenRecorder\AviFile.h
文件 37180 2015-06-06 16:13 MyScreenRecorder\MyScreenRecorder.aps
文件 2464 2015-06-06 16:15 MyScreenRecorder\MyScreenRecorder.clw
文件 2203 2015-06-06 11:10 MyScreenRecorder\MyScreenRecorder.cpp
文件 4542 2015-06-06 16:15 MyScreenRecorder\MyScreenRecorder.dsp
文件 555 2015-06-06 11:10 MyScreenRecorder\MyScreenRecorder.dsw
文件 1434 2015-06-06 11:10 MyScreenRecorder\MyScreenRecorder.h
文件 66560 2015-06-06 16:15 MyScreenRecorder\MyScreenRecorder.ncb
文件 49664 2015-06-06 16:15 MyScreenRecorder\MyScreenRecorder.opt
文件 2048 2015-06-06 16:15 MyScreenRecorder\MyScreenRecorder.plg
文件 7441 2015-06-06 16:13 MyScreenRecorder\MyScreenRecorder.rc
文件 8064 2015-06-06 16:11 MyScreenRecorder\MyScreenRecorderDlg.cpp
文件 2189 2015-06-06 16:07 MyScreenRecorder\MyScreenRecorderDlg.h
文件 1373 2015-06-06 11:54 MyScreenRecorder\MySetDlg.cpp
文件 1269 2015-06-06 11:53 MyScreenRecorder\MySetDlg.h
文件 3759 2015-06-06 11:10 MyScreenRecorder\ReadMe.txt
文件 1078 2015-06-06 11:10 MyScreenRecorder\res\MyScreenRecorder.ico
文件 408 2015-06-06 11:10 MyScreenRecorder\res\MyScreenRecorder.rc2
文件 1386 2015-06-06 16:11 MyScreenRecorder\resource.h
文件 218 2015-06-06 11:10 MyScreenRecorder\StdAfx.cpp
文件 1054 2015-06-06 11:10 MyScreenRecorder\StdAfx.h
目录 0 2015-06-06 16:18 MyScreenRecorder\Debug
目录 0 2015-06-06 16:17 MyScreenRecorder\Release
目录 0 2015-06-06 16:18 MyScreenRecorder\res
目录 0 2015-06-06 16:18 MyScreenRecorder
----------- --------- ---------- ----- ----
205580 26
- 上一篇:MFC 与UG开发教程与视频
- 下一篇:KMP,键树 英语文章单词统计
评论
共有 条评论