Saturday, November 5, 2011

Device Context, a Closer Look of .Graphics Under Windows in C programming

Now that we have written a few programs and are comfortable with idea of selecting objects like font, pen and brush into the DC, it is time for us to understand how Windows achieves the device independent drawing using the concept of DC. In fact a DC is nothing but a structure that holds handles of various drawing objects like font, pen, brush, etc. A screen DC and its working is







You can make following observations from Figure 18.6:

(a) The DC doesn’t hold the drawing objects like pen, brush, etc. It merely holds their handles.
(b) With each DC a default monochrome bitmap of size 1 pixel x 1 pixel is associated.
(c) Default objects like black pen, white brush, etc. are shared by different DCs in same or different applications
(d) The drawing objects that an application explicitly creates can be shared within DCs of the same application, but is never shared between different applications.
Two different applications would need two different DCs even though both would be used to draw to (e) the same screen. In other words with one screen multiple DCs can exist.
(f) A common Device Driver would serve the drawing requests coming from different applications. (Truly speaking the request comes from GDI functions that our application calls).
Screen and printer DC is OK, but what purpose would a memory DC serve? Well, that is what the next program would explain.

No comments:

Post a Comment