public void CreateProject() { // kinda losing my sanity string FullFileName = Path.Combine(Cappy.FolderName, Cappy.Prefix + Cappy.GetSaveTime() + Cappy.ProjectExtension); File.Create(FullFileName).Dispose(); Cappy.ProjectPath = FullFileName; }
public static string GetCapture(int posX, int posY, string buttonClicked) { string saveTime = Cappy.GetSaveTime(); string folder = Cappy.FolderName + @"\Images\"; string FullFileName = String.Empty; string FocusFileName = String.Empty; string buttonAction = String.Empty; if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } FullFileName = folder + Cappy.Prefix + Cappy.FieldSeperator + saveTime + Cappy.FieldSeperator + "full" + Cappy.Extension; FocusFileName = folder + Cappy.Prefix + Cappy.FieldSeperator + saveTime + Cappy.FieldSeperator + "focus" + Cappy.Extension; IntPtr hwnd = NativeMethods.WindowFromPoint(posX, posY); string WindowText = NativeMethods.GetWindowTextByWM(hwnd); Bitmap FullCapture = ScreenCapture.GetScreenShot(posX, posY, 0, false); FullCapture.Save(FullFileName); FullCapture.Dispose(); Bitmap FocusedCapture = ScreenCapture.GetScreenShot(posX, posY, 1, false); FocusedCapture.Save(FocusFileName); FocusedCapture.Dispose(); if (buttonClicked.Equals("Left")) { buttonAction = "Click"; } else if (buttonClicked.Equals("Right")) { buttonAction = "Right-click"; } else if (buttonClicked.Equals("Tab") || buttonClicked.Equals("Escape") || buttonClicked.Equals("Enter")) { buttonAction = "Press"; } if (String.IsNullOrEmpty(WindowText)) { WindowText = "<< UNKNOWN >>"; } string CaptureDetails = buttonAction + ";" + buttonClicked + ";" + WindowText + ";" + FullFileName + ";" + FocusFileName + "?"; return(CaptureDetails); }
public static string GetCapture(string buttonClicked) { // method overloading is cool string saveTime = Cappy.GetSaveTime(); string folder = Cappy.FolderName + @"\Images\"; string FileName; string buttonAction = String.Empty; if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } FileName = folder + Cappy.Prefix + Cappy.FieldSeperator + saveTime + Cappy.FieldSeperator + "key" + Cappy.Extension; // rectangl shid Rectangle bounds = new Rectangle(); NativeMethods.RECT rct; IntPtr hwnd = NativeMethods.GetForegroundWindow(); IntPtr parentHwnd = NativeMethods.GetParent(hwnd); if (parentHwnd == IntPtr.Zero) { // if foreground window is already top level, just use it's hwnd NativeMethods.GetWindowRect(hwnd, out rct); bounds.X = rct.Left; bounds.Y = rct.Top; bounds.Width = rct.Right - rct.Left; bounds.Height = rct.Bottom - rct.Top; } else { // otherwise, get the top level window in the foreground window's hierarchy NativeMethods.GetWindowRect(parentHwnd, out rct); bounds.X = rct.Left; bounds.Y = rct.Top; bounds.Width = rct.Right - rct.Left; bounds.Height = rct.Bottom - rct.Top; } Bitmap Capture = ScreenCapture.GetScreenShot(bounds.X + (bounds.Width / 2), bounds.Y + (bounds.Height / 2), 1, true); Capture.Save(FileName); Capture.Dispose(); if (buttonClicked.Equals("Left")) { buttonAction = "Click"; } else if (buttonClicked.Equals("Right")) { buttonAction = "Right-click"; } else if (buttonClicked.Equals("Tab") || buttonClicked.Equals("Escape") || buttonClicked.Equals("Enter")) { buttonAction = "Press"; } string CaptureDetails = buttonAction + ";" + buttonClicked + ";" + FileName + "?"; return(CaptureDetails); }
public void BuildDocument(string[] ScriptItems) { string FullDocFileName = Cappy.FolderName + @"\" + Cappy.Prefix + Cappy.FieldSeperator + Cappy.GetSaveTime() + Cappy.FieldSeperator + Cappy.DocExtension; using (DocX document = DocX.Create(FullDocFileName)) { foreach (string ScriptItem in ScriptItems) { if (ScriptItem != null) { // instantiate some // TODO: this loop contains alot of copy paste and hackiness because im tired and shit, please clean it up string[] Fields = ScriptItem.Split(';'); string ButtonAction = String.Empty; string ButtonClicked = String.Empty; string WindowText = String.Empty; string FullFileName = String.Empty; string FocusFileName = String.Empty; if (Fields.Length == 5) { ButtonAction = Fields[0]; ButtonClicked = Fields[1]; WindowText = Fields[2]; FullFileName = Fields[3]; FocusFileName = Fields[4]; } else if (Fields.Length == 3) { ButtonAction = Fields[0]; ButtonClicked = Fields[1]; FullFileName = Fields[2]; } string ParagraphText; if (Fields.Length == 5) { // because alot of things in windows have weird window names, or you perform more advanced actions on them then click, let's define some things to make our documents nicer if (!String.IsNullOrEmpty(WindowText)) { ParagraphText = ButtonAction + " " + WindowText; } else { // if we can't determine what was clicked, resort to this. ParagraphText = ButtonAction + " << FILL IN MISSING TEXT >>"; } // create our paragraph to work with Paragraph p = document.InsertParagraph(); // get bitmaps of the desired images System.Drawing.Image FullCaptureImage = GetImage(FullFileName); System.Drawing.Image FocusCaptureImage = GetImage(FocusFileName); // instantiate memory streams for writing our bitmaps to MemoryStream FullCaptureStream = new MemoryStream(); MemoryStream FocusCaptureStream = new MemoryStream(); // save our bitmaps into the memory stream FullCaptureImage.Save(FullCaptureStream, FullCaptureImage.RawFormat); FocusCaptureImage.Save(FocusCaptureStream, FocusCaptureImage.RawFormat); // set position in memory stream FullCaptureStream.Seek(0, SeekOrigin.Begin); FocusCaptureStream.Seek(0, SeekOrigin.Begin); // create the base image to work with, and add it to our document object for later Xceed.Document.NET.Image FullCapture = document.AddImage(FullCaptureStream); Xceed.Document.NET.Image FocusCapture = document.AddImage(FocusCaptureStream); // convert image to picture usable in a document Picture FullCapturePic = FullCapture.CreatePicture(); Picture FocusCapturePic = FocusCapture.CreatePicture(); // because screenshots will be a constant size, simply set a scalar to our desired resolution. we can also use this for calculating the focus size. const int imgWidth = 512; const int imgHeight = 288; // apply aforementioned scalar FullCapturePic.Width = imgWidth; FullCapturePic.Height = imgHeight; // create focused screenshot size Size focusbbox = new Size(imgWidth, imgHeight); // get the scaled version of focused image Size focusSize = ExpandToBound(FocusCaptureImage.Size, focusbbox); FocusCapturePic.Width = focusSize.Width; FocusCapturePic.Height = focusSize.Height; // insert bullet list var list = document.AddList(listType: ListItemType.Numbered, continueNumbering: true); document.AddListItem(list, ParagraphText, 0, listType: ListItemType.Numbered); // insert images p.InsertListBeforeSelf(list); p.AppendLine().AppendPicture(FullCapturePic); p.AppendLine(); // space the images p.AppendLine().AppendPicture(FocusCapturePic); p.AppendLine(); // leave a space for writing p.InsertPageBreakAfterSelf(); // release unneeded resources FullCaptureImage.Dispose(); FullCaptureStream.Dispose(); FocusCaptureImage.Dispose(); FocusCaptureStream.Dispose(); } if (Fields.Length == 3) { ParagraphText = ButtonAction + " " + ButtonClicked; // create our paragraph to work with Paragraph p = document.InsertParagraph(); // get bitmaps of the desired images System.Drawing.Image FullCaptureImage = GetImage(FullFileName); // instantiate memory streams for writing our bitmaps to MemoryStream FullCaptureStream = new MemoryStream(); // save our bitmaps into the memory stream FullCaptureImage.Save(FullCaptureStream, FullCaptureImage.RawFormat); // set position in memory stream FullCaptureStream.Seek(0, SeekOrigin.Begin); // create the base image to work with, and add it to our document object for later Xceed.Document.NET.Image FullCapture = document.AddImage(FullCaptureStream); // convert image to picture usable in a document Picture FullCapturePic = FullCapture.CreatePicture(); // because screenshots will be a constant size, simply set a scalar to our desired resolution. we can also use this for calculating the focus size. const int imgWidth = 512; const int imgHeight = 288; // apply aforementioned scalar FullCapturePic.Width = imgWidth; FullCapturePic.Height = imgHeight; // insert bullet list var list = document.AddList(listType: ListItemType.Numbered, continueNumbering: true); document.AddListItem(list, ParagraphText, 0, listType: ListItemType.Numbered); // insert images p.InsertListBeforeSelf(list); p.AppendLine().AppendPicture(FullCapturePic); p.AppendLine(); // space the images // leave a space for writing p.InsertPageBreakAfterSelf(); // release unneeded resources FullCaptureImage.Dispose(); FullCaptureStream.Dispose(); } } } document.Save(); } }