by selftaught (17 Submissions)
Category: Graphics
Compatability: VB Script
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating:
(7 Votes)

That horrible bug found by Lavolpe scared me into spending half the night going over this code with a fine-tooth comb. Minor optimizations and major commenting added. Anyone who downloaded the code before this update will probably want to scrap the old version and grab this one. Also check out the new screenshot. If that's not stress testing, I don't know what is!
Inspired by Lavolpe's "GDI Font Management" submission, this code is a drop-in replacement for common gdi api calls. The benefits of using this code as opposed to the api calls directly are two-fold:
1. Identical fonts, brushes and pens are shared between all procedures who request them. A reference count is kept, and the objects are deleted when no longer in use.
2. Debugging is simple, simply change a few compiler constants and you will receive a debug message if any font, brush, pen, DC, or bitmap handles are leaked.
This code is very fast, because it hashes the gdi objects and uses a linked list to store the necessary information. Actually it's a bit more complicated than that because the nodes in the list must be looked up by the gdi object when creating an object and by the handle when destroying it. So two linked lists are kept, but only one set of nodes. One is used to lookup by the gdi object and the other by handle.