Showing posts with label Internet Explorer Automation using C#. Show all posts
Showing posts with label Internet Explorer Automation using C#. Show all posts

Oct 27, 2008

C# - How to take a screenshot of Internet Explorer

Asuming you have InternetExplorerClass instance, named ie, you can do the following to obtain screenshot:



                  
int screenWidth = ie.Width;
                  
int screenHeight = ie.Height;

                   #region Get IE Bitmap

                  
Bitmap b = new Bitmap(ie.Width, ie.Height);
                  
Graphics g = Graphics.FromImage(b);
                  
IntPtr hdc = g.GetHdc();

                  
bool result = PrintWindow((IntPtr)ie.HWND, hdc, 0);

                   g.ReleaseHdc();
                   g.Flush();
/>                   b.Save(@"filename.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);


You will also need to add the PrintWindow function (it is windows API function):

     [
DllImport("user32.dll")]
    
private static extern bool PrintWindow(IntPtr hwnd, IntPtr hdcBlt,
        
uint nFlags);

Not that hard, but not well documented. If you don't know how to get a pointer to a running Internet Explorer class, you can do the following:

1. Add reference to ShDocVw (it is in the COM tab and it should be named "Microsoft Objects Automation library" or something like this)
2. Add the following code:

        SHDocVw.
ShellWindowsClass windows = new ShellWindowsClass();

foreach (SHDocVw.InternetExplorer explorer in windows)
        {
          
if (explorer.LocationURL == string.Empty)
           {
            
// this is our guy!
             ie = explorer;
           }
        }
NOTE: please be sure to use your own if statement. This one will get an instance to the last found Internet explorer which has an empty string as Location.


Happy C# programming!

Oct 16, 2008

C# - Web Browser Control - Load String in Web Browser control (4th way).

Here is one more way to load string in Web Browser Control (C#). This is in case you are using the managed control.

        
// Fourth way to write html in WebBrowserControl with C#:
        wb.DocumentText = strHtml;

I can tell you (just guessing) that this will be the best one as it became available in the managed control (at least I didn't found it in the old COM versions). That is why I think it was reviewed and probably optimized.
>

Jun 10, 2007

What happened with the Data mining?

Well, I simply stopped the project for a while, since I need to see the legal aspects of it. I am not quite sure if it is legal to simply take some catalogs from somewhere, reformat them and use them as your own. I think I can do such thing with some free public catalogs, but I will not act, until I have the written permission from the authors. Here are two screenshots of the spider in action :



The above screenshot is when the spider is gathering data. It displays how much data is gathered and what the spider is doing in the given moment.



The above screenshot displays the results of the crawl as a treeview. It uses MS Access database to store the data (since it is a small project).

Technologies used for the spider :
/>.NET 1.1 (Windows Forms), MS Access, Internet Explorer Automation COM Libraries (AxWebBrowser, ShDocVW COM mshtml).