Solved

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

Posted on 2002-03-18
5
1,095 Views
Last Modified: 2013-11-20
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
Comment
Question by:jhanson040697
  • 3
5 Comments
 
LVL 2

Expert Comment

by:shilpa_Jb
ID: 6879277
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
 
LVL 1

Expert Comment

by:kirthir
ID: 6879409
Why you want to use GetDC?

U can declare a CClientDC object instead

try this
CClientDC dc(this);
0
 
LVL 1

Expert Comment

by:kirthir
ID: 6879412
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
 
LVL 1

Accepted Solution

by:
kirthir earned 100 total points
ID: 6879413
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
 

Author Comment

by:jhanson040697
ID: 6881719
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Adapt this command to show who installed 29 112
move a line in eclipse 3 109
noX challenge 17 134
Work with App store 7 89
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question