int main()
{
HDC hdcSrc = GetDC(NULL);
int nBitPerPixel = GetDeviceCaps(hdcSrc, BITSPIXEL);
int nWidth = GetDeviceCaps(hdcSrc, HORZRES);
int nHeight = GetDeviceCaps(hdcSrc, VERTRES);
CImage image;
image.Create(nWidth, nHeight, nBitPerPixel);
BitBlt(image.GetDC(), 0, 0, nWidth, nHeight, hdcSrc, 0, 0, SRCCOPY);
ReleaseDC(NULL, hdcSrc);
image.ReleaseDC();
image.Save(L"1.png", Gdiplus::ImageFormatPNG);//ImageFormatJPEG
return 0;
{
HDC hdcSrc = GetDC(NULL);
int nBitPerPixel = GetDeviceCaps(hdcSrc, BITSPIXEL);
int nWidth = GetDeviceCaps(hdcSrc, HORZRES);
int nHeight = GetDeviceCaps(hdcSrc, VERTRES);
CImage image;
image.Create(nWidth, nHeight, nBitPerPixel);
BitBlt(image.GetDC(), 0, 0, nWidth, nHeight, hdcSrc, 0, 0, SRCCOPY);
ReleaseDC(NULL, hdcSrc);
image.ReleaseDC();
image.Save(L"1.png", Gdiplus::ImageFormatPNG);//ImageFormatJPEG
return 0;
}
http://blog.youkuaiyun.com/chinafe/article/details/16940585
注意:HDC hdcSrc = GetDC(NULL); 和 ReleaseDC(NULL, hdcSrc);语句中的NULL是替代参数,在此位置应根据需要提供要截屏的窗口DC。

本文介绍了一个使用C++实现的屏幕截图程序。通过GetDC获取设备上下文,利用GetDeviceCaps获取屏幕宽度、高度及每像素位数等信息,并创建位图进行截图。最后将截图保存为PNG文件。
1077

被折叠的 条评论
为什么被折叠?



