private static void Centering() { // ペイントの中央揃え using (var process = Process.GetProcessesByName("mspaint").FirstOrDefault()) { if (process == null) { Console.WriteLine($"No process."); return; } var windowHandle = process.MainWindowHandle; var clientPoint = new NetCoreEx.Geometry.Point(0, 0); User32Methods.GetClientRect(windowHandle, out var clientRect); User32Methods.ClientToScreen(windowHandle, ref clientPoint); Console.WriteLine($"clientRect: {clientRect.ToString()}"); Console.WriteLine($"clientPoint: {clientPoint.ToString()}"); var screen = Screen.PrimaryScreen; Console.WriteLine($"PrimaryScreen: {screen.Bounds.ToString()}"); // 小数点以下は切り捨て var x = (screen.Bounds.Width - clientRect.Width) / 2; var y = (screen.Bounds.Height - clientRect.Height) / 2; Console.WriteLine($"Move to ({x}, {y})"); // Move Window User32Methods.MoveWindow(windowHandle, x, y, clientRect.Width, clientRect.Height, true); } }
public Rectangle GetClientRect() { Rectangle rectangle; User32Methods.GetClientRect(this.Handle, out rectangle); return(rectangle); }
/// <summary> /// The get client size. /// </summary> /// <returns> /// The <see cref="Size"/>. /// </returns> public Size GetClientSize() { var size = new Size(); if (Handle != IntPtr.Zero) { User32Methods.GetClientRect(Handle, out var rectangle); size.Width = rectangle.Width; size.Height = rectangle.Height; } return(size); }
public static void ProcessPaint(ref PaintPacket packet, NativePixelBuffer pixelBuffer, Action <SKSurface> handler) { var hwnd = packet.Hwnd; Rectangle clientRect; User32Methods.GetClientRect(hwnd, out clientRect); var size = clientRect.Size; pixelBuffer.EnsureSize(size.Width, size.Height); PaintStruct ps; var hdc = User32Methods.BeginPaint(hwnd, out ps); var skPainted = false; try { using (var surface = SKSurface.Create( size.Width, size.Height, SKColorType.Bgra8888, SKAlphaType.Premul, pixelBuffer.Handle, pixelBuffer.Stride)) { if (surface != null) { handler(surface); skPainted = true; } } } finally { if (skPainted) { Gdi32Helpers.SetRgbBitsToDevice(hdc, size.Width, size.Height, pixelBuffer.Handle); } User32Methods.EndPaint(hwnd, ref ps); } }
public static unsafe void ProcessPaint(ref PaintPacket packet, NativePixelBuffer pixelBuffer, Action <SKSurface> handler) { var hwnd = packet.Hwnd; Rectangle clientRect; User32Methods.GetClientRect(hwnd, out clientRect); var size = clientRect.Size; pixelBuffer.EnsureSize(size.Width, size.Height); PaintStruct ps; var hdc = User32Methods.BeginPaint(hwnd, out ps); var skPainted = false; try { using (var surface = SKSurface.Create( size.Width, size.Height, SKColorType.Bgra8888, SKAlphaType.Premul, pixelBuffer.Handle, pixelBuffer.Stride)) { if (surface != null) { handler(surface); /* * foreach (var VARIABLE in Enumerable.Range(0, pixelBuffer.Stride * size.Height / 4)) * { * var value = Marshal.ReadInt32(pixelBuffer.Handle, VARIABLE*4); * // ABGR >> ARGB * unchecked * { * value = ((value & (int)0xff000000) >> 0) + * ((value & 0xff0000) >> 16 )+ * ((value & 0xff00) << 0) + * ((value & 0xff) << 16); * } * * Marshal.WriteInt32(pixelBuffer.Handle, VARIABLE * 4, value); * }*/ var max = pixelBuffer.Stride * size.Height / 4; int *arr = (int *)pixelBuffer.Handle.ToPointer(); unchecked { var a = 0; while (a < max) {/* * arr = ((*arr & (int) 0xff000000) >> 0) + * ((*arr & 0xff0000) >> 16) + * ((*arr & 0xff00) << 0) + * ((*arr & 0xff) << 16); * arr++;*/ a++; } } skPainted = true; } } } finally { if (skPainted) { Gdi32Helpers.SetRgbBitsToDevice(hdc, size.Width, size.Height, pixelBuffer.Handle); } User32Methods.EndPaint(hwnd, ref ps); } }
public bool GetClientRect(out Rectangle rectangle) { return(User32Methods.GetClientRect(this.Handle, out rectangle)); }