public void ClickWindow(IntPtr wh) { Native.RECT rect = new Native.RECT(); if (!Native.GetWindowRect(new HandleRef(null, wh), out rect)) { throw new Win32Exception(Marshal.GetLastWin32Error()); } Rectangle windowSize = rect.ToRectangle(); int y = 20; int x = 20; Native.PostMessage(wh, Native.WM_LBUTTONDOWN, 0, Native.MakeLParam(x, y)); Thread.Sleep(100); Native.PostMessage(wh, Native.WM_LBUTTONUP, 0, Native.MakeLParam(x, y)); Thread.Sleep(100); }
private Bitmap GetScreenshot(IntPtr hwnd) { Native.RECT rect = new Native.RECT(); if (!Native.GetWindowRect(new HandleRef(null, hwnd), out rect)) { throw new Win32Exception(Marshal.GetLastWin32Error()); } Thread.Sleep(500); Rectangle windowSize = rect.ToRectangle(); Bitmap target = new Bitmap(windowSize.Width, windowSize.Height); using (Graphics g = Graphics.FromImage(target)) { g.CopyFromScreen(windowSize.X, windowSize.Y, 0, 0, new System.Drawing.Size(windowSize.Width, windowSize.Height)); } return(target); }