I need to be able to derive the color that was used to construct an HPEN handle. HPEN doesn't seem to be a pointer to a structure. What exactly is a handle, and how can I use it to get to the structure that backs it up?
Good Question!
1. Handles and Objects
An object is a data structure that represents a system resource, such as a file, thread, or graphic image. An application cannot directly access object data or the system resource that an object represents. Instead, an application must obtain an object handle, which it can use to examine or modify the system resource. Each handle has an entry in an internally maintained table. These entries contain the addresses of the resources and the means to identify the resource type. So , mainly , a handle is a pointer.
2. Each graphic-object class in the class library has a cast operator that will cast an MFC object to the associated Windows handle but not reverse:
CPen p1;
p1.CreateSolidPen( );
HPEN hToCPen = (HPEN) p1;
Leaving aside MFC (I'm using the SDK), then, it would appear there is no way to determine the color in a particular HPEN unless there is an accessor function made available by HPEN to get the color. And there is no way to translate a handle to a pointer, that being the reason for handles in the first place. If that's the case, your last statement in 1), that "mainly, a handle is a pointer" would be more accurately put that it functions like a pointer, except that it can't be used to directly access the object's data like a pointer could. Is that a correct assessment?
if it is, is there such an accessor function to get the color from an HPEN? I haven't been able to find such.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.