Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 740
  • Last Modified:

Render a CHtmlView to a memory device context?


I have 2 questions:
1)  how would I go about to render a CHtmlView to a memory device context?
    what member functions would I have to overload?
    (Just BitBlt-ing to a memory device context won't be enough.
    I need to actually render to such a DC instead of to the screen.

2)  When I use OnPaint then whatever I paint is drawn BEFORE I see the
    webpage that CHtmlView.  So for example I see my painted stuff flicker
    up for a very brief time and then it gets overwritten by the webpage.
    How would I go about to paint something ON TOP of the webpage?

Thank you for your answers!
  • 2
1 Solution
In For Instance OnPaint
     // Memory DC compatible your window
        CDC cdcMem;
      cdcMem.Attach ( OnPaintsDC )

     // Get the raw screen coords of the window
        CRect rect;
     GetWindowRect  ( rect );

        // Create the bitmap compatible
     HBITMAP hBmp = NULL;
     HDC hdc = ::GetDC ( pDC );
     CDC* pDC = new CDC;
     pDC->Attach ( hdc );
    hBmp = CreateCompatibleBitmap ( pDC->GetSafeHdc (), rect.right - rect.left, rect.bottom - rect.top );

    // Move memory area into the bitmap
    HGDIOBJ hOld = cdcMem.SelectObject ( hBmp );
     cdcMem.BitBlt( 0, 0, rect.right - rect.left, rect.bottom - rect.top, pDC, rect.left,rect.top, SRCCOPY );

     // done dc
        ReleaseDC ( pDC );

     // clean up
     cdcMem.SelectObject ( hOld );
        cdcMem.Detach ();

     delete pDC;
You are calling the default ::OnPaint () too soon
Call OnPaint First then do your drawing
Alternatively do you painting in OnEraseBackground and retyrn TRUE from OnEraseBackGround
rhoeppergerAuthor Commented:
williamcampbell, thanks a lot for your help.  I will try your suggestions tonight or first thing tomorrow morning.

Thanks a lot!
I would like to accept williamcampbell's answer (and thank you for it!) but don't see the buttons "Accept answer"...
Could you please accept the answer for me Dan?  Thank you.

Thanks WilliamCampbell!


Hi Dan,

My name in Austria is Höpperger which in English can be represented as hoepperger or hopperger.  As experts-exchange did not allow umlauts, I used rhoepperger while I was still living in Europe.  I moved to America 4 years ago and here my name is Hopperger and so I used rhopperger as my username.   That's probably how this two account-scenario happened.

Anyway,  I CAN log on as rhopperger (the newer account) but no matter what I try, I CANNOT log on as rhoepperger.  I get a weird error page (SQL errors and such...) if I try.

So I have no means of loging on as rhoepperger and also cannot give anybody the points for the answer.
As I cannot log onto the site as rhoepperger anyway, there will also be no more problem in the future.  The few questions that are still open as rhoepperger will be closed soon and every new question will be under rhopperger.

I accept williamcampbell as the guy who gets the points.  Thanks William!  And sorry for not closing the question earlier.

And thank you to all, who spent time answering the question.

Kind regards

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now