Library tutorials & articles
Saving the DC context
- Introduction
- The Problem
- An even easier solution
- The code
Introduction
There are some problems with maintaining resources for drawing, such as pens, brushes, etc. When you select an object into a DC, that object becomes undeletable. You might exit the context in which it was allocated, and its destructor is called, and DeleteObject is ultimately called on it, but, surprise!, it hasn't really gone away. Because it was selected into a DC, there is a flag saying it is inactive use, and therefore your DeleteObject can't work. I don't know the actual details of how this works internally, but I know the external manifestation. The pen, brush, etc. simply stays in the "GDI heap".
If you are working on one of those horrid 16-bit windows-kludge-on-top-of-MS-DOS systems like Windows 3.1, Windows 3.11, Win98, Win98, or WinME, (and if you think that Win9x/ME is a 32-bit OS, you have (a) not read the API documentation carefully (b) believed Microsoft's consumer-level documentation and thought it was technical documentation) there is a very limited system-wide pool out of which all pens and brushes are allocated, and eventually not even your desktop can allocate the resources it needs to draw. On a real, 32-bit operating system such as NT/2000/XP, the GDI heap is much larger, and is per-process, so eventually your program won't be able to draw, but the rest of the system will work fine, since you are only allowed to shoot yourself in the foot.
Related articles
Related discussion
-
IT Service Desk Analyst
by aniamodis (0 replies)
-
Can somebody help: CAsyncSOcket class (Client-server networking)
by chong (5 replies)
-
Database connectivity using C++ code
by pkjena (0 replies)
-
Need help working with Ado.net
by personaje (0 replies)
-
conting repeated words
by Slicksim (2 replies)
Events coming up
-
Jun
16
Code Generation 2009
Cambridge, United Kingdom
A developer event with a practical focus on helping people get to grips with code generation tools and technologies.
This thread is for discussions of Saving the DC context.