How do I know it's a valid gdi region handle?
or other gdi ha开发者_开发问答ndle, such as pen brush. how do i know is it valid?
You should never get yourself into a situation where you might be holding onto a handle that isn't valid. If necessary, set the handle to NULL after calling DeleteObject() so it is completely obvious. Assuming that a GDI function will give you a FALSE return value because you passed a bad handle isn't safe.
The answer is: where did you get the handle from?
Simply speaking, it's like with the art: how do you know it's authentic, not a fake? There're some "heuristics", but the only 100%-working way is to know where is it from.
So, regarding the GDI regions: you should only trust those region handles that are returned by GDI functions.
:)
Try GetObject()
or GetObjectType()
. They should return NULL if the object handle is invalid.
I can see where you'd want to use this for debugging. In a perfect world, we keep track of our objects and know where they are at all times.
Ours is not a perfect world.
精彩评论