Window screenshot using WinAPI

How to take a screenshot of a program window using WinAPI and C #?

I am sending a message WM_PAINT (0x000F)to a window that I want to take off the screen wParam = HDC, but not a screenshot in my box. If I send a message WM_CLOSE, all deviations (target window closes). What am I doing wrong with WM_PAINT? Maybe HDC is not a component of PictureBox (WinForms)? P.SGetLastError() == ""

[DllImport("User32.dll")]
public static extern Int64 SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
  .....

SendMessage(targetWindowHandle, 0x000F, pictureBox.Handle, IntPtr.Zero);
+2
source share
3 answers

pictureBox.HandleIt is a window handle, not a DC handle. There are several online tutorials for creating screenshots. One of them is here . See Also @ In the silicone answer.

+1
source

. 100x100, , . Graphics.CopyFromScreen

  Bitmap bmp = new Bitmap(100,100);
  using (Graphics g = Graphics.FromImage(bmp))
  {
    g.CopyFromScreen(0, 0, 0, 0, new Size(100, 100));        
  }
  pictureBox1.Image = bmp;
+2

Source: https://habr.com/ru/post/1794706/


All Articles