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

Diff Betwn CClientDC & CWindowDC??

What is the difference between MFC classes "CClientDC" and "CWindowDC"??? Both the classes are derived from CWnd and have a protected "hWnd" member variable(afxwin.h). What scenario suits the usage of which class????

1 Solution
CClientDC by default only includes the client area of your window while CWindowDC contains the non-client area as well.

clientdc is the area returns from
and Windowsdc
is what returns from GetWindowRect() including the statusbar and the toolbar and menu area
CClientDC objects encapsulate working with a device context that represents only the client area of a window. The CClientDC constructor calls the GetDC function, and the destructor calls the ReleaseDC function. CWindowDC objects encapsulate a device context that represents the whole window, including its frame. A CWindowDC object accesses the entire screen area of a CWnd (both client and nonclient areas).

CClientDC creates a a client area DC that can be used outside OnPaint. Means its scope is not limited to OnPaint function. you can call it in any function when you want to to do drawing operation for that window. e.g. In button down messages..

You can make use of CwindowDC for drawing operation on client as well as non-client ares of the window like title bar, borders. This is most commonly used when u want to draw on non-client areas e.g. cutomized title bars :) But the best approach for this situation is handling WM_NCPAINT maessage.

kbshaAuthor Commented:
Comments from naveenkohli were really elobarative. Thanks for all of u....
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

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