public static Bitmap Take_Snapshot_Process(Process_Object proc) { int is_success = 0; WindowsStructs.RECT window_dimensions; WindowsStructs.GetWindowRect(proc.GetMWHandle(), out window_dimensions); Bitmap scrnsht_wind = new Bitmap(window_dimensions.Right - window_dimensions.Left + 1, window_dimensions.Bottom - window_dimensions.Top + 1); Graphics to_shot = Graphics.FromImage(scrnsht_wind); IntPtr bitmap_pointer = to_shot.GetHdc(); is_success = WindowsStructs.PrintWindow(proc.GetMWHandle(), bitmap_pointer, 0); if (is_success == 0) { System.Console.Write("\nError Taking Screenshot\n"); } else { System.Console.Write("\nSnapshot Taken\n"); } to_shot.ReleaseHdc(bitmap_pointer); to_shot.Dispose(); /*try * { * scrnsht_wind.Save("League.bmp"); //Only included for debugging reasons * } * catch(Exception e) * { * System.Console.Write("\nError Saving Bitmap\n"); * }*/ return(scrnsht_wind); }
//For Diagnostics public static void Print_Process_Window_Dimensions(Process_Object proc) { WindowsStructs.RECT window_size; if (WindowsStructs.GetWindowRect(proc.GetMWHandle(), out window_size) == 0) { System.Console.Write("\nERROR getting size"); return; } System.Console.Write(string.Concat("\nHeight: ", window_size.Bottom - window_size.Top + 1, " Width: ", window_size.Right - window_size.Left + 1)); }
public static void Click(Process_Object procObj, Program_Profile progProf) { //Adapted only for 64 bit systems? //TODO: Make alternate code for 32bit systems WindowsStructs.SetForegroundWindow(procObj.GetMWHandle()); UInt64 clickPoint = 0x0; clickPoint = clickPoint | (UInt32)(progProf.Get_OffsetY() + 5); clickPoint = clickPoint << 0x10; clickPoint = clickPoint | (UInt32)(progProf.Get_OffsetX() + 5); WindowsStructs.SendMessage(procObj.GetMWHandle(), WindowsStructs.WM_LBUTTONDOWN, (IntPtr)WindowsStructs.MK_LBUTTON, (IntPtr)clickPoint); WindowsStructs.SendMessage(procObj.GetMWHandle(), WindowsStructs.WM_LBUTTONUP, (IntPtr)WindowsStructs.MK_LBUTTON, (IntPtr)clickPoint); //WindowsStructs.SendMessage(procObj.GetMWHandle(), WindowsStructs.WM_LBUTTONDOWN, WindowsStructs.MK_LBUTTON, (UInt32)((progProf.Get_LengthY() << 0x10) | progProf.Get_LengthX())); //WindowsStructs.SendMessage(procObj.GetMWHandle(), WindowsStructs.WM_LBUTTONUP, WindowsStructs.MK_LBUTTON, (UInt32)((progProf.Get_LengthY() << 0x10) | progProf.Get_LengthX())); }
public bool Close() { uint exit_code = 0; int is_success = 0; is_success = WindowsStructs.TerminateProcess(this.handle, exit_code); if (is_success == 0) { return(false); } else { return(true); } }
//Allows part of the picture to be cropped out according to offsets public static Bitmap Take_Snapshot_Process(Process_Object proc, int offset_x, int offset_y, int offset_x2, int offset_y2) { int is_success = 0; Rectangle new_img_bounds = new Rectangle(0, 0, offset_x2, offset_y2); Rectangle crop_bounds = new Rectangle(offset_x, offset_y, offset_x2, offset_y2); WindowsStructs.RECT window_dimensions; WindowsStructs.GetWindowRect(proc.GetMWHandle(), out window_dimensions); Bitmap scrnsht_wind = new Bitmap(window_dimensions.Right - window_dimensions.Left + 1, window_dimensions.Bottom - window_dimensions.Top + 1); Graphics to_shot = Graphics.FromImage(scrnsht_wind); IntPtr bitmap_pointer = to_shot.GetHdc(); is_success = WindowsStructs.PrintWindow(proc.GetMWHandle(), bitmap_pointer, 0); if (is_success == 0) { System.Console.Write("\nError Taking Screenshot\n");// can return null which can call for a new mainwindowhandler } else { System.Console.Write("\nSnapshot Taken\n"); } Bitmap cropped_pic = new Bitmap(offset_x2, offset_y2); to_shot.ReleaseHdc(bitmap_pointer); to_shot.Dispose(); cropped_pic = (Bitmap)scrnsht_wind.Clone(crop_bounds, scrnsht_wind.PixelFormat); scrnsht_wind.Dispose(); /* try * { * cropped_pic.Save("League.bmp"); //Only included for debugging reasons * } * catch (Exception e) * { * System.Console.Write("\nError Saving Bitmap\n"); * }*/ return(cropped_pic); }
/**Retrieves a Process_Object to be stored. Stores name, PID, handle to process, and the actual Process object */ public static Process_Object GetProcessObject(string name) { Process_Object pb1 = new Process_Object(); Process[] tmp = Process.GetProcessesByName(name); // System.Console.Write(tmp.Length); if (tmp.Length == 0) { System.Console.Write("\nCouldn't find process\n"); return(null); } else if (tmp.Length == 1) { System.Console.Write("Found Exact Process"); pb1.SetProcess(tmp[0]); pb1.SetName(tmp[0].ProcessName); pb1.SetPID(tmp[0].Id); pb1.SetMWHandle(tmp[0].MainWindowHandle); //Get Handle after opening process, currently only containing Terminate_Process tag IntPtr tmp_hndle = WindowsStructs.OpenProcess((IntPtr)0x1F0FFF, false, (IntPtr)tmp[0].Id); if (tmp_hndle == null) { System.Console.Write("Could not open process"); pb1.SetHandle(tmp[0].Handle); } else { pb1.SetHandle(tmp_hndle); } //End getting of handle } else { System.Console.Write("Multiple Processes Found -- returning null"); return(null); } return(pb1); }
public bool IsOpen() { IntPtr ex_code; int value; unsafe { int success = WindowsStructs.GetExitCodeProcess(this.GetHandle(), out ex_code); if (success == 0) { return(false); } value = ex_code.ToInt32(); } if (value == 259) { return(true); } else { return(false); } }