Click here to Skip to main content
15,892,809 members
Home / Discussions / C#
   

C#

 
Questionbind textbox to XML node Pin
Jassim Rahma29-Mar-10 12:00
Jassim Rahma29-Mar-10 12:00 
QuestionReusable TableAdapters and such for Lookup Tables? Pin
Bert Edens29-Mar-10 11:40
Bert Edens29-Mar-10 11:40 
QuestionReading message Id's from a file?!? Pin
MWRivera29-Mar-10 11:13
MWRivera29-Mar-10 11:13 
AnswerRe: Reading message Id's from a file?!? Pin
Not Active29-Mar-10 12:12
mentorNot Active29-Mar-10 12:12 
GeneralRe: Reading message Id's from a file?!? Pin
MWRivera30-Mar-10 6:42
MWRivera30-Mar-10 6:42 
GeneralRe: Reading message Id's from a file?!? Pin
Not Active30-Mar-10 7:23
mentorNot Active30-Mar-10 7:23 
GeneralRe: Reading message Id's from a file?!? Pin
MWRivera30-Mar-10 8:04
MWRivera30-Mar-10 8:04 
QuestionHow to take the snapshot of a IE webpage through a BHO (C#) Pin
kumar kapil29-Mar-10 10:39
kumar kapil29-Mar-10 10:39 
Hi,

I am trying to build an IE BHO in C# for taking the snapshot of a webpage loaded in the IE browser. Here is what I'm trying to do:



public class ShowToolbarBHO : BandObjectLib.IObjectWithSite
{

IWebBrowser2 webBrowser = null;

public void SetSite (Object site)
{
.......
if (site != null)
{
......
webBrowser = (IWebBrowser2)site;
......
}
}
}


Also, I p/invoke the following COM methods:

[Guid("0000010D-0000-0000-C000-000000000046")]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
[ComImportAttribute()]
public interface IViewObject
{
void Draw([MarshalAs(UnmanagedType.U4)] int dwDrawAspect, int lindex, IntPtr pvAspect, [In] IntPtr ptd, IntPtr hdcTargetDev, IntPtr hdcDraw, [MarshalAs(UnmanagedType.LPStruct)] ref COMRECT lprcBounds, [In] IntPtr lprcWBounds, IntPtr pfnContinue, int dwContinue);
int GetColorSet([MarshalAs(UnmanagedType.U4)] int dwDrawAspect, int lindex, IntPtr pvAspect, [In] IntPtr ptd, IntPtr hicTargetDev, [Out] IntPtr ppColorSet);
int Freeze([MarshalAs(UnmanagedType.U4)] int dwDrawAspect, int lindex, IntPtr pvAspect, out IntPtr pdwFreeze);
int Unfreeze([MarshalAs(UnmanagedType.U4)] int dwFreeze);
int SetAdvise([MarshalAs(UnmanagedType.U4)] int aspects, [MarshalAs(UnmanagedType.U4)] int advf, [MarshalAs(UnmanagedType.Interface)] IAdviseSink pAdvSink);
void GetAdvise([MarshalAs(UnmanagedType.LPArray)] out int[] paspects, [MarshalAs(UnmanagedType.LPArray)] out int[] advf, [MarshalAs(UnmanagedType.LPArray)] out IAdviseSink[] pAdvSink);
}

[StructLayoutAttribute(LayoutKind.Sequential)]
public class COMRECT
{
public int left;
public int top;
public int right;
public int bottom;

public COMRECT()
{
}

public COMRECT(int left, int top, int right, int bottom)
{
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
}
}

[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
[ComVisibleAttribute(true)]
[GuidAttribute("0000010F-0000-0000-C000-000000000046")]
[ComImportAttribute()]
public interface IAdviseSink
{
void OnDataChange([In]IntPtr pFormatetc, [In]IntPtr pStgmed);
void OnViewChange([MarshalAs(UnmanagedType.U4)] int dwAspect, [MarshalAs(UnmanagedType.I4)] int lindex);
void OnRename([MarshalAs(UnmanagedType.Interface)] object pmk);
void OnSave();
void OnClose();
}


Now When I take the snapshot:

I make a call CaptureWebScreenImage((IHTMLDocument2) webBrowser.document);

public static Image CaptureWebScreenImage(IHTMLDocument2 myDoc) {
int heightsize = (int)getDocumentAttribute(myDoc, "scrollHeight");
int widthsize = (int)getDocumentAttribute(myDoc, "scrollWidth");

Bitmap finalImage = new Bitmap(widthsize, heightsize);
Graphics gFinal = Graphics.FromImage(finalImage);
COMRECT rect = new COMRECT();
rect.left = 0;
rect.top = 0;
rect.right = widthsize;
rect.bottom = heightsize;

IntPtr hDC = gFinal.GetHdc();
IViewObject vO = myDoc as IViewObject;

vO.Draw(1, -1, (IntPtr)0, (IntPtr)0, (IntPtr)0, (IntPtr)hDC, ref rect, (IntPtr)0, (IntPtr)0, 0);
gFinal.ReleaseHdc();

gFinal.Dispose();

return finalImage;
}
I am not getting the image of the webpage. Rather I am getting an image with black background. I am not sure if this is the right way of doing it, but I found over the web that IViewObject::Draw method is used for taking the image of a webpage in IE.

I was earlier doing the image capture using the Native PrintWindow() method as mentioned in the following codeproject's page - http://www.codeproject.com/KB/graphics/IECapture.aspx

But the image size is humongous! I was trying to see if I can reduce the size by using other techniques. It would be great if someone can point out the mistakes (I am sure there would be many) in my code above.

Thanks, Kapil
QuestionFilenames and open file dialog Pin
SRJ9229-Mar-10 8:58
SRJ9229-Mar-10 8:58 
AnswerRe: Filenames and open file dialog Pin
Wes Aday29-Mar-10 9:15
professionalWes Aday29-Mar-10 9:15 
AnswerRe: Filenames and open file dialog Pin
OriginalGriff29-Mar-10 9:32
mveOriginalGriff29-Mar-10 9:32 
GeneralRe: Filenames and open file dialog [modified] Pin
SRJ9229-Mar-10 9:46
SRJ9229-Mar-10 9:46 
GeneralRe: Filenames and open file dialog Pin
Not Active29-Mar-10 9:53
mentorNot Active29-Mar-10 9:53 
GeneralRe: Filenames and open file dialog Pin
SRJ9229-Mar-10 9:54
SRJ9229-Mar-10 9:54 
GeneralRe: Filenames and open file dialog Pin
Dave Kreskowiak29-Mar-10 10:00
mveDave Kreskowiak29-Mar-10 10:00 
GeneralRe: Filenames and open file dialog Pin
SRJ9229-Mar-10 10:07
SRJ9229-Mar-10 10:07 
QuestionDoes anybody have ups rate calculator for asp.net? Pin
bigeyed29-Mar-10 7:15
bigeyed29-Mar-10 7:15 
AnswerRe: Does anybody have ups rate calculator for asp.net? Pin
Not Active29-Mar-10 7:28
mentorNot Active29-Mar-10 7:28 
AnswerRe: Does anybody have ups rate calculator for asp.net? Pin
Dave Kreskowiak29-Mar-10 9:57
mveDave Kreskowiak29-Mar-10 9:57 
Questiondid you Google Block Gmail?! Pin
Jassim Rahma29-Mar-10 5:50
Jassim Rahma29-Mar-10 5:50 
AnswerRe: did you Google Block Gmail?! Pin
Richard MacCutchan29-Mar-10 6:41
mveRichard MacCutchan29-Mar-10 6:41 
GeneralRe: did you Google Block Gmail?! Pin
Jassim Rahma29-Mar-10 11:30
Jassim Rahma29-Mar-10 11:30 
GeneralRe: did you Google Block Gmail?! [modified] Pin
Richard MacCutchan29-Mar-10 11:41
mveRichard MacCutchan29-Mar-10 11:41 
QuestionTreeview aftercheck Pin
Wannes Geysen29-Mar-10 5:21
Wannes Geysen29-Mar-10 5:21 
AnswerRe: Treeview aftercheck Pin
Kevin Marois29-Mar-10 5:28
professionalKevin Marois29-Mar-10 5:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.