基本信息
源码名称:VC6桌面录像
源码大小:3.04KB
文件格式:.rar
开发语言:C/C++
更新时间:2016-01-06
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍
VC6桌面录像,未设置压缩功能

#include <windows.h>
#include <vfw.h>
#include <string.h>
#include <iostream.h>



int main()
{	cout<<"一个录制电脑桌面生成AVI视频文件的Demo,未加入压缩、选录窗口功能"<<"\n\n\n";
	cout<<"请输入文件名:";
	char szFileName[100];
	cin>>szFileName;
	strcat(szFileName, ".avi");
	cout<<endl<<"请输入每秒钟录制的帧数(最大不超过10帧,超过10帧默认为10帧):";
	int ZS=0;
	cin>>ZS;
	ZS=min(10,ZS);
	cout<<endl<<"请输入录制的时长(以秒计算):";
	int MS=0;
	cin>>MS;
	cout<<endl;
	PAVIFILE pfile;	// AVI文件指针
	PAVISTREAM pstream;	// stream指针
	AVISTREAMINFO pstreaminfo;	// stream信息
	BITMAPINFO bi;	// 
 
 	HWND	hwndDesktop = GetDesktopWindow ();	// 获取整个桌面窗口的句柄
	HDC	hdcDesktop  = GetWindowDC ( hwndDesktop );	// 获取整个桌面窗口的设备环境的句柄
	HDC	hmemDC = CreateCompatibleDC ( hdcDesktop );	// 创建并获取兼容内存的设备环境的句柄

	long WEIGHT = GetDeviceCaps(hdcDesktop, HORZRES);
	long HEIGHT = GetDeviceCaps(hdcDesktop, VERTRES);

	AVIFileInit();	// 初始化AVIFile库
 	AVIFileOpen(&pfile, szFileName, OF_CREATE | OF_WRITE, NULL);	// 创建AVI文件

	ZeroMemory(&bi, sizeof(BITMAPINFO));
	CONST int BIT_COUNT24 = 24;
	int bmpWidthBytes =0;
	bmpWidthBytes= WEIGHT*BIT_COUNT24;
	bmpWidthBytes  = 31;
	bmpWidthBytes /= 32;
	bmpWidthBytes *= 4;
	bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	bi.bmiHeader.biBitCount=BIT_COUNT24;
	bi.bmiHeader.biCompression=BI_RGB;
	bi.bmiHeader.biPlanes=1;
	bi.bmiHeader.biWidth = WEIGHT;
	bi.bmiHeader.biHeight = HEIGHT;
	bi.bmiHeader.biSizeImage = bmpWidthBytes * bi.bmiHeader.biHeight;
	BYTE *pBmpBits=NULL;
	HBITMAP	hmemBMP = CreateDIBSection(NULL,&bi,0,(void**)&pBmpBits,NULL,0);	// 创建设备无关位图


	ZeroMemory(&pstreaminfo, sizeof(AVISTREAMINFO));	// 初始化pstreaminfo信息
	pstreaminfo.fccType = streamtypeVIDEO;	// 设置视频流
	pstreaminfo.fccHandler = 0;
	pstreaminfo.dwScale = 1;	// 设置时间间隔
	pstreaminfo.dwRate = ZS;	// 设置帧数
	pstreaminfo.dwSuggestedBufferSize = bmpWidthBytes * bi.bmiHeader.biHeight   0x400;
	SetRect(&pstreaminfo.rcFrame, 0, 0, (int)bi.bmiHeader.biWidth, (int)bi.bmiHeader.biHeight);


	AVIFileCreateStream(pfile, &pstream, &pstreaminfo);	// 创建stream
	AVIStreamSetFormat(pstream, 0, &bi.bmiHeader, sizeof(bi.bmiHeader));	// 设置stream格式

	HBITMAP	holdmemBMP =(HBITMAP)SelectObject ( hmemDC, hmemBMP );	// 将设备无关位图选入兼容内存,并保存原来的兼容DC数据

	cout<<"录制已经开始,倒计时:"<<endl;
	for(long lStreamSize = 0, total = MS*ZS; lStreamSize<total 1; lStreamSize  )
	{
		if(0 == lStreamSize%ZS)
		{
			cout<<MS-lStreamSize/ZS<<endl;
		}
		BitBlt ( hmemDC,0,0,WEIGHT,HEIGHT, hdcDesktop,0,0, SRCCOPY );
		POINT point;
		GetCursorPos(&point);
		HICON hicon = (HICON)LoadCursor(NULL, IDC_ARROW);
		DrawIcon(hmemDC, point.x, point.y,hicon);

		AVIStreamWrite(pstream, lStreamSize, 1, (LPBYTE)pBmpBits, bi.bmiHeader.biSizeImage, AVIIF_KEYFRAME, NULL, NULL);
		lStreamSize  ;
		Sleep(1000/ZS);
	}

	SelectObject ( hmemDC, holdmemBMP );	// 还原兼容DC数据
	DeleteObject ( hmemBMP );	// 删除兼容位图的句柄,销毁创建的位图
	DeleteDC ( hmemDC );	// 删除兼容内存的设备环境的句柄
	ReleaseDC ( hwndDesktop, hdcDesktop );	// 释放整个桌面窗口的设备环境的句柄
	AVIStreamRelease(pstream);	// 关闭stream
	AVIFileRelease(pfile);	// 关闭AVI文件
	AVIFileExit();	// 释放AVIFile库
	return 0;
}