对不起,不好意思,忘贴了一段API调用
struct GetDeviceCapsIndex
{
public static readonly int DRIVERVERSION = 0;
public static readonly int HORZSIZE = 4;
public static readonly int VERTSIZE = 6;
public static readonly int HORZRES = 8;
public static readonly int VERTRES = 10;
}
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
public struct LUID
{
public uint LowPart;
public uint HighPart;
}
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
public struct TOKEN_PRIVILEGES
{
public uint PrivilegeCount;
public LUID Luid;
public uint Attributes;
}
public class Win32API
{
[DllImport("Advapi32", CharSet=CharSet.Auto)]
public static extern bool LookupPrivilegeValue (string sysname,string privname,ref LUID luid);
[DllImport("kernel32.dll")]
public static extern int GetLastError();
[DllImport("user32.dll")]
public static extern bool ExitWindowsEx(int uFlags, int dwReason);
[DllImport("gdi32.dll")]
public static extern IntPtr CreateDC(
string lpszDriver, // driver name
string lpszDevice, // device name
string lpszOutput, // not used; should be NULL
Int64 lpInitData // optional printer data
);
[DllImport("gdi32.dll")]
public static extern IntPtr CreateCompatibleDC(
IntPtr hdc // handle to DC
);
[DllImport("gdi32.dll")]
public static extern int GetDeviceCaps(
IntPtr hdc, // handle to DC
int nIndex // index of capability
);
[DllImport("gdi32.dll")]
public static extern IntPtr CreateCompatibleBitmap(
IntPtr hdc, // handle to DC
int nWidth, // width of bitmap, in pixels
int nHeight // height of bitmap, in pixels
);
[DllImport("gdi32.dll")]
public static extern IntPtr SelectObject(
IntPtr hdc, // handle to DC
IntPtr hgdiobj // handle to object
);
[DllImport("gdi32.dll")]
public static extern int BitBlt(
IntPtr hdcDest, // handle to destination DC
int nXDest, // x-coord of destination upper-left corner
int nYDest, // y-coord of destination upper-left corner
int nWidth, // width of destination rectangle
int nHeight, // height of destination rectangle
IntPtr hdcSrc, // handle to source DC
int nXSrc, // x-coordinate of source upper-left corner
int nYSrc, // y-coordinate of source upper-left corner
UInt32 dwRop // raster operation code
);
[DllImport("gdi32.dll")]
public static extern int DeleteDC(
IntPtr hdc // handle to DC
);
}
public class GDI
{
public static Bitmap GetScreen()
{
IntPtr hscrdc,hmemdc;
IntPtr hbitmap,holdbitmap;
int nx,ny,nx2,ny2;
nx=ny=nx2=ny2=0;
int nwidth, nheight;
int xscrn, yscrn;
hscrdc = Win32API.CreateDC("DISPLAY", null, null, 0);//创建DC句柄
hmemdc = Win32API.CreateCompatibleDC(hscrdc);//创建一个内存DC
xscrn = Win32API.GetDeviceCaps(hscrdc, GetDeviceCapsIndex.HORZRES);//获取屏幕宽度
yscrn = Win32API.GetDeviceCaps(hscrdc, GetDeviceCapsIndex.VERTRES);//获取屏幕高度
nx = 0;
ny = 0;
nx2 = xscrn;
ny2 = yscrn;