private void m_timer_Tick(object sender, EventArgs e) { if (!m_running) { return; } try { Rectangle window_rect = Win32Helper.GetWindowRect(m_process_whnd); Bitmap bitmap = Win32Helper.CaptureWindow(m_process_whnd); if (bitmap == null) { StopRunning(); ShowErrorMessage("Failed to capture the window."); return; } JewelMatcher.Solution solution = m_matcher.GetSolution(bitmap); bitmap.Dispose(); Point point_src = solution.PointSrc; point_src.X += window_rect.Left; point_src.Y += window_rect.Top; Point point_dst = solution.PointDst; point_dst.X += window_rect.Left; point_dst.Y += window_rect.Top; if (point_src.X <= window_rect.Left || point_src.X >= window_rect.Right || point_src.Y <= window_rect.Top || point_src.Y >= window_rect.Bottom || point_dst.X <= window_rect.Left || point_dst.X >= window_rect.Right || point_dst.Y <= window_rect.Top || point_dst.Y >= window_rect.Bottom) { StopRunning(); ShowErrorMessage("Internal Error."); return; } Cursor.Position = point_src; Win32Helper.MouseDown(); System.Threading.Thread.Sleep(m_time_move); Cursor.Position = point_dst; Win32Helper.MouseUp(); } catch (Exception) { /* * StopRunning(); * ShowErrorMessage("Exception: " + exp.Message); */ // do nothing } }
public static Bitmap CaptureHandle(IntPtr hWnd) { Bitmap bitmap = null; try { Rectangle rect = Win32Helper.GetWindowRect(hWnd); Graphics g_hwnd = Graphics.FromHwnd(hWnd); bitmap = new Bitmap(rect.Width, rect.Height, g_hwnd); Graphics g_bitmap = Graphics.FromImage(bitmap); g_bitmap.CopyFromScreen(rect.X, rect.Y, 0, 0, rect.Size, CopyPixelOperation.SourceCopy); g_bitmap.Dispose(); g_hwnd.Dispose(); } catch (Exception exp) { throw exp; } return(bitmap); }