将屏幕保存为图片,使用vs2008编译通过。
#include "stdafx.h"
#include <windows.h>
#include <atlimage.h>
int __stdcall WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd)
{
HWND hwnd = ::GetDesktopWindow();
HDC hDC = ::GetDC(hwnd);//获取屏幕DC
RECT rect;
::GetClientRect(hwnd, &rect);//获取屏幕大小
HDC hDCMem = ::CreateCompatibleDC(hDC);//创建兼容DC
HBITMAP hBitMap = ::CreateCompatibleBitmap(hDC, rect.right, rect.bottom);//创建兼容位图
HBITMAP hOldMap = (HBITMAP)::SelectObject(hDCMem, hBitMap);//将位图选入DC,并保存返回值
::BitBlt(hDCMem, 0, 0, rect.right, rect.bottom, hDC, 0, 0, SRCCOPY);//将屏幕DC的图象复制到内存DC中
CImage image; <
#include "stdafx.h"
#include <windows.h>
#include <atlimage.h>
int __stdcall WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd)
{
HWND hwnd = ::GetDesktopWindow();
HDC hDC = ::GetDC(hwnd);//获取屏幕DC
RECT rect;
::GetClientRect(hwnd, &rect);//获取屏幕大小
HDC hDCMem = ::CreateCompatibleDC(hDC);//创建兼容DC
HBITMAP hBitMap = ::CreateCompatibleBitmap(hDC, rect.right, rect.bottom);//创建兼容位图
HBITMAP hOldMap = (HBITMAP)::SelectObject(hDCMem, hBitMap);//将位图选入DC,并保存返回值
::BitBlt(hDCMem, 0, 0, rect.right, rect.bottom, hDC, 0, 0, SRCCOPY);//将屏幕DC的图象复制到内存DC中
CImage image; <