///////////////////////////////////////////////////////////////////////// // // www.ultima.smoce.net // Name: Snap // ///////////////////////////////////////////////////////////////////////// using System; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Runtime.InteropServices; using System.Threading; namespace Phoenix.Plugins { public static partial class Commands { [Command] public static void Snap() { SaveScreenshot(CaptureWindow(Client.HWND)); } [Command] public static void SnapAll() { SaveScreenshot(CaptureWindow(User32.GetDesktopWindow())); } private static void SaveScreenshot(Image img) { DirectoryInfo dir = new DirectoryInfo(Path.Combine(Core.Directory, "Screenshots")); dir.Create(); string name = "Momentka_" + DateTime.Now.ToString(@"[yyyy-MM-dd]_HH-mm-ss") + ".jpg"; new Thread(() => { img.Save(Path.Combine(dir.FullName, name), ImageFormat.Jpeg); UO.Print(0x06EA,"Screenshot byl ulozen."); }).Start(); } private static Image CaptureWindow(IntPtr handle) { IntPtr hdcSrc = User32.GetWindowDC(handle); User32.RECT windowRect = new User32.RECT(); User32.GetWindowRect(handle, ref windowRect); int width = windowRect.right - windowRect.left; int height = windowRect.bottom - windowRect.top; IntPtr hdcDest = GDI32.CreateCompatibleDC(hdcSrc); IntPtr hBitmap = GDI32.CreateCompatibleBitmap(hdcSrc, width, height); IntPtr hOld = GDI32.SelectObject(hdcDest, hBitmap); GDI32.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, 0, 0, GDI32.SRCCOPY); GDI32.SelectObject(hdcDest, hOld); GDI32.DeleteDC(hdcDest); User32.ReleaseDC(handle, hdcSrc); Image img = Image.FromHbitmap(hBitmap); GDI32.DeleteObject(hBitmap); return img; } } public class GDI32 { public const int SRCCOPY = 0x00CC0020; [DllImport("gdi32.dll")] public static extern bool BitBlt(IntPtr hObject, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hObjectSource, int nXSrc, int nYSrc, int dwRop); [DllImport("gdi32.dll")] public static extern IntPtr CreateCompatibleBitmap(IntPtr hDC, int nWidth, int nHeight); [DllImport("gdi32.dll")] public static extern IntPtr CreateCompatibleDC(IntPtr hDC); [DllImport("gdi32.dll")] public static extern bool DeleteDC(IntPtr hDC); [DllImport("gdi32.dll")] public static extern bool DeleteObject(IntPtr hObject); [DllImport("gdi32.dll")] public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject); } public class User32 { [DllImport("user32.dll")] public static extern IntPtr GetDesktopWindow(); [DllImport("user32.dll")] public static extern IntPtr GetWindowDC(IntPtr hWnd); [DllImport("user32.dll")] public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDC); [DllImport("user32.dll")] public static extern IntPtr GetWindowRect(IntPtr hWnd, ref RECT rect); #region Nested type: RECT [StructLayout(LayoutKind.Sequential)] public struct RECT { public int left; public int top; public int right; public int bottom; } #endregion } }