//获得IE里面的URL和需要的信息 public static string getIEContent() { Hashtable hashtable = new Hashtable(); string userNum="blank"; SHDocVw.ShellWindows shellWindow = new SHDocVw.ShellWindowsClass(); string filename; foreach (SHDocVw.InternetExplorer ie in shellWindow){ filename= Path.GetFileNameWithoutExtension(ie.FullName).ToLower(); if (filename.Equals("iexplore")){ try{ MSHTML.IHTMLDocument2 htmlDoc = ie.Document as MSHTML.IHTMLDocument2; IHTMLInputElement input =null; if(htmlDoc!=null){ input = (IHTMLInputElement)htmlDoc.all.item("CONS_NO",0); // 获取指定名称的对象 } if(input != null ){ string temp = input.value + "0"; if(temp.Length>=5){ userNum = input.value; } } } catch(COMException e){ //不做处理 Console.WriteLine(e.Message); } } } if(userNum.Equals("blank")){ // NotificationIcon.userNumCheck="initialStr"; } return userNum; }
public static mshtml.HTMLDocument GetDocumentByPtr(this SHDocVw.ShellWindowsClass shell, IntPtr pointer) { var wbSearched = new ShellWindowsClass().Cast <IWebBrowser2>().FirstOrDefault(x => x.HWND == (int)pointer); if (wbSearched == null) { return(null); } if (!(wbSearched.Document is mshtml.HTMLDocument)) { return(null); } return((mshtml.HTMLDocument)wbSearched.Document); }
public static mshtml.HTMLDocument GetDocumentByAddress(this SHDocVw.ShellWindowsClass shell, string address) { var wbSearched = new ShellWindowsClass().Cast <IWebBrowser2>().FirstOrDefault(x => x.LocationURL.ToLower().Contains(address.ToLower())); if (wbSearched == null) { return(null); } if (!(wbSearched.Document is mshtml.HTMLDocument)) { return(null); } return((mshtml.HTMLDocument)wbSearched.Document); }
/// <summary> /// http://weblogs.asp.net/stevencohn/archive/2004/01/23/62117.aspx Automating IE Remotely Using C# /// </summary> public static void AutomatingIERemotely() { string filename; SHDocVw.InternetExplorer browser = null; SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass(); foreach (SHDocVw.InternetExplorer ie in shellWindows) { filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower(); if (filename.Equals("iexplore")) { browser = ie; break; } } }
//获得IE里面的URL和需要的信息 public static string getIEContentDetail() { Hashtable hashtable = new Hashtable(); string userNum="blank"; SHDocVw.ShellWindows shellWindow = new SHDocVw.ShellWindowsClass(); string filename; foreach (SHDocVw.InternetExplorer ie in shellWindow){ filename= Path.GetFileNameWithoutExtension(ie.FullName).ToLower(); if (filename.Equals("iexplore")){ try{ MSHTML.IHTMLDocument2 htmlDoc = ie.Document as MSHTML.IHTMLDocument2; //写入参数 FileStream fileStream = new FileStream(Application.StartupPath +"\\html.ini", FileMode.OpenOrCreate, FileAccess.ReadWrite); StreamWriter oputfile = new StreamWriter(fileStream); oputfile.WriteLine(htmlDoc.body.outerHTML); oputfile.Close(); fileStream.Close(); IHTMLInputElement input =null; if(htmlDoc!=null){ input = (IHTMLInputElement)htmlDoc.all.item("CONS_NO",0); // 获取指定名称的对象 } if(input != null ){ string temp = input.value + "0"; if(temp.Length>=5){ userNum = input.value; } } } catch(COMException e){ //不做处理 Console.WriteLine(e.Message); } } } if(userNum.Equals("blank")){ // NotificationIcon.userNumCheck="initialStr"; } return userNum; }
private void capturePic_Click2(object sender, EventArgs e) { string captureLocation = @"D:\IECapt\IECapt.exe"; SHDocVw.WebBrowser m_browser = null; //get browser SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass(); // string filename; foreach (SHDocVw.WebBrowser ie in shellWindows) { filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower(); if (filename.Equals("iexplore")) { m_browser = ie; break; } } Process p = Process.Start(captureLocation, "--url=" + m_browser.LocationURL + " --out=" + @"c:\\IECapture\Captured_" + DateTime.Now.ToString("yyyy-mm-dd") + ".jpg"); p.WaitForExit(); }
/// <summary> /// Saves IE web page full content to Image reference. /// </summary> public static void grabWeb() { try { lock(SnapLocker) { SHDocVw.WebBrowser m_browser = null; SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass(); //Find first availble browser window. //Application can easily be modified to loop through and capture all open windows. string filename; foreach(SHDocVw.WebBrowser ie in shellWindows) { filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower(); if(filename.Equals("iexplore")) { m_browser = ie; break; } } if(m_browser == null) { MessageBox.Show("No IE Browser Open.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if(bmp != null) { bmp.Dispose(); bmp = null; } //Assign Browser Document mshtml.IHTMLDocument2 myDoc = (mshtml.IHTMLDocument2)m_browser.Document; mshtml.IHTMLDocument3 doc3 = (mshtml.IHTMLDocument3)myDoc; //URL Location string myLocalLink = myDoc.url; int URLExtraHeight = 0; int URLExtraLeft = 0; //TrimHeight and TrimLeft trims off some captured IE graphics. int trimHeight = 3; int trimLeft = 3; //Use UrlExtra height to carry trimHeight. URLExtraHeight = URLExtraHeight - trimHeight; URLExtraLeft = URLExtraLeft - trimLeft; setAttribute("scroll", 1, myDoc, doc3); //Get Browser Window Height int heightsize = getAttribute("scrollHeight", myDoc, doc3); int widthsize = getAttribute("scrollWidth", myDoc, doc3); //Get Screen Height int screenHeight = getAttribute("clientHeight", myDoc, doc3); int screenWidth = getAttribute("clientWidth", myDoc, doc3); //Get bitmap to hold screen fragment. Bitmap bm = new Bitmap(screenWidth, screenHeight);//, System.Drawing.Imaging.PixelFormat.Format16bppRgb555); //Create a target bitmap to draw into. Bitmap bm2 = new Bitmap(widthsize + URLExtraLeft, heightsize + URLExtraHeight - trimHeight);//, System.Drawing.Imaging.PixelFormat.Format16bppRgb555); Graphics g2 = Graphics.FromImage(bm2); Graphics g = null; IntPtr hdc; Image screenfrag = null; int brwTop = 0; int brwLeft = 0; int myPage = 0; IntPtr myIntptr = (IntPtr)m_browser.HWND; //Get inner browser window. int hwndInt = myIntptr.ToInt32(); IntPtr hwnd = myIntptr; hwnd = GetWindow(hwnd, GW_CHILD); StringBuilder sbc = new StringBuilder(256); //Get Browser "Document" Handle while(hwndInt != 0) { hwndInt = hwnd.ToInt32(); GetClassName(hwndInt, sbc, 256); if(sbc.ToString().IndexOf("Shell DocObject View", 0) > -1) //IE6 { hwnd = FindWindowEx(hwnd, IntPtr.Zero, "Internet Explorer_Server", IntPtr.Zero); break; } if(sbc.ToString().IndexOf("TabWindowClass", 0) > -1) //IE7 { hwnd = FindWindowEx(hwnd, IntPtr.Zero, "Shell DocObject View", IntPtr.Zero); hwnd = FindWindowEx(hwnd, IntPtr.Zero, "Internet Explorer_Server", IntPtr.Zero); break; } if(sbc.ToString().IndexOf("Frame Tab", 0) > -1) // IE8 { hwnd = FindWindowEx(hwnd, IntPtr.Zero, "TabWindowClass", IntPtr.Zero); hwnd = FindWindowEx(hwnd, IntPtr.Zero, "Shell DocObject View", IntPtr.Zero); hwnd = FindWindowEx(hwnd, IntPtr.Zero, "Internet Explorer_Server", IntPtr.Zero); break; } hwnd = GetWindow(hwnd, GW_HWNDNEXT); } //Get Screen Height (for bottom up screen drawing) while((myPage * screenHeight) < heightsize) { setAttribute("scrollTop", (screenHeight - 5) * myPage, myDoc, doc3); ++myPage; } //Rollback the page count by one --myPage; int myPageWidth = 0; while((myPageWidth * screenWidth) < widthsize) { setAttribute("scrollLeft", (screenWidth - 5) * myPageWidth, myDoc, doc3); brwLeft = getAttribute("scrollLeft", myDoc, doc3); for(int i = myPage ; i >= 0 ; --i) { //Shoot visible window g = Graphics.FromImage(bm); hdc = g.GetHdc(); setAttribute("scrollTop", (screenHeight - 5) * i, myDoc, doc3); brwTop = getAttribute("scrollTop", myDoc, doc3); PrintWindow(hwnd, hdc, 0); g.ReleaseHdc(hdc); g.Flush(); screenfrag = Image.FromHbitmap(bm.GetHbitmap()); g2.DrawImage(screenfrag, brwLeft + URLExtraLeft, brwTop + URLExtraHeight); } ++myPageWidth; } snap = new Snap(bm2, GetExt(Settings.Default.Path), DateTime.Now, Settings.Default.AccountID, null); lastSnap = snap; main.refreshPreview(); if(Settings.Default.SaveSnaps) SnapToDB(snap); //insertSnapToDB.RunWorkerAsync(snap); main.updateStatus(); bm.Dispose(); bm2.Dispose(); screenfrag.Dispose(); g.Dispose(); g2.Dispose(); } } catch(Exception ex) { MessageBox.Show("Couldn't grab web page content.\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void button1_Click(object sender, System.EventArgs e) { //TODO In Next Version: //Add cursor capture //Add file naming option //Add visible screen capture //Make captured image a DDB not a DIB bitmap. Cursor.Current = Cursors.WaitCursor; SHDocVw.WebBrowser m_browser = null; SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass(); //Find first availble browser window. //Application can easily be modified to loop through and capture all open windows. string filename; foreach (SHDocVw.WebBrowser ie in shellWindows) { filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower(); if (filename.Equals("iexplore")) { m_browser = ie; break; } } if (m_browser == null) { MessageBox.Show("No Browser Open"); return; } //Assign Browser Document mshtml.IHTMLDocument2 myDoc = (mshtml.IHTMLDocument2)m_browser.Document; //URL Location string myLocalLink = myDoc.url; int URLExtraHeight = 0; int URLExtraLeft = 0; //Adjustment variable for capture size. if (chkWriteURL.Checked == true) { URLExtraHeight = 25; } //TrimHeight and TrimLeft trims off some captured IE graphics. int trimHeight = 3; int trimLeft = 3; //Use UrlExtra height to carry trimHeight. URLExtraHeight = URLExtraHeight - trimHeight; URLExtraLeft = URLExtraLeft - trimLeft; myDoc.body.setAttribute("scroll", "yes", 0); //Get Browser Window Height int heightsize = (int)myDoc.body.getAttribute("scrollHeight", 0); int widthsize = (int)myDoc.body.getAttribute("scrollWidth", 0); //Get Screen Height int screenHeight = (int)myDoc.body.getAttribute("clientHeight", 0); int screenWidth = (int)myDoc.body.getAttribute("clientWidth", 0); //Get bitmap to hold screen fragment. Bitmap bm = new Bitmap(screenWidth, screenHeight, System.Drawing.Imaging.PixelFormat.Format16bppRgb555); //Create a target bitmap to draw into. Bitmap bm2 = new Bitmap(widthsize + URLExtraLeft, heightsize + URLExtraHeight - trimHeight, System.Drawing.Imaging.PixelFormat.Format16bppRgb555); Graphics g2 = Graphics.FromImage(bm2); Graphics g = null; IntPtr hdc; Image screenfrag = null; int brwTop = 0; int brwLeft = 0; int myPage = 0; IntPtr myIntptr = (IntPtr)m_browser.HWND; //Get inner browser window. int hwndInt = myIntptr.ToInt32(); IntPtr hwnd = myIntptr; hwnd = GetWindow(hwnd, GW_CHILD); StringBuilder sbc = new StringBuilder(256); //Get Browser "Document" Handle while (hwndInt != 0) { hwndInt = hwnd.ToInt32(); GetClassName(hwndInt, sbc, 256); if (sbc.ToString().IndexOf("Shell DocObject View", 0) > -1) { hwnd = FindWindowEx(hwnd, IntPtr.Zero, "Internet Explorer_Server", IntPtr.Zero); break; } hwnd = GetWindow(hwnd, GW_HWNDNEXT); } //Get Screen Height (for bottom up screen drawing) while ((myPage * screenHeight) < heightsize) { myDoc.body.setAttribute("scrollTop", (screenHeight - 5) * myPage, 0); ++myPage; } //Rollback the page count by one --myPage; int myPageWidth = 0; while ((myPageWidth * screenWidth) < widthsize) { myDoc.body.setAttribute("scrollLeft", (screenWidth - 5) * myPageWidth, 0); brwLeft = (int)myDoc.body.getAttribute("scrollLeft", 0); for (int i = myPage; i >= 0; --i) { //Shoot visible window g = Graphics.FromImage(bm); hdc = g.GetHdc(); myDoc.body.setAttribute("scrollTop", (screenHeight - 5) * i, 0); brwTop = (int)myDoc.body.getAttribute("scrollTop", 0); PrintWindow(hwnd, hdc, 0); g.ReleaseHdc(hdc); g.Flush(); screenfrag = Image.FromHbitmap(bm.GetHbitmap()); g2.DrawImage(screenfrag, brwLeft + URLExtraLeft, brwTop + URLExtraHeight); } ++myPageWidth; } //Draw Standard Resolution Guides if (chkShowGuides.Checked == true) { // Create pen. int myWidth = 1; Pen myPen = new Pen(Color.Navy, myWidth); Pen myShadowPen = new Pen(Color.NavajoWhite, myWidth); // Create coordinates of points that define line. float x1 = -(float)myWidth - 1 + URLExtraLeft; float y1 = -(float)myWidth - 1 + URLExtraHeight; float x600 = 600.0F + (float)myWidth + 1; float y480 = 480.0F + (float)myWidth + 1; float x2 = 800.0F + (float)myWidth + 1; float y2 = 600.0F + (float)myWidth + 1; float x3 = 1024.0F + (float)myWidth + 1; float y3 = 768.0F + (float)myWidth + 1; float x1280 = 1280.0F + (float)myWidth + 1; float y1024 = 1024.0F + (float)myWidth + 1; // Draw line to screen. g2.DrawRectangle(myPen, x1, y1, x600 + myWidth, y480 + myWidth); g2.DrawRectangle(myPen, x1, y1, x2 + myWidth, y2 + myWidth); g2.DrawRectangle(myPen, x1, y1, x3 + myWidth, y3 + myWidth); g2.DrawRectangle(myPen, x1, y1, x1280 + myWidth, y1024 + myWidth); // Create font and brush. Font drawFont = new Font("Arial", 12); SolidBrush drawBrush = new SolidBrush(Color.Navy); SolidBrush drawBrush2 = new SolidBrush(Color.NavajoWhite); // Set format of string. StringFormat drawFormat = new StringFormat(); drawFormat.FormatFlags = StringFormatFlags.FitBlackBox; // Draw string to screen. g2.DrawString("600 x 480", drawFont, drawBrush, 5, y480 - 20 + URLExtraHeight, drawFormat); g2.DrawString("800 x 600", drawFont, drawBrush, 5, y2 - 20 + URLExtraHeight, drawFormat); g2.DrawString("1024 x 768", drawFont, drawBrush, 5, y3 - 20 + URLExtraHeight, drawFormat); g2.DrawString("1280 x 1024", drawFont, drawBrush, 5, y1024 - 20 + URLExtraHeight, drawFormat); } //Write URL if (chkWriteURL.Checked == true) { //Backfill URL paint location SolidBrush whiteBrush = new SolidBrush(Color.White); Rectangle fillRect = new Rectangle(0, 0, widthsize, URLExtraHeight + 2); Region fillRegion = new Region(fillRect); g2.FillRegion(whiteBrush, fillRegion); SolidBrush drawBrushURL = new SolidBrush(Color.Black); Font drawFont = new Font("Arial", 12); StringFormat drawFormat = new StringFormat(); drawFormat.FormatFlags = StringFormatFlags.FitBlackBox; g2.DrawString(myLocalLink, drawFont, drawBrushURL, 0, 0, drawFormat); } //Reduce Resolution Size double myResolution = Convert.ToDouble(cmbResolution.Text) * 0.01; int finalWidth = (int)((widthsize + URLExtraLeft) * myResolution); int finalHeight = (int)((heightsize + URLExtraHeight) * myResolution); Bitmap finalImage = new Bitmap(finalWidth, finalHeight, System.Drawing.Imaging.PixelFormat.Format16bppRgb555); Graphics gFinal = Graphics.FromImage((Image)finalImage); gFinal.DrawImage(bm2, 0, 0, finalWidth, finalHeight); //Get Time Stamp DateTime myTime = DateTime.Now; String format = "MM.dd.hh.mm.ss"; //Create Directory to save image to. Directory.CreateDirectory("C:\\IECapture"); //Write Image. EncoderParameters eps = new EncoderParameters(1); long myQuality = Convert.ToInt64(cmbQuality.Text); eps.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, myQuality); ImageCodecInfo ici = GetEncoderInfo("image/jpeg"); finalImage.Save(@"c:\\IECapture\Captured_" + myTime.ToString(format) + ".jpg", ici, eps); //Clean Up. myDoc = null; g.Dispose(); g2.Dispose(); gFinal.Dispose(); bm.Dispose(); bm2.Dispose(); finalImage.Dispose(); Cursor.Current = Cursors.Default; }
private void capturePic_Click(object sender, EventArgs e) { SHDocVw.WebBrowser m_browser = null; //get browser SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass(); // string filename; foreach (SHDocVw.WebBrowser ie in shellWindows) { filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower(); if (filename.Equals("iexplore")) { m_browser = ie; break; } } //Assign Browser Document mshtml.IHTMLDocument2 myDoc = (mshtml.IHTMLDocument2)m_browser.Document; DispHTMLDocument myDocImpl = myDoc as DispHTMLDocument; HTMLDocument myHtmlDoc = myDoc as HTMLDocument; // IHTMLDocument2 doc2 = (IHTMLDocument2)m_browser.Document; // IHTMLDocument3 doc3 = (IHTMLDocument3)m_browser.Document; // IHTMLElement2 body2 = (IHTMLElement2)doc2.body; // IHTMLElement2 root2 = (IHTMLElement2)doc3.documentElement; // int width = Math.Max(body2.scrollWidth, root2.scrollWidth); // int height = Math.Max(root2.scrollHeight, body2.scrollHeight); // //m_browser.SetBounds(0, 0, width, height); // width = Math.Max(body2.scrollWidth, root2.scrollWidth); // height = Math.Max(root2.scrollHeight, body2.scrollHeight); // //m_browser.SetBounds(0, 0, width, height); // Bitmap image = new Bitmap(width, height); // Graphics g = Graphics.FromImage(image); // _RECTL bounds; // bounds.left = 0; // bounds.top = 0; // bounds.right = width; // bounds.bottom = height; // IntPtr hdc = g.GetHdc(); // IViewObject iv = doc2 as IViewObject; // // TODO: Write to Metafile instead if requested.1, -1, (IntPtr)0, (IntPtr)0, (IntPtr)0,(IntPtr)hdc, ref bounds, (IntPtr)0, (IntPtr)0, 0 // iv.Draw(1, -1, (IntPtr)0, (IntPtr)0, (IntPtr)0, //(IntPtr)hdc, ref bounds, (IntPtr)0, (IntPtr)0, 0); // g.ReleaseHdc(hdc); // image.Save("c:\\1.jpg"); // image.Dispose(); //URL Location IHTMLDocument2 doc2 = (IHTMLDocument2)m_browser.Document; IHTMLDocument3 doc3 = (IHTMLDocument3)m_browser.Document; IHTMLElement2 body2 = (IHTMLElement2)doc2.body; IHTMLElement2 root2 = (IHTMLElement2)doc3.documentElement; int width = Math.Max(body2.scrollWidth, root2.scrollWidth); int height = Math.Max(root2.scrollHeight, body2.scrollHeight); string myLocalLink = myDoc.url; int URLExtraHeight = 0; int URLExtraLeft = 0; //Adjustment variable for capture size. //if (chkWriteURL.Checked == true) // URLExtraHeight = 25; //TrimHeight and TrimLeft trims off some captured IE graphics. int trimHeight = 3; int trimLeft = 3; //Use UrlExtra height to carry trimHeight. URLExtraHeight = URLExtraHeight - trimHeight; URLExtraLeft = URLExtraLeft - trimLeft; myDoc.body.setAttribute("scroll", "yes", 0); //Get Browser Window Height int heightsize = (int)myDoc.body.getAttribute("scrollHeight", 0); int widthsize = (int)myDoc.body.getAttribute("scrollWidth", 0); //Get Screen Height int screenHeight = (int)myDoc.body.getAttribute("clientHeight", 0); int screenWidth = (int)myDoc.body.getAttribute("clientWidth", 0); //Get bitmap to hold screen fragment. Bitmap bm = new Bitmap(screenWidth, screenHeight, System.Drawing.Imaging.PixelFormat.Format32bppRgb); //Create a target bitmap to draw into. Bitmap bm2 = new Bitmap(widthsize + URLExtraLeft, heightsize + URLExtraHeight - trimHeight, System.Drawing.Imaging.PixelFormat.Format32bppRgb); Graphics g2 = Graphics.FromImage(bm2); Graphics g = null; IntPtr hdc; Image screenfrag = null; int brwTop = 0; int brwLeft = 0; int myPage = 0; IntPtr myIntptr = (IntPtr)m_browser.HWND; //Get inner browser window. int hwndInt = myIntptr.ToInt32(); IntPtr hwnd = myIntptr; FindWindow fw = new FindWindow(hwnd, "Internet Explorer_Server"); hwnd = fw.FoundHandle; string bodyId = (string)myDoc.body.getAttribute("id", 0); if (bodyId == null) { myDoc.body.setAttribute("id", "current", 0); bodyId = (string)myDoc.body.getAttribute("id", 0); } //Get Screen Height (for bottom up screen drawing) while ((myPage * screenHeight) < height) { myDoc.body.setAttribute("scrollTop", (screenHeight - 5) * myPage, 0); ++myPage; } //Rollback the page count by one --myPage; int myPageWidth = 0; while ((myPageWidth * screenWidth) < width) { //myDocImpl.getElementById(bodyId).setAttribute("scrollLeft", (screenWidth - 5) * myPageWidth, 0); //myDoc.body.setAttribute("scrollLeft", (screenWidth - 5) * myPageWidth, 0); //brwLeft = (int)myDoc.body.getAttribute("scrollLeft", 0); //brwLeft = (int)myDocImpl.getElementById(bodyId).getAttribute("scrollLeft", 0); for (int i = myPage; i >= 0; --i) { //Shoot visible window g = Graphics.FromImage(bm); hdc = g.GetHdc(); //myDoc.body.setAttribute("scrollTop", (screenHeight - 5) * i, 0); //brwTop = (int)myDoc.body.getAttribute("scrollTop", 0); //myDocImpl.getElementById(bodyId).setAttribute("scrollTop", (screenHeight - 5) * myPageWidth, 0); //brwTop = (int)myDocImpl.getElementById(bodyId).getAttribute("scrollTop", 0); if (i == 0) { myDocImpl.parentWindow.scrollBy(0, (screenHeight - 5) * i);// = height; } else { myDocImpl.parentWindow.scrollTo((screenWidth - 5) * myPageWidth, (screenHeight - 5) * i); } PrintWindow(hwnd, hdc, 0); g.ReleaseHdc(hdc); g.Flush(); screenfrag = Image.FromHbitmap(bm.GetHbitmap()); g2.DrawImage(screenfrag, brwLeft + URLExtraLeft, brwTop + URLExtraHeight); } ++myPageWidth; } //Reduce Resolution Size double myResolution = Convert.ToDouble(1024) * 0.01; int finalWidth = (int)((widthsize + URLExtraLeft) * myResolution); int finalHeight = (int)((heightsize + URLExtraHeight) * myResolution); Bitmap finalImage = new Bitmap(finalWidth, finalHeight, System.Drawing.Imaging.PixelFormat.Format32bppRgb); Graphics gFinal = Graphics.FromImage((Image)finalImage); gFinal.DrawImage(bm2, 0, 0, finalWidth, finalHeight); //Get Time Stamp DateTime myTime = DateTime.Now; String format = "MM.dd.hh.mm.ss"; //Create Directory to save image to. if (!Directory.Exists("C:\\IECapture")) { Directory.CreateDirectory("C:\\IECapture"); } //Write Image. EncoderParameters eps = new EncoderParameters(1); long myQuality = 75L;//Convert.ToInt64(cmbQuality.Text); eps.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, myQuality); ImageCodecInfo ici = GetEncoderInfo("image/jpeg"); finalImage.Save(@"c:\\IECapture\Captured_" + myTime.ToString(format) + ".jpg", ici, eps); myDoc = null; g.Dispose(); g2.Dispose(); gFinal.Dispose(); bm.Dispose(); bm2.Dispose(); finalImage.Dispose(); }
static int Main(string[] args) { SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass(); string filename; string prefix = ""; Uri uri; int count = 0; int choice = -1; Console.Out.NewLine="\n"; Console.Error.NewLine="\n"; if (args.Length >= 1) { //choice = Int32.ParseInt(args[0]); if (!Int32.TryParse(args[0], out choice)) { Console.Error.WriteLine("Error! argument could not be parsed."); choice = -1; return 1; } } foreach ( SHDocVw.InternetExplorer ie in shellWindows ) { filename = Path.GetFileNameWithoutExtension( ie.FullName ).ToLower(); /* if ( filename.Equals( "iexplore" ) ) { Console.WriteLine( "Web Site : {0} == {1}", ie.LocationURL, ie.LocationName); } */ if ( filename.Equals( "explorer" ) && ie.LocationURL.StartsWith( "file://" )) { if (choice > -1) { if (choice == count) { prefix = ""; } else if (count < choice) { count++; continue; } else { break; } } else { prefix = count + ": "; } ///Console.WriteLine("after choice check"); if (ie.LocationURL.StartsWith("file:///")) { uri = new Uri(ie.LocationURL); Console.WriteLine( "{0}{1}", prefix, uri.GetComponents(UriComponents.Path, UriFormat.Unescaped)); } else { uri = new Uri(ie.LocationURL); Console.WriteLine( "{0}//{1}", prefix, uri.GetComponents(UriComponents.Path | UriComponents.Host, UriFormat.Unescaped)); } count++; } } if (choice > -1 && choice >= count) { Console.Error.WriteLine("Error! argument too large"); return 1; } return 0; }
private void capturePic_Click2(object sender, EventArgs e) { string captureLocation = @"D:\IECapt\IECapt.exe"; SHDocVw.WebBrowser m_browser = null;//get browser SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass(); // string filename; foreach (SHDocVw.WebBrowser ie in shellWindows) { filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower(); if (filename.Equals("iexplore")) { m_browser = ie; break; } } Process p = Process.Start(captureLocation, "--url=" + m_browser.LocationURL + " --out=" + @"c:\\IECapture\Captured_" + DateTime.Now.ToString("yyyy-mm-dd") + ".jpg"); p.WaitForExit(); }
private void capturePic_Click(object sender, EventArgs e) { SHDocVw.WebBrowser m_browser = null;//get browser SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass(); // string filename; foreach (SHDocVw.WebBrowser ie in shellWindows) { filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower(); if (filename.Equals("iexplore")) { m_browser = ie; break; } } //Assign Browser Document mshtml.IHTMLDocument2 myDoc = (mshtml.IHTMLDocument2)m_browser.Document; DispHTMLDocument myDocImpl = myDoc as DispHTMLDocument; HTMLDocument myHtmlDoc = myDoc as HTMLDocument; // IHTMLDocument2 doc2 = (IHTMLDocument2)m_browser.Document; // IHTMLDocument3 doc3 = (IHTMLDocument3)m_browser.Document; // IHTMLElement2 body2 = (IHTMLElement2)doc2.body; // IHTMLElement2 root2 = (IHTMLElement2)doc3.documentElement; // int width = Math.Max(body2.scrollWidth, root2.scrollWidth); // int height = Math.Max(root2.scrollHeight, body2.scrollHeight); // //m_browser.SetBounds(0, 0, width, height); // width = Math.Max(body2.scrollWidth, root2.scrollWidth); // height = Math.Max(root2.scrollHeight, body2.scrollHeight); // //m_browser.SetBounds(0, 0, width, height); // Bitmap image = new Bitmap(width, height); // Graphics g = Graphics.FromImage(image); // _RECTL bounds; // bounds.left = 0; // bounds.top = 0; // bounds.right = width; // bounds.bottom = height; // IntPtr hdc = g.GetHdc(); // IViewObject iv = doc2 as IViewObject; // // TODO: Write to Metafile instead if requested.1, -1, (IntPtr)0, (IntPtr)0, (IntPtr)0,(IntPtr)hdc, ref bounds, (IntPtr)0, (IntPtr)0, 0 // iv.Draw(1, -1, (IntPtr)0, (IntPtr)0, (IntPtr)0, //(IntPtr)hdc, ref bounds, (IntPtr)0, (IntPtr)0, 0); // g.ReleaseHdc(hdc); // image.Save("c:\\1.jpg"); // image.Dispose(); //URL Location IHTMLDocument2 doc2 = (IHTMLDocument2)m_browser.Document; IHTMLDocument3 doc3 = (IHTMLDocument3)m_browser.Document; IHTMLElement2 body2 = (IHTMLElement2)doc2.body; IHTMLElement2 root2 = (IHTMLElement2)doc3.documentElement; int width = Math.Max(body2.scrollWidth, root2.scrollWidth); int height = Math.Max(root2.scrollHeight, body2.scrollHeight); string myLocalLink = myDoc.url; int URLExtraHeight = 0; int URLExtraLeft = 0; //Adjustment variable for capture size. //if (chkWriteURL.Checked == true) // URLExtraHeight = 25; //TrimHeight and TrimLeft trims off some captured IE graphics. int trimHeight = 3; int trimLeft = 3; //Use UrlExtra height to carry trimHeight. URLExtraHeight = URLExtraHeight - trimHeight; URLExtraLeft = URLExtraLeft - trimLeft; myDoc.body.setAttribute("scroll", "yes", 0); //Get Browser Window Height int heightsize = (int)myDoc.body.getAttribute("scrollHeight", 0); int widthsize = (int)myDoc.body.getAttribute("scrollWidth", 0); //Get Screen Height int screenHeight = (int)myDoc.body.getAttribute("clientHeight", 0); int screenWidth = (int)myDoc.body.getAttribute("clientWidth", 0); //Get bitmap to hold screen fragment. Bitmap bm = new Bitmap(screenWidth, screenHeight, System.Drawing.Imaging.PixelFormat.Format32bppRgb); //Create a target bitmap to draw into. Bitmap bm2 = new Bitmap(widthsize + URLExtraLeft, heightsize + URLExtraHeight - trimHeight, System.Drawing.Imaging.PixelFormat.Format32bppRgb); Graphics g2 = Graphics.FromImage(bm2); Graphics g = null; IntPtr hdc; Image screenfrag = null; int brwTop = 0; int brwLeft = 0; int myPage = 0; IntPtr myIntptr = (IntPtr)m_browser.HWND; //Get inner browser window. int hwndInt = myIntptr.ToInt32(); IntPtr hwnd = myIntptr; FindWindow fw = new FindWindow(hwnd, "Internet Explorer_Server"); hwnd = fw.FoundHandle; string bodyId = (string)myDoc.body.getAttribute("id", 0); if (bodyId == null) { myDoc.body.setAttribute("id", "current", 0); bodyId =(string) myDoc.body.getAttribute("id", 0); } //Get Screen Height (for bottom up screen drawing) while ((myPage * screenHeight) < height) { myDoc.body.setAttribute("scrollTop", (screenHeight - 5) * myPage, 0); ++myPage; } //Rollback the page count by one --myPage; int myPageWidth = 0; while ((myPageWidth * screenWidth) < width) { //myDocImpl.getElementById(bodyId).setAttribute("scrollLeft", (screenWidth - 5) * myPageWidth, 0); //myDoc.body.setAttribute("scrollLeft", (screenWidth - 5) * myPageWidth, 0); //brwLeft = (int)myDoc.body.getAttribute("scrollLeft", 0); //brwLeft = (int)myDocImpl.getElementById(bodyId).getAttribute("scrollLeft", 0); for (int i = myPage; i >= 0; --i) { //Shoot visible window g = Graphics.FromImage(bm); hdc = g.GetHdc(); //myDoc.body.setAttribute("scrollTop", (screenHeight - 5) * i, 0); //brwTop = (int)myDoc.body.getAttribute("scrollTop", 0); //myDocImpl.getElementById(bodyId).setAttribute("scrollTop", (screenHeight - 5) * myPageWidth, 0); //brwTop = (int)myDocImpl.getElementById(bodyId).getAttribute("scrollTop", 0); if (i == 0) myDocImpl.parentWindow.scrollBy(0,(screenHeight - 5) * i);// = height; else myDocImpl.parentWindow.scrollTo((screenWidth - 5) * myPageWidth, (screenHeight - 5) * i); PrintWindow(hwnd, hdc, 0); g.ReleaseHdc(hdc); g.Flush(); screenfrag = Image.FromHbitmap(bm.GetHbitmap()); g2.DrawImage(screenfrag, brwLeft + URLExtraLeft, brwTop + URLExtraHeight); } ++myPageWidth; } //Reduce Resolution Size double myResolution = Convert.ToDouble(1024) * 0.01; int finalWidth = (int)((widthsize + URLExtraLeft) * myResolution); int finalHeight = (int)((heightsize + URLExtraHeight) * myResolution); Bitmap finalImage = new Bitmap(finalWidth, finalHeight, System.Drawing.Imaging.PixelFormat.Format32bppRgb); Graphics gFinal = Graphics.FromImage((Image)finalImage); gFinal.DrawImage(bm2, 0, 0, finalWidth, finalHeight); //Get Time Stamp DateTime myTime = DateTime.Now; String format = "MM.dd.hh.mm.ss"; //Create Directory to save image to. if (!Directory.Exists("C:\\IECapture")) Directory.CreateDirectory("C:\\IECapture"); //Write Image. EncoderParameters eps = new EncoderParameters(1); long myQuality = 75L;//Convert.ToInt64(cmbQuality.Text); eps.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, myQuality); ImageCodecInfo ici = GetEncoderInfo("image/jpeg"); finalImage.Save(@"c:\\IECapture\Captured_" + myTime.ToString(format) + ".jpg", ici, eps); myDoc = null; g.Dispose(); g2.Dispose(); gFinal.Dispose(); bm.Dispose(); bm2.Dispose(); finalImage.Dispose(); }
private void button1_Click(object sender, System.EventArgs e) { //TODO In Next Version: //Add cursor capture //Add file naming option //Add visible screen capture //Make captured image a DDB not a DIB bitmap. Cursor.Current = Cursors.WaitCursor; SHDocVw.WebBrowser m_browser = null; SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass(); //Find first availble browser window. //Application can easily be modified to loop through and capture all open windows. string filename; foreach (SHDocVw.WebBrowser ie in shellWindows) { filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower(); if (filename.Equals("iexplore")) { m_browser = ie; break; } } if (m_browser == null) { MessageBox.Show("No Browser Open"); return; } //Assign Browser Document mshtml.IHTMLDocument2 myDoc = (mshtml.IHTMLDocument2)m_browser.Document; //URL Location string myLocalLink = myDoc.url; int URLExtraHeight = 0; int URLExtraLeft = 0; //Adjustment variable for capture size. if (chkWriteURL.Checked == true) URLExtraHeight = 25; //TrimHeight and TrimLeft trims off some captured IE graphics. int trimHeight = 3; int trimLeft = 3; //Use UrlExtra height to carry trimHeight. URLExtraHeight = URLExtraHeight - trimHeight; URLExtraLeft = URLExtraLeft - trimLeft; myDoc.body.setAttribute("scroll", "yes", 0); //Get Browser Window Height int heightsize = (int)myDoc.body.getAttribute("scrollHeight", 0); int widthsize = (int)myDoc.body.getAttribute("scrollWidth", 0); //Get Screen Height int screenHeight = (int)myDoc.body.getAttribute("clientHeight", 0); int screenWidth = (int)myDoc.body.getAttribute("clientWidth", 0); //Get bitmap to hold screen fragment. Bitmap bm = new Bitmap(screenWidth, screenHeight, System.Drawing.Imaging.PixelFormat.Format16bppRgb555); //Create a target bitmap to draw into. Bitmap bm2 = new Bitmap(widthsize + URLExtraLeft, heightsize + URLExtraHeight - trimHeight, System.Drawing.Imaging.PixelFormat.Format16bppRgb555); Graphics g2 = Graphics.FromImage(bm2); Graphics g = null; IntPtr hdc; Image screenfrag = null; int brwTop = 0; int brwLeft = 0; int myPage = 0; IntPtr myIntptr = (IntPtr)m_browser.HWND; //Get inner browser window. int hwndInt = myIntptr.ToInt32(); IntPtr hwnd = myIntptr; hwnd = GetWindow(hwnd, GW_CHILD); StringBuilder sbc = new StringBuilder(256); //Get Browser "Document" Handle while (hwndInt != 0) { hwndInt = hwnd.ToInt32(); GetClassName(hwndInt, sbc, 256); if (sbc.ToString().IndexOf("Shell DocObject View", 0) > -1) { hwnd = FindWindowEx(hwnd, IntPtr.Zero, "Internet Explorer_Server", IntPtr.Zero); break; } hwnd = GetWindow(hwnd, GW_HWNDNEXT); } //Get Screen Height (for bottom up screen drawing) while ((myPage * screenHeight) < heightsize) { myDoc.body.setAttribute("scrollTop", (screenHeight - 5) * myPage, 0); ++myPage; } //Rollback the page count by one --myPage; int myPageWidth = 0; while ((myPageWidth * screenWidth) < widthsize) { myDoc.body.setAttribute("scrollLeft", (screenWidth - 5) * myPageWidth, 0); brwLeft = (int)myDoc.body.getAttribute("scrollLeft", 0); for (int i = myPage; i >= 0; --i) { //Shoot visible window g = Graphics.FromImage(bm); hdc = g.GetHdc(); myDoc.body.setAttribute("scrollTop", (screenHeight - 5) * i, 0); brwTop = (int)myDoc.body.getAttribute("scrollTop", 0); PrintWindow(hwnd, hdc, 0); g.ReleaseHdc(hdc); g.Flush(); screenfrag = Image.FromHbitmap(bm.GetHbitmap()); g2.DrawImage(screenfrag, brwLeft + URLExtraLeft, brwTop + URLExtraHeight); } ++myPageWidth; } //Draw Standard Resolution Guides if (chkShowGuides.Checked == true) { // Create pen. int myWidth = 1; Pen myPen = new Pen(Color.Navy, myWidth); Pen myShadowPen = new Pen(Color.NavajoWhite, myWidth); // Create coordinates of points that define line. float x1 = -(float)myWidth - 1 + URLExtraLeft; float y1 = -(float)myWidth - 1 + URLExtraHeight; float x600 = 600.0F + (float)myWidth + 1; float y480 = 480.0F + (float)myWidth + 1; float x2 = 800.0F + (float)myWidth + 1; float y2 = 600.0F + (float)myWidth + 1; float x3 = 1024.0F + (float)myWidth + 1; float y3 = 768.0F + (float)myWidth + 1; float x1280 = 1280.0F + (float)myWidth + 1; float y1024 = 1024.0F + (float)myWidth + 1; // Draw line to screen. g2.DrawRectangle(myPen, x1, y1, x600 + myWidth, y480 + myWidth); g2.DrawRectangle(myPen, x1, y1, x2 + myWidth, y2 + myWidth); g2.DrawRectangle(myPen, x1, y1, x3 + myWidth, y3 + myWidth); g2.DrawRectangle(myPen, x1, y1, x1280 + myWidth, y1024 + myWidth); // Create font and brush. Font drawFont = new Font("Arial", 12); SolidBrush drawBrush = new SolidBrush(Color.Navy); SolidBrush drawBrush2 = new SolidBrush(Color.NavajoWhite); // Set format of string. StringFormat drawFormat = new StringFormat(); drawFormat.FormatFlags = StringFormatFlags.FitBlackBox; // Draw string to screen. g2.DrawString("600 x 480", drawFont, drawBrush, 5, y480 - 20 + URLExtraHeight, drawFormat); g2.DrawString("800 x 600", drawFont, drawBrush, 5, y2 - 20 + URLExtraHeight, drawFormat); g2.DrawString("1024 x 768", drawFont, drawBrush, 5, y3 - 20 + URLExtraHeight, drawFormat); g2.DrawString("1280 x 1024", drawFont, drawBrush, 5, y1024 - 20 + URLExtraHeight, drawFormat); } //Write URL if (chkWriteURL.Checked == true) { //Backfill URL paint location SolidBrush whiteBrush = new SolidBrush(Color.White); Rectangle fillRect = new Rectangle(0, 0, widthsize, URLExtraHeight + 2); Region fillRegion = new Region(fillRect); g2.FillRegion(whiteBrush, fillRegion); SolidBrush drawBrushURL = new SolidBrush(Color.Black); Font drawFont = new Font("Arial", 12); StringFormat drawFormat = new StringFormat(); drawFormat.FormatFlags = StringFormatFlags.FitBlackBox; g2.DrawString(myLocalLink, drawFont, drawBrushURL, 0, 0, drawFormat); } //Reduce Resolution Size double myResolution = Convert.ToDouble(cmbResolution.Text) * 0.01; int finalWidth = (int)((widthsize + URLExtraLeft) * myResolution); int finalHeight = (int)((heightsize + URLExtraHeight) * myResolution); Bitmap finalImage = new Bitmap(finalWidth, finalHeight, System.Drawing.Imaging.PixelFormat.Format16bppRgb555); Graphics gFinal = Graphics.FromImage((Image)finalImage); gFinal.DrawImage(bm2, 0, 0, finalWidth, finalHeight); //Get Time Stamp DateTime myTime = DateTime.Now; String format = "MM.dd.hh.mm.ss"; //Create Directory to save image to. Directory.CreateDirectory("C:\\IECapture"); //Write Image. EncoderParameters eps = new EncoderParameters(1); long myQuality = Convert.ToInt64(cmbQuality.Text); eps.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, myQuality); ImageCodecInfo ici = GetEncoderInfo("image/jpeg"); finalImage.Save(@"c:\\IECapture\Captured_" + myTime.ToString(format) + ".jpg", ici, eps); //Clean Up. myDoc = null; g.Dispose(); g2.Dispose(); gFinal.Dispose(); bm.Dispose(); bm2.Dispose(); finalImage.Dispose(); Cursor.Current = Cursors.Default; }