Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing handle attributes

Status
Not open for further replies.

LyMc

Programmer
Jun 3, 2003
84
US
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;

-obislavu-
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top