using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace ConsoleApplication1
{
class Program
{
//Win32 API
[DllImport("User32.dll")]
public static extern int GetSystemMetrics(int nIndex);
static void Main(string[] args)
{
int Width, Height;
double LineWidth, Size;
Width = GetSystemMetrics(0);
Height = GetSystemMetrics(1);
//验证
Console.WriteLine("{0}*{1}", Width, Height);
Console.ReadKey();
LineWidth = (((Width * 24) + 31) & (0x7FFFFFFF - 31)) >> 3; //对齐后每行数据长度
Size = LineWidth * Height;
//验证
Console.WriteLine("{0};{1}", LineWidth, Size);
Console.ReadKey();
GetMem(Bits, Size);//动态分布内存
//截图
Wnd = GetDesktopWindow(); //获取桌面句柄
DC = GetWindowDC(Wnd); //返回hWnd参数所指定的窗口的设备环境
MemDC = CreateCompatibleDC(DC); //该函数创建一个与指定设备兼容的内存设备上下文环境
Bitmap = CreateCompatibleBitmap(DC, Width, Height); //创建与指定的设备环境相关的设备兼容的位图
OldBitmap = SelectObject(MemDC, Bitmap); //选择一对象到指定的设备上下文环境中
BitBlt(MemDC, 0, 0, Width, Height, DC, 0, 0, SRCCOPY); //
Bitmap = SelectObject(MemDC, OldBitmap);
}
}
}
哎,忘了写错了啥,估计这篇又丢图了
作者:꧁执笔小白꧂