mirror of https://github.com/quasar/Quasar.git
Fixed #294
This commit is contained in:
parent
cf16e57d9e
commit
db2c7e8adf
|
@ -62,7 +62,7 @@ public static void HandleGetDesktop(Packets.ServerPackets.GetDesktop command, Cl
|
|||
Bitmap desktop = null;
|
||||
try
|
||||
{
|
||||
desktop = RemoteDesktopHelper.GetDesktop(command.Monitor);
|
||||
desktop = RemoteDesktopHelper.CaptureScreen(command.Monitor);
|
||||
desktopData = desktop.LockBits(new Rectangle(0, 0, desktop.Width, desktop.Height),
|
||||
ImageLockMode.ReadWrite, desktop.PixelFormat);
|
||||
|
||||
|
|
|
@ -1,20 +1,33 @@
|
|||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using xClient.Core.Utilities;
|
||||
|
||||
namespace xClient.Core.Helper
|
||||
{
|
||||
public static class RemoteDesktopHelper
|
||||
{
|
||||
public static Bitmap GetDesktop(int screenNumber)
|
||||
private const int SRCCOPY = 0x00CC0020;
|
||||
|
||||
public static Bitmap CaptureScreen(int screenNumber)
|
||||
{
|
||||
var bounds = GetBounds(screenNumber);
|
||||
var screenshot = new Bitmap(bounds.Width, bounds.Height, PixelFormat.Format32bppArgb);
|
||||
using (Graphics graph = Graphics.FromImage(screenshot))
|
||||
Rectangle bounds = GetBounds(screenNumber);
|
||||
IntPtr desktopHandle = NativeMethods.GetDesktopWindow();
|
||||
Bitmap screen = new Bitmap(bounds.Width, bounds.Height);
|
||||
|
||||
using (Graphics g = Graphics.FromImage(screen))
|
||||
{
|
||||
graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy);
|
||||
return screenshot;
|
||||
IntPtr destDeviceContext = g.GetHdc();
|
||||
IntPtr srcDeviceContext = NativeMethods.GetWindowDC(desktopHandle);
|
||||
|
||||
NativeMethods.BitBlt(destDeviceContext, 0, 0, bounds.Width, bounds.Height, srcDeviceContext, bounds.X,
|
||||
bounds.Y, SRCCOPY);
|
||||
NativeMethods.ReleaseDC(desktopHandle, srcDeviceContext);
|
||||
|
||||
g.ReleaseHdc(destDeviceContext);
|
||||
}
|
||||
|
||||
return screen;
|
||||
}
|
||||
|
||||
public static Rectangle GetBounds(int screenNumber)
|
||||
|
|
|
@ -18,6 +18,36 @@ public static class NativeMethods
|
|||
[DllImport("user32.dll")]
|
||||
public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = false)]
|
||||
public static extern IntPtr GetDesktopWindow();
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr GetWindowDC(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern bool ReleaseDC(IntPtr hWnd, IntPtr hDC);
|
||||
|
||||
/// <summary>
|
||||
/// Performs a bit-block transfer of the color data corresponding to a
|
||||
/// rectangle of pixels from the specified source device context into
|
||||
/// a destination device context.
|
||||
/// </summary>
|
||||
/// <param name="hdc">Handle to the destination device context.</param>
|
||||
/// <param name="nXDest">The leftmost x-coordinate of the destination rectangle (in pixels).</param>
|
||||
/// <param name="nYDest">The topmost y-coordinate of the destination rectangle (in pixels).</param>
|
||||
/// <param name="nWidth">The width of the source and destination rectangles (in pixels).</param>
|
||||
/// <param name="nHeight">The height of the source and the destination rectangles (in pixels).</param>
|
||||
/// <param name="hdcSrc">Handle to the source device context.</param>
|
||||
/// <param name="nXSrc">The leftmost x-coordinate of the source rectangle (in pixels).</param>
|
||||
/// <param name="nYSrc">The topmost y-coordinate of the source rectangle (in pixels).</param>
|
||||
/// <param name="dwRop">A raster-operation code.</param>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the operation succeedes, <c>false</c> otherwise. To get extended error information, call <see cref="System.Runtime.InteropServices.Marshal.GetLastWin32Error"/>.
|
||||
/// </returns>
|
||||
[DllImport("gdi32.dll", EntryPoint = "BitBlt", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool BitBlt([In] IntPtr hdc, int nXDest, int nYDest, int nWidth, int nHeight, [In] IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
|
||||
|
||||
[DllImport("msvcrt.dll", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern unsafe int memcmp(byte* ptr1, byte* ptr2, uint count);
|
||||
|
||||
|
|
|
@ -93,7 +93,13 @@ public void UpdateImage(Bitmap bmp, bool cloneBitmap = false)
|
|||
CountFps();
|
||||
picDesktop.Invoke((MethodInvoker) delegate
|
||||
{
|
||||
// get old image to dispose it correctly
|
||||
var oldImage = picDesktop.Image;
|
||||
|
||||
picDesktop.Image = cloneBitmap ? (Bitmap) bmp.Clone() : bmp;
|
||||
|
||||
if (oldImage != null)
|
||||
oldImage.Dispose();
|
||||
});
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
|
|
Loading…
Reference in New Issue