Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Difference between Painting in OnPaint and Painitng at other places?

Chaitanya_PuneChaitanya_Pune Member Posts: 87
When ever a Window needs to be repainted. OS sendes WM_PAINT mesage to our application. OnPaint handler gets called.

We can also do some painting in OnLButtonDown or other places.

To draw paint in OnPaint we create object of CPaintDC while to paint at other places we create object of CClientDC.

Can any one explain why so?


Comments

  • veliusvelius Member Posts: 456
    : When ever a Window needs to be repainted. OS sendes WM_PAINT mesage to our application. OnPaint handler gets called.
    :
    : We can also do some painting in OnLButtonDown or other places.
    :
    : To draw paint in OnPaint we create object of CPaintDC while to paint at other places we create object of CClientDC.
    :
    : Can any one explain why so?
    :
    :
    :
    The CPaintDC class calls BeginPaint() at contstruction time and EndPaint() at destruction time. This is how the Win32 API was designed. When drawing or painting outside of a response to WM_PAINT the use of CClientDC is used because it makes a call to GetDC() at construction time which returns a usable Device Context to the window. And then calls ReleaseDC() at destruction time to free the resources for you.

    So the CPaintDC uses BeginPaint() to fill in the PAINTSTRUCT struct and CClientDC uses GetDC() to represent only the Client Area. That is, you cannot use CClientDC for working with the border of your window but you can use CWindowDC for that.

    I hope that makes sense or at if I'm wrong someone will correct me.

    Good luck.
    [hr]
    We'll be an army of theives
    Of self-freed slaves
    Of mild-mannered maids
    We'll fight with whispers and blades
    So get ready, a new day is dawning
    - The New Wild West -- Jewel

Sign In or Register to comment.