HDC? Handle?
What is an HDC? What are handles? How do they come into use? HELP?
I saw this code
HDC hdc
pbuf->GETDC(hdc);
//other stuff
pbuf->ReleaseDC(hdc);
What is an HDC? And what is a Handle? AHHHH!
It''s an ID to an object in the Windows API. It''s used instead of pointers.
HDC is a handle to a Device Context, which is what GDI uses for buffers, so that it can correctly blit images and such.
Look it up in the Win32 API
HDC is a handle to a Device Context, which is what GDI uses for buffers, so that it can correctly blit images and such.
Look it up in the Win32 API
A HDC is a handle to a DEVICE CONTEXT. "A device context is basically a shorthand for a pile of settings for a particular device: 20 settings to be precise. These settings are used as a default whenever you make a call to a graphics function, avoiding the need for the function to have 20 additional parameters. You can think of the device context as a sort of set of "environment" variables for the GDI. You can change the settings by calling certain GDI functions with the handle of the device context as the first parameter." - from Black Art of Windows Game Programming - Eric. R. Lyons - pg 154.
"- To begin with, said the Cat, a dog's not mad. You grant that? - I suppose so, said Alice. - Well, then, - the Cat went on - you see, a dog growls when it's angry, and wags its tail when it's pleased. Now I growl when I'm pleased, and wag my tail when I'm angry. Therefore I'm mad."
Allright. I now understand. But what, then, is the difference between a handle and a pointer?
Nothing really, the handle is used the same way as a pointer. It''s not a pointer though so don''t try to use it as one.
I think it something that Microsoft came up with to keep their Windows API more object oriented before C++ came along. I''m not sure though, so don''t blame me if I''m wrong =)
I think it something that Microsoft came up with to keep their Windows API more object oriented before C++ came along. I''m not sure though, so don''t blame me if I''m wrong =)
A handle is a number that tells windows of a resource. Resources are what windows basically loans to you program so you create various windows and windows types.
There are different types of handles for different types of resources, but down underneath they are all still the same type (long, but it is been awhile since I checked so it could be something else). When you create a window, or resource you will get a handle to it, that handle can then be used to tell windows how the manipulate that resource or get the HDC of the resource.
A pointer is just that, a variable that points to a location in memory. If windows handed you a pointer to a window, you wouldn't be able to alter it or do what you needed. Windows stores all the information for each window in a separate place, so a pointer would simple not do. That is why it give you a handle to a resource. That way windows finds the data for you and alters it, so you don't have to keep track of twenty pointers to alter the data.
Hope this clears everything up.
-Omalacon
Edited by - Omalacon on 2/9/00 8:00:58 PM
There are different types of handles for different types of resources, but down underneath they are all still the same type (long, but it is been awhile since I checked so it could be something else). When you create a window, or resource you will get a handle to it, that handle can then be used to tell windows how the manipulate that resource or get the HDC of the resource.
A pointer is just that, a variable that points to a location in memory. If windows handed you a pointer to a window, you wouldn't be able to alter it or do what you needed. Windows stores all the information for each window in a separate place, so a pointer would simple not do. That is why it give you a handle to a resource. That way windows finds the data for you and alters it, so you don't have to keep track of twenty pointers to alter the data.
Hope this clears everything up.
-Omalacon
Edited by - Omalacon on 2/9/00 8:00:58 PM
Some handles are actually pointers into kernel protected memory space. Once the kernel gets a hold of them, they treat them as normal pointers. You can''t access that memory, though; you''ll protection fault. Some other handles are just indices into kernel tables. Either way, you can''t do anything with the other than hand them to API functions.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement