using System; using System.Linq; using System.Collections.Generic; using System.Drawing; using System.Text; using System.Runtime.InteropServices; using System.Windows.Forms; namespace INT69DB_2A { public static class IntechGraphics { public enum TernaryRasterOperations : uint { /// dest = source SRCCOPY = 0x00CC0020, /// dest = source OR dest SRCPAINT = 0x00EE0086, /// dest = source AND dest SRCAND = 0x008800C6, /// dest = source XOR dest SRCINVERT = 0x00660046, /// dest = source AND (NOT dest) SRCERASE = 0x00440328, /// dest = (NOT source) NOTSRCCOPY = 0x00330008, /// dest = (NOT src) AND (NOT dest) NOTSRCERASE = 0x001100A6, /// dest = (source AND pattern) MERGECOPY = 0x00C000CA, /// dest = (NOT source) OR dest MERGEPAINT = 0x00BB0226, /// dest = pattern PATCOPY = 0x00F00021, /// dest = DPSnoo PATPAINT = 0x00FB0A09, /// dest = pattern XOR dest PATINVERT = 0x005A0049, /// dest = (NOT dest) DSTINVERT = 0x00550009, /// dest = BLACK BLACKNESS = 0x00000042, /// dest = WHITE WHITENESS = 0x00FF0062 } [DllImport("Coredll.dll")] private static extern IntPtr GetDC(IntPtr hWnd); [DllImport("Coredll.dll")] private static extern IntPtr CreateCompatibleDC(IntPtr hdc); [DllImport("coredll.dll")] private static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidth, int nHeight); [DllImport("coredll.dll")] private static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject); [DllImport("coredll.dll")] private static extern int BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, uint dwRop); [DllImport("coredll.dll")] private static extern int DeleteDC(IntPtr hdc); [DllImport("coredll.dll")] private static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDC); [DllImport("coredll.dll")] private static extern IntPtr DeleteObject(IntPtr hObject); public static Bitmap CopyFromScreen() { int width = Screen.PrimaryScreen.Bounds.Width; int height = Screen.PrimaryScreen.Bounds.Height; IntPtr hBitmap; IntPtr hDC = GetDC(IntPtr.Zero); IntPtr hMemDC = CreateCompatibleDC(hDC); hBitmap = CreateCompatibleBitmap(hDC, width, height); if (hBitmap != IntPtr.Zero) { IntPtr hOld = (IntPtr)SelectObject(hMemDC, hBitmap); BitBlt(hMemDC, 0, 0, width, height, hDC, 0, 0, (uint)TernaryRasterOperations.SRCCOPY); SelectObject(hMemDC, hOld); DeleteDC(hMemDC); ReleaseDC(IntPtr.Zero, hDC); Bitmap bmp = System.Drawing.Image.FromHbitmap(hBitmap); DeleteObject(hBitmap); return bmp; } return null; } } }