Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.51 KB | None | 0 0
  1. [StructLayout(LayoutKind.Sequential)]
  2. public struct RECT
  3. {
  4. private int _Left;
  5. private int _Top;
  6. private int _Right;
  7. private int _Bottom;
  8.  
  9. public RECT(RECT Rectangle) : this(Rectangle.Left, Rectangle.Top, Rectangle.Right, Rectangle.Bottom)
  10. {
  11. }
  12. public RECT(int Left, int Top, int Right, int Bottom)
  13. {
  14. _Left = Left;
  15. _Top = Top;
  16. _Right = Right;
  17. _Bottom = Bottom;
  18. }
  19.  
  20. public int X {
  21. get { return _Left; }
  22. set { _Left = value; }
  23. }
  24. public int Y {
  25. get { return _Top; }
  26. set { _Top = value; }
  27. }
  28. public int Left {
  29. get { return _Left; }
  30. set { _Left = value; }
  31. }
  32. public int Top {
  33. get { return _Top; }
  34. set { _Top = value; }
  35. }
  36. public int Right {
  37. get { return _Right; }
  38. set { _Right = value; }
  39. }
  40. public int Bottom {
  41. get { return _Bottom; }
  42. set { _Bottom = value; }
  43. }
  44. public int Height {
  45. get { return _Bottom - _Top; }
  46. set { _Bottom = value + _Top; }
  47. }
  48. public int Width {
  49. get { return _Right - _Left; }
  50. set { _Right = value + _Left; }
  51. }
  52. public Point Location {
  53. get { return new Point(Left, Top); }
  54. set {
  55. _Left = value.X;
  56. _Top = value.Y;
  57. }
  58. }
  59. public Size Size {
  60. get { return new Size(Width, Height); }
  61. set {
  62. _Right = value.Width + _Left;
  63. _Bottom = value.Height + _Top;
  64. }
  65. }
  66.  
  67. public static implicit operator Rectangle(RECT Rectangle)
  68. {
  69. return new Rectangle(Rectangle.Left, Rectangle.Top, Rectangle.Width, Rectangle.Height);
  70. }
  71. public static implicit operator RECT(Rectangle Rectangle)
  72. {
  73. return new RECT(Rectangle.Left, Rectangle.Top, Rectangle.Right, Rectangle.Bottom);
  74. }
  75. public static bool operator ==(RECT Rectangle1, RECT Rectangle2)
  76. {
  77. return Rectangle1.Equals(Rectangle2);
  78. }
  79. public static bool operator !=(RECT Rectangle1, RECT Rectangle2)
  80. {
  81. return !Rectangle1.Equals(Rectangle2);
  82. }
  83.  
  84. public override string ToString()
  85. {
  86. return "{Left: " + _Left + "; " + "Top: " + _Top + "; Right: " + _Right + "; Bottom: " + _Bottom + "}";
  87. }
  88.  
  89. public override int GetHashCode()
  90. {
  91. return ToString().GetHashCode();
  92. }
  93.  
  94. public bool Equals(RECT Rectangle)
  95. {
  96. return Rectangle.Left == _Left && Rectangle.Top == _Top && Rectangle.Right == _Right && Rectangle.Bottom == _Bottom;
  97. }
  98.  
  99. public override bool Equals(object Object)
  100. {
  101. if (Object is RECT) {
  102. return Equals((RECT)Object);
  103. } else if (Object is Rectangle) {
  104. return Equals(new RECT((Rectangle)Object));
  105. }
  106.  
  107. return false;
  108. }
  109. }
  110.  
  111. [DllImport("user32.dll")]
  112. public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
  113. [DllImport("user32.dll")]
  114. public static extern bool PrintWindow(IntPtr hWnd, IntPtr hdcBlt, int nFlags);
  115.  
  116. public static Bitmap PrintWindow(IntPtr hwnd)
  117. {
  118. RECT rc;
  119. GetWindowRect(hwnd, out rc);
  120.  
  121. Bitmap bmp = new Bitmap(rc.Width, rc.Height, PixelFormat.Format32bppArgb);
  122. Graphics gfxBmp = Graphics.FromImage(bmp);
  123. IntPtr hdcBitmap = gfxBmp.GetHdc();
  124.  
  125. PrintWindow(hwnd, hdcBitmap, 0);
  126.  
  127. gfxBmp.ReleaseHdc(hdcBitmap);
  128. gfxBmp.Dispose();
  129.  
  130. }
  131.  
  132. pictureBox.Image = myBitmap.Clone(
  133. new Rectangle(0, 0, myBitmap.Width, myBitmap.Height),
  134. System.Drawing.Imaging.PixelFormat.DontCare);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement