/// <summary> /// 截一张图用作识别 /// </summary> private void getPicture() { IntPtr hWnd = WindowsAPI.FindWindow(null, "夜神模拟器"); IntPtr hscrdc = WindowsAPI.GetWindowDC(hWnd); System.Drawing.Rectangle rect = new System.Drawing.Rectangle(); WindowsAPI.GetWindowRect(hWnd, out rect); System.Drawing.Bitmap bmp = null; if (Config.ScreenMode == ScreenMode.Window) { IntPtr hbitmap = WindowsAPI.CreateCompatibleBitmap(hscrdc, rect.Width, rect.Height); IntPtr hmemdc = WindowsAPI.CreateCompatibleDC(hscrdc); WindowsAPI.SelectObject(hmemdc, hbitmap); WindowsAPI.PrintWindow(hWnd, hmemdc, 0); bmp = System.Drawing.Bitmap.FromHbitmap(hbitmap); WindowsAPI.DeleteDC(hmemdc); } else if (Config.ScreenMode == ScreenMode.Desktop) { bmp = WindowsAPI.GetDesktop(rect); } if (File.Exists(TempImages.OrigImagePath)) { File.Delete(TempImages.OrigImagePath); } if (bmp != null) { bmp.Save(TempImages.OrigImagePath); bmp.Dispose(); bmp = null; } WindowsAPI.DeleteDC(hscrdc); }
/// <summary> /// 释放资源 /// </summary> public static void Dispose() { WindowsAPI.DeleteDC(windowHand); WindowsAPI.DeleteDC(windowDC); WindowsAPI.DeleteDC(bitmapHand); WindowsAPI.DeleteDC(bitmapDC); }
/// <summary> /// 获取模拟器的大小 /// </summary> /// <returns></returns> private System.Drawing.Rectangle getVriualSize() { IntPtr hWnd = WindowsAPI.FindWindow(null, "夜神模拟器"); IntPtr hscrdc = WindowsAPI.GetWindowDC(hWnd); System.Drawing.Rectangle rect = new System.Drawing.Rectangle(); WindowsAPI.GetWindowRect(hWnd, out rect); WindowsAPI.DeleteDC(hscrdc); return(rect); }
/// <summary> /// 运行前初始化 /// </summary> private void InitVriual() { IntPtr hWnd = WindowsAPI.FindWindow(null, "夜神模拟器"); IntPtr hscrdc = WindowsAPI.GetWindowDC(hWnd); System.Drawing.Rectangle rect = new System.Drawing.Rectangle(); WindowsAPI.GetWindowRect(hWnd, out rect); WindowsAPI.MoveWindow(hWnd, 0, 0, DefultRectangle.Width, DefultRectangle.Height, true); WindowsAPI.DeleteDC(hscrdc); isStopTask = false; selectedBar.IsEnabled = false; fwSelected.IsEnabled = false; runTask.IsEnabled = false; }