![]() |
中国DOS联盟-- 联合DOS 推动DOS 发展DOS --联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum |
| 游客 | 登录 | 注册 | 会员 | 搜索 | 中国DOS联盟 |
|
中国DOS联盟论坛 现在时间是 2026-08-06 08:30 |
共 48,039 主题排行 / 350,124 发帖 / 今日 0 篇 / 48,251 会员排行 |
| DOS批处理 & 脚本技术(批处理室) » 网上找的自动截屏到文件的小程序(请高手编译下吧) |
| 可打印版本 648 / 0 |
| 第1楼 hello547rf44 | 发表于 2007-11-03 17:58 |
| 初级用户 发帖 63 积分 172 | |
|
网上找的自动截屏到文件的小程序(请高手编译下吧) 网上找的自动截屏到文件的小程序(请高手编译下吧)
(一)功能 实现了一个定时截取当前屏幕图像的小程序。 (二)准备工作 1)建立VC CONSOLE APPLICATION,选择MFC SUPPORT 2)在STDAFX.H文件中加入头文件:conio.h (三)主程序 主程序代码如下: char Filename[100]; int count = 0; while(!_kbhit())//用户按键则退出 { Sleep(5000);//挂起5秒 count ++; sprintf(Filename, "%d.bmp", count); Screen(Filename);//调用Screen函数 } 以上代码每隔5秒钟调用一次函数Screen,将当前屏幕保存到文件中。 (四)工作函数Screen Screen实现了当前屏幕内容到bmp文件的拷贝。 源代码如下: void Screen(char filename[]) { CDC *pDC;//屏幕DC pDC = CDC::FromHandle(GetDC(NULL));//获取当前整个屏幕DC int BitPerPixel = pDC->GetDeviceCaps(BITSPIXEL);//获得颜色模式 int Width = pDC->GetDeviceCaps(HORZRES); int Height = pDC->GetDeviceCaps(VERTRES); cout << "当前屏幕色彩模式为" << BitPerPixel << "位色彩" << endl << "屏幕宽度:" << Width << endl << "屏幕高度:" << Height << endl << endl; CDC memDC;//内存DC memDC.CreateCompatibleDC(pDC); CBitmap memBitmap, *oldmemBitmap;//建立和屏幕兼容的bitmap memBitmap.CreateCompatibleBitmap(pDC, Width, Height); oldmemBitmap = memDC.SelectObject(&memBitmap);//将memBitmap选入内存DC memDC.BitBlt(0, 0, Width, Height, pDC, 0, 0, SRCCOPY);//复制屏幕图像到内存DC //以下代码保存memDC中的位图到文件 BITMAP bmp; memBitmap.GetBitmap(&bmp);//获得位图信息 FILE *fp = fopen(filename, "w+b"); BITMAPINFOHEADER bih = {0};//位图信息头 bih.biBitCount = bmp.bmBitsPixel;//每个像素字节大小 bih.biCompression = BI_RGB; bih.biHeight = bmp.bmHeight;//高度 bih.biPlanes = 1; bih.biSize = sizeof(BITMAPINFOHEADER); bih.biSizeImage = bmp.bmWidthBytes * bmp.bmHeight;//图像数据大小 bih.biWidth = bmp.bmWidth;//宽度 BITMAPFILEHEADER bfh = {0};//位图文件头 bfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);//到位图数据的偏移量 bfh.bfSize = bfh.bfOffBits + bmp.bmWidthBytes * bmp.bmHeight;//文件总的大小 bfh.bfType = (WORD)0x4d42; fwrite(&bfh, 1, sizeof(BITMAPFILEHEADER), fp);//写入位图文件头 fwrite(&bih, 1, sizeof(BITMAPINFOHEADER), fp);//写入位图信息头 byte * p = new byte[bmp.bmWidthBytes * bmp.bmHeight];//申请内存保存位图数据 GetDIBits(memDC.m_hDC, (HBITMAP) memBitmap.m_hObject, 0, Height, p, (LPBITMAPINFO) &bih, DIB_RGB_COLORS);//获取位图数据 fwrite(p, 1, bmp.bmWidthBytes * bmp.bmHeight, fp);//写入位图数据 delete [] p; fclose(fp); memDC.SelectObject(oldmemBitmap); } (五)改进 可以在系统热键中加入自定义热键,进行动态的(按用户需要的)截屏操作。 |
|
|
[ 联系联盟系统管理团队 -
中国DOS联盟 -
标准版 ] Sponsored by ifanr Inc | © 2001–2023 |