|
The Device Context |
The Device Context A handle, you'll recall, is simply a number that Windows uses for internal reference to an object. You obtain the handle from Windows and then use the handle in other functions. The device context handle is your window's passport to the GDI functions. With that device context handle you are free to paint your client area and make it as beautiful or as ugly as you like. The device context (also called simply the "DC") is really just a data structure maintained internally by GDI. A device context is associated with a particular display device, such as a video display or a printer. For a video display, a device context is usually associated with a particular window on the display. Some of the values in the device context are graphics "attributes." These attributes define some particulars of how GDI drawing functions work. With TextOut, for instance, the attributes of the device context determine the color of the text, the color of the text background, how the x-coordinate and y-coordinate in the TextOut function are mapped to the client area of the window, and what font Windows uses when displaying the text. When a program needs to paint, it must first obtain a handle to a device context. When you obtain this handle, Windows fills the internal device context structure with default attribute values. As you'll see in later chapters, you can change these defaults by calling various GDI functions. Other GDI functions let you obtain the current values of these attributes. Then, of course, there are still other GDI functions that let you actually paint the client area of the window. After a program has finished painting its client area, it should release the handle. When a program releases the handle, the handle is no longer valid and must not be used. The program should obtain the handle and release the handle during the processing of a single message. Except for a device context created with a call to CreateDC (a function I won't discuss in this chapter), you should not keep a device context handle around from one message to another. Windows applications generally use two methods for getting a device context handle in preparation for painting the screen.
可知其实设备上下文是指的一种数据结构,是由图形设备接口内部所维护的,通常与特定的显示设备有关系,例如显示器,打印机.对于显示器来说,Device Context就和显示的特定的窗口有关. 设备上下文就是绘图的一些"属性值" 要想使用GDI绘图必须先要得到Device Context Handle,之后,WINDOW会以确省的值去真充Divece Context数据结构中的数据,在之后,我们就可以调用一些GDI的一些函数去改变这些值. | |
|
|
|
|