Hello all,
I'm currently playing around with giving a dialog different colors than the standard one, and have ran into a bit of a problem:
I want to mix using the results of CreateSolidBrush and GetSysColorBrush.
The thing is that while the latter handles do need to be deleted, the former ones must be (otherwise GDI resource leakage will occur).
While calling DeleteObject on a GetSysColorBrush handle doesn't do anything, accidentily prematurily deleting a CreateSolidBrush handle causes "bad things" to happen.
So:
tl;dr:
I would like to cache (lock?) my CreateSolidBrush handle just like the GetSysColorBrush handle is said to be. How do I do that ?
Regards,
Rudy Wieser
P.s.
I tried to take a peek into the CreateSolidBrush result handle (in an
attempt to compare the cached and non-cached brush in search for a "lock" bit), but alas, it seems to be stored somewhere where I am not allowed to even look at it ....
There's no way to lock GDI handles.
You'll just have to conditionally delete the handles, or create
a new brush with the same color as the system brush.
"System color brushes are owned by the system so you don't
need to destroy them. Although you don't need to delete the
logical brush that GetSysColorBrush returns, no harm occurs
by calling DeleteObject."
They're not listed in the process' GDI handles list within the
process TEB (check with Nirsoft GDIView).
But DeleteObject() is the one which protects stock objects.
DeleteObject() at least, actively protects them. The kernel function
may or may not protect them. I don't bother to check because
debugging the kernel is a pain in Windows NT.
Even if there is such flag, it would be within the internal data structure
of the GDI object. But in Windows NT, GDI object's data is within the
kernel address space. So, there's no way to reach it from the user mode application without custom driver, or without undocumented function (if
there is any).
But DeleteObject() is the one which protects stock objects.
Does it ? I wonder ...
In the above case I could imagine that DeleteObject simply
doesn't get the list of stock objects, meaning that it can't find the to-be-deleted object and thus doesn't do anything.
Than again, I was hoping I would be able to find a "don't delete" flag in
the object itself - which certainly does need the cooperation of DeleteObject.
They're not listed in the process' GDI handles list within the
process TEB (check with Nirsoft GDIView).
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 399 |
Nodes: | 16 (3 / 13) |
Uptime: | 63:44:05 |
Calls: | 8,354 |
Calls today: | 14 |
Files: | 13,159 |
Messages: | 5,893,697 |
Posted today: | 1 |