PullRank Home a tool to enable you to log the Google PageRank of a URL
Development History
The Code
Instead of writing my own code to programmatically grab a screenshot, I searched online for a snippet of C# code that would do it for me. Fortunately, my search was successful, and I found a nice little piece of code that did all the work for me – I didn't have to change a thing.

However, when I plugged the code into my PullRank infrastructure, I discovered that it would often snap the screenshot before the web page finished loading; thus, the PageRank would not be included in the screenshot. Instead of waiting for some arbitrary amount of time until it was "safe" to take the screenshot, I decided to try to register for an event that would fire when the InternetExplorer object finished loading the page. As there was such an event listed in the IE API, this seemed trivial to set up.

And it was. At least it was once I found an article online with an example of how to handle InternetExplorer events. I do not think that I could have figured out the syntax on my own:

// code in constructor:
InternetExplorer ie = new InternetExplorer();
ie.DocumentComplete += new
  SHDocVw.DWebBrowserEvents2_DocumentCompleteEventHandler(DocumentComplete);

// method defined elsewhere in class:
public void DocumentComplete(object pDisp, ref object URL) {
  Console.WriteLine("DocumentComplete");
  loaded = true;
}
As you can see, this uses operator overloading (+=) and passes the DocumentComplete method as a parameter. As a Java programmer, this syntax seemed "sloppy" to me, but I guess it worked.


References:
  1. Screen Capture Using C# and GDI+
  2. InternetExplorer Object API
  3. Responding to COM Events in .NET Applications


©2004 Michael Bolin » bolinfest@gmail.com www.bolinfest.com