Click here to Skip to main content
14,608,158 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi,

The feature i'm trying to achieve is something like Firefox's Screengrab Add-On. I've found some links but most of them required me to either

1. Save the page as HTML/MHTML and convert it to image -> Can't do this because it'll loose the CSS style
2. Pass in the URL of the page to convert to image -> Won't work in password required sites.

It doesn't have to only run on Firefox. I just need to be able to do it either on Firefox or IE. :sigh:

Please help.
Posted
Comments
Shani Natav 30-Dec-10 4:00am
   
Server Side, or winforms?
eight 30-Dec-10 5:09am
   
it's on the client side
Rate this:
Please Sign up or sign in to vote.

Solution 2

I do it in this way.

IViewObject2*          view = 0;
IWebBrowser2*          wbb = 0;
unsigned int          connid = 0;
IOleObject*            oleo = 0;
IOleInPlaceObject*    oipo = 0;
iOleClientSite*        iolesite = 0;
RECT                  rc = {0,0,100,100};
MSG                    msg; memset(&msg,0,sizeof(msg));

Empty();
iolesite = new iOleClientSite; if(!iolesite) return E_OUTOFMEMORY;

if(S_OK==(hr=CoCreateInstance(IID_IInternetExplorer,0,CLSCTX_INPROC_SERVER,IID_IWebBrowser2,(void**)&wbb)))
{
  if(S_OK==wbb->QueryInterface(IID_IOleObject,(void**)&oleo))
  {
    oleo->SetClientSite(iolesite);
    connid = ConnectSink(oleo,IID_DWebBrowserEvents2,(bUnk*)iolesite);
    oleo->DoVerb(OLEIVERB_INPLACEACTIVATE,&msg,iolesite,0,iolesite->_hwnd,&rc);
    oleo->Release(); oleo = 0;

    iolesite->Resize(wbb,_sil.cx,_sil.cy);
  }

  {
    tArr<unsigned short>    wstr(8+strlen(file)); MultiByteToWideChar(0,0,file,1+strlen(file),wstr.array,wstr.count);
    VARIANT                  v; v.vt = VT_BSTR; v.bstrVal = SysAllocString(wstr.array);
    VARIANT                  i; i.vt = VT_INT; i.lVal = 0;
    READYSTATE              ready;

    hr = wbb->Navigate2(&v,&i,0,0,0);

    while((S_OK==wbb->get_ReadyState(&ready)) && (READYSTATE_COMPLETE!=ready) && GetMessage(&msg,0,0,0))
    {
      DispatchMessage(&msg);
    }

    VariantClear(&v);
    VariantClear(&i);
  }

  IDispatch*    app = 0;
  if((S_OK==hr) && (S_OK==wbb->get_Document(&app)) )
  {
    if(app)
    {
      _Object    obj(app,1);
      int        cxy = 0;
      int        cxr = 0; // rahmen kann nicht ermittelt werden
      int        cyr = 0;


      if(obj["body"].get("scrollHeight",cxy)) _sil.cy = cxy+cyr;
      if(obj["body"].get("scrollWidth" ,cxy)) _sil.cx = cxy+cxr;

      TRACE("document.body.scrollWidth = %i\r\ndocument.body.scrollHeight = %i\r\n",_sil.cx,_sil.cy);

      iolesite->Resize(wbb,_sil.cx,_sil.cy);

      if(obj["body"].get("scrollHeight",cxy)) _sil.cy = cxy+cxr;

      if(forcecx) _sil.cx = forcecx;

      iolesite->Resize(wbb,_sil.cx,_sil.cy);

      if(S_OK==app->QueryInterface(IID_IViewObject2,(void**)&view))
      {
        HDC                hdcm = CreateCompatibleDC(0);
        RECTL              rcbound = { 0,0,_sil.cx,_sil.cy };
        HGDIOBJ            obmp;
        BITMAPINFO        bmi;
        unsigned int      bpl;

        if(forcecy) _sil.cy = min(_sil.cy,forcecy);

        bmi.bmiHeader.biSize          = sizeof(bmi);
        bmi.bmiHeader.biWidth         = _sil.cx;
        bmi.bmiHeader.biHeight        = _sil.cy;
        bmi.bmiHeader.biPlanes        = 1;
        bmi.bmiHeader.biBitCount      = 24;
        bmi.bmiHeader.biCompression   = 0;

        bpl = (((bmi.bmiHeader.biWidth*bmi.bmiHeader.biBitCount)>>3)+3)&~3;
        bmi.bmiHeader.biSizeImage     = bmi.bmiHeader.biHeight*bpl;
        bmi.bmiHeader.biXPelsPerMeter = 0;
        bmi.bmiHeader.biYPelsPerMeter = 0;
        bmi.bmiHeader.biClrUsed       = 0;
        bmi.bmiHeader.biClrImportant  = 0;

        _hbmp = CreateDIBSection(hdcm,&bmi,DIB_RGB_COLORS,0,0,0);

        obmp = SelectObject(hdcm,_hbmp);
        hr = view->Draw(DVASPECT_CONTENT,-1,0,0,0,hdcm,&rcbound,0,__fnContDraw,0);
        SelectObject(hdcm,obmp);

        DeleteDC(hdcm);
        view->Release(); view = 0;
      }
      app->Release(); app = 0;
    }
  }



  if(S_OK==wbb->QueryInterface(IID_IOleObject,(void**)&oleo))
  {
    DisconnectSink(oleo,IID_DWebBrowserEvents2,(bUnk*)iolesite,connid);
    oleo->SetClientSite(0);
    oleo->Release(); oleo = 0;
  }

  wbb->Release();
}
iolesite->Release();
   
v2
Comments
Espen Harlinn 5-Jan-11 11:26am
   
5+ nice piece of code - simple and clean
eight 5-Jan-11 21:05pm
   
Thanks mbue
Rate this:
Please Sign up or sign in to vote.

Solution 1

For Internet explorer , you can create browser helper object(BHO). BHO are plugins for internet explorer.It must be a good start.

You can do something similar to http://h71028.www7.hp.com/hho/cache/482779-0-0-225-121.html[^] with BHO.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100