Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1222
  • Last Modified:

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.
0
jhanson040697
Asked:
jhanson040697
  • 3
1 Solution
 
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
 
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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