C++截取整个屏幕,并生成图片(基于MFC)
2016-09-20 15:58
357 查看
第一步:建立Windows 32控制台控制程序 |
第二部:设置工程的属性如下:MFC的使用 --> 在共享 DLL 中使用 MFC |
stdafx.h |
#pragma once #define WIN32_LEAN_AND_MEAN // 从 Windows 头中排除极少使用的资料 #include <tchar.h> |
ScreenCapture.cpp:此文件主要是调用截屏方法 |
// ScreenCapture.cpp : 定义控制台应用程序的入口点。 #include "stdafx.h" #include "SC.h" #include <windows.h> int _tmain(int argc, _TCHAR* argv[]) { Sleep(10000); Screen("aa.jpg"); return 0; } |
SC.h |
void Screen(char filename[]); |
SC.cpp |
#include "stdafx.h" #include <afxwin.h> 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); printf("当前屏幕色彩模式为%d位色彩n", BitPerPixel); printf("屏幕宽度:%dn", Width); printf("屏幕高度:%dn", Height); 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 |
相关文章推荐
- [转载]MFC截屏之一:C++截取整个屏幕,并生成图片(基于MFC)
- vc截取整个屏幕保存成bmp图片
- c++截取屏幕图片并保存(函数代码实现)
- 将屏幕保存为图片 将当前MFC程序保存为图片 c++ vc
- c++截取屏幕图片并保存(函数代码实现)
- c++ 截取屏幕图片并保存
- 将屏幕保存为图片 将当前MFC程序保存为图片 c++ vc
- C++ 在Windows下截取整个屏幕 和 指定句柄窗口的屏幕
- 安卓开发截取当前屏幕图片及截取整个ListView图片并保存到本地
- c++截取屏幕图片并保存(函数代码实现)
- iOS怎样截取屏幕并生成图片?
- 【框架-MFC】截取整个屏幕,伪造桌面
- iOS怎样截取屏幕并生成图片?
- 将屏幕保存为图片 将当前MFC程序保存为图片 c++ vc
- 将屏幕保存为图片 将当前MFC程序保存为图片 c++ vc
- 视频管理模块代码总结 (1)对上传的flash截取视频并自动生成图片
- C#截取当前屏幕界面作为图片保存
- 用Cocoa截取屏幕内容并保存为图片
- ListView,实现滚动分页效果。实现异步加载URL生成的图片。使得屏幕不卡
- 截取屏幕图片