Unable to Get a Device Context (using CWnd::GetDC())

I'm writing an application that allows users to place bitmaps on the screen using the mouse. I need to draw bitmaps when the user pushes the mouse button or holds the button and drags. Therefore I can't just use the device context from the OnDraw function, I need to use GetDC() in the OnButtonDown and OnMouseMove functions. This works fine for the first few hundred bitmaps but eventually I get back NULL from the GetDC(). I have checked, and I can't find anyplace that I'm not calling ReleaseDC. Is there any other reason that calling GetDC could fail? It seems like I am using up some resource. Is it possible to get this problem by using up some resource other than device contexts? I have also noticed that once I start getting NULL back from GetDC, none of the other windows in my app will display correctly. By the way, I am using VC++ 5 and running Windows XP.
jhanson040697Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
kirthirConnect With a Mentor Commented:
The constructor of CClientDC takes care of calling GetDC() and destructor takes of ReleaseDC(),
If you want to do it manually, u need to be more careful in coding
0
 
shilpa_JbCommented:
Hi,
Just check for the return value of the RealseDC() i suspect that its not releasing the resource and hence GetDC
is returning NULL.
-Shilpa
0
 
kirthirCommented:
Why you want to use GetDC?

U can declare a CClientDC object instead

try this
CClientDC dc(this);
0
 
kirthirCommented:
The constructor of CClientDC takes care of calling GetDC() and destructor takes of ReleaseDC(),
If you want to do it manually, u need to be more careful in coding
0
 
jhanson040697Author Commented:
Thanks for the help. I replaced all the GetDCs with ClientDCs an it fixed my problem. I must have missed a ReleaseDC somewhere.
0
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.

All Courses

From novice to tech pro — start learning today.