Anyone think they could give me the low down on device contexts? I sort of think I know what they are... but could someone give me a specific, thorough (?), explanation? Can they be compared to buffers? Some general hardware abstraction thing? what?
Yup you got it: it's a general hardware abstraction thing. A device context is an abstraction of an output device, such as a video display (the "screen"), printer, or an individual window.
Technically, an HDC (handle to a device context) is a 32-bit unsigned integer. A handle, in general, is a number that Windows uses for internal reference to an object. Think of it as an index to a table that Windows keeps of all its millions of things (in this case, its output devices).
A device context is just a data structure maintained internally by the GDI. It stores stuff like the font associated with a window, the background color behind the font, and more. When you get a handle to a device context, Windows fills in the structure with default attributes (font, etc.)
The number you get in an HDC for your screen in one program can (and most likely *will*) be different in another program for the same screen. It's a bunch of dynamically allocated and indexed "stuff" that Windows worries about. That's how Microsoft puts it, and they probably leave it that way cuz we wouldn't WANT to know how it handles this stuff! (yikes!)
Since a DC is filled automatically with default attributes, you don't have to specify 101 things to a simple TextOut() function. You just have to give it the coordinates, the string to output, and the HDC. All of the GDI functions that render output to a display device take a handle to a device context (HDC), instead of having to specify every detail yourself.
**Windows supplies the majority of the rendering details, with default settings, in the form of a data strucutre Microsoft refers to as a Device Context.**
You can change the attributes of a DC -- you are not stuck with a default font! Say you had the HDC to a particular window. You can put any font into that DC to which you have a handle. Another way to say that is this: you can set the font the GDI text functions will use for THAT window.
Edited by - Steel on September 29, 2000 1:12:46 AM
Technically, an HDC (handle to a device context) is a 32-bit unsigned integer. A handle, in general, is a number that Windows uses for internal reference to an object. Think of it as an index to a table that Windows keeps of all its millions of things (in this case, its output devices).
A device context is just a data structure maintained internally by the GDI. It stores stuff like the font associated with a window, the background color behind the font, and more. When you get a handle to a device context, Windows fills in the structure with default attributes (font, etc.)
The number you get in an HDC for your screen in one program can (and most likely *will*) be different in another program for the same screen. It's a bunch of dynamically allocated and indexed "stuff" that Windows worries about. That's how Microsoft puts it, and they probably leave it that way cuz we wouldn't WANT to know how it handles this stuff! (yikes!)
Since a DC is filled automatically with default attributes, you don't have to specify 101 things to a simple TextOut() function. You just have to give it the coordinates, the string to output, and the HDC. All of the GDI functions that render output to a display device take a handle to a device context (HDC), instead of having to specify every detail yourself.
**Windows supplies the majority of the rendering details, with default settings, in the form of a data strucutre Microsoft refers to as a Device Context.**
You can change the attributes of a DC -- you are not stuck with a default font! Say you had the HDC to a particular window. You can put any font into that DC to which you have a handle. Another way to say that is this: you can set the font the GDI text functions will use for THAT window.
Edited by - Steel on September 29, 2000 1:12:46 AM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement