毕业设计外文资料译文-基于个人日程管理系统备忘录的设计与实现_第1页
毕业设计外文资料译文-基于个人日程管理系统备忘录的设计与实现_第2页
毕业设计外文资料译文-基于个人日程管理系统备忘录的设计与实现_第3页
毕业设计外文资料译文-基于个人日程管理系统备忘录的设计与实现_第4页
毕业设计外文资料译文-基于个人日程管理系统备忘录的设计与实现_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

毕业设计外文资料译文Advanced MFC Programming Chapter 8:DC, Pen, Brush and Palette 8.0 Device Context & GDI ObjectsStarting from this chapter, we are going to study topics on GDI (Graphics Device Interface) programming.SituationGDI is a standard interface between the programmer and physical devices. It provides many functions that can be used to output various objects to the hardware (e.g. a display or a printer). GDI is very important because, as a programmer, we may want our applications to be compatible with as many peripherals as possible. For example, almost every application need to write to display, and many applications also support printer output. The problem here is that since a program should be able to run on different types of devices, it is impossible to let the programmer know the details of every device and write code to support it beforehand.The solution is to introduce GDI between the hardware and the programmer. Because it is a standard interface, the programmer doesnt have to have any knowledge on the hardware in order to operate it. As long as the hardware supports standard GDI, the application should be able to execute correctly.Device ContextAs a programmer, we do not output directly to hardware such as display or printer. Instead, we output to an object that will further realize our intention. This object is called device context (DC), it is a Windows object that contains the detailed information about hardware. When we call a standard GDI function, the DC implements it according to hardware attributes and configuration. Suppose we want to put a pixel at specific logical coordinates on the display. If we do not have GDI, we need the following information of the display in order to implement this simple operation:1Video memory configuration. We need this information in order to convert logical coordinates to physical buffer address. 2Device type. If the device is a palette device, we need to convert a RGB combination to an index to the color table and use it to specify a color. If the device is a non-palette device, we can use the RGB combination directly to specify a color.Because the actual devices are different form one type to another, it is impossible for us to gather enough information to support all the devices in the world. So instead of handling it by the programmer, GDI functions let us use logical coordinates and RGB color directly, the conversion will be implemented by the device driver.GDI ObjectsIn Windows, GDI objects are tools that can be used together with device context to perform various drawings. They are designed for the convenience of programmers. The following is a list of some commonly used GDI objects:GDI objects UsagePen Used to draw line, curve, the border of a rectangle, ellipse, polygon, etc.Brush Used to fill the interior of a rectangle, ellipse, polygon with a specified patternFont Used to manage a variety of fonts that can be used to output textPalette Used to manage colors on a palette deviceBitmap Used to manage image creating, drawing, manipulating, etcThe above GDI objects, along with device context, are all managed through handles. We can use the handle of an object to identify or access it. Besides the handles, every GDI object has a corresponding MFC class. The following is a list of their handle types and classes:Object Handle Type MFC ClassObject Handle Type MFC ClassDevice Context HDC CDC, CClientDC, CWindowDC, etc.Pen HPEN CPenBrush HBRUSH CBrushFont HFONT CFontPalette HPALETTE CPaletteBitmap HBITMAP CBitmapObtaining DCAs a programmer, most of the time we need to output to a specific window rather than the wholescreen. A DC can be obtained from any window in the system, and can be used to call GDI functions.There are many ways to obtain DC from a window, the following is an incomplete list:1Call function CWnd:GetDC(). This function will return a CDC type pointer that can be used to perform drawing operations within the window.2Declare CClientDC type variable and pass a CWnd type pointer to its constructor. Class CClientDC is designed to perform drawing operations in the client area of a window.3Declare CWndowDC type variable and pass a CWnd type pointer to its constructor. Class CWindowDC is designed to perform drawing operations in the whole window (including client area and non-client area).4 In MFC, certain member functions are designed to update applications interface (i.e. CView:OnDraw (). These functions will automatically be called when a window needs to be updated. For this kind of functions, the device context will be passed through one of functions parameters.Using DC with GDI ObjectsBefore calling any function to perform drawing, we must make sure that an appropriate GDI object is being selected by the DC. For example, if we want to draw a red line with a width of 2, we must select a solid red pen whose width is 2. The following steps show how to use DC together with GDI objects:1Obtain or create a DC that can be used to perform drawing operations on the target window.2 Create or obtain an appropriate GDI (pen, brush, font) object.3 Select the GDI object into the DC, use a pointer to store the old GDI object.4 Perform drawing operations.5 Select the old GDI object into the DC, this will select the new GDI object out of the DC. Destroy the GDI object if necessary (If the GDI object was created in step 2 and will not be used byother DCs from now on).The following sections will discuss how to use specific GDI objects to draw a kind of graphicObjects(ie. Rectangle)RectangleIt is easy to implement rectangle drawing after we understand the previous knowledge. To draw a rectangle, we need to call function CDC:Rentangle() and pass a CRect type value to it. The rectangles border will be drawn using current pen selected by the DC, and its interior will be filled with the currently selected brush. We can declare a brush type variable using class CBrush, and create various kind of brushes by calling any of the following functions: CBrush:CreateSolidBrush(), CBrush:CreateHatchBrush(), CBrush:CreatePatternBrush(). In Windows, there are severalpre-implemented default GDI objects that can be retrieved and used at any time. These objects include pens, brushes, fonts, etc. We can get any object by calling :GetStockObject() API function. There turned value is a handle that could be attached to a GDI variable (declared by MFC class) of the same type. When a rectangle is not finally fixed, we may want to draw only its border and leave its interiorunpainted. To implement this, we can select a NULL (hollow) brush into the device context. A hollowbrush can be obtained by calling function :GetStockObject() using HOLLOW_BTRUSH or NULL_BRUSH flag.With the above implementation, the application will be able to let the user draw rectangles. With only minor modifications we can let the application draw ellipses. To draw an ellipse, we need to call function CDC:Ellipse()and pass a CRect type value to it. This is exactly the same with calling function CDC:Rectangle(). So in the previous sample, if we change all the “Rectangle” keywords to “Ellipse”, the application will be implemented to draw ellipses instead of rectangles.FontFont is another very important GDI object, every application deals with font. Usually a systemcontains some default fonts that can be used by all the applications. Besides these default fonts, we can also install fonts provided by the thirty party. For word processing applications, using font is a complex issue. There are many things we need to take care. For example, when creating this type of applications, we need to think about the following issues: how to display a font with different styles; how to change the text alignment; how to add special effects to characters.When we implement a font dialog box, all the available fonts contained in the system will be listed in it. We can select font size, font name, special styles, and text color.Like other GDI objects such as pen and brush, we need to create font with specific styles and select it into a DC in order to use it for outputting text. In MFC, the class that can be used to implement font is CFont. To create a font, we can call either CFont:CreateFont() or CFont:CreateFontIndirect(), whose formats are listed as follows:BOOL CFont:CreateFont ( int nHeight, int nWidth,int nEscapement, int nOrientation, int nWeight,BYTE bItalic, BYTE bUnderline, BYTE cStrikeOut,BYTE nCharSet, BYTE nOutPrecision, BYTE nClipPrecision, BYTE nQuality,BYTE nPitchAndFamily, LPCTSTR lpszFacename );BOOL CFont:CreateFontIndirect(const LOGFONT *lpLogFont);The first function has many parameters and the second one needs only a LOGFONT type pointer. The results of the two member functions are exactly the same, every style we need to specify for a font in the first function has a corresponding member in structure LOGFONT:typedef struct tagLOGFONTLONG lfHeight;LONG lfWidth;LONG lfEscapement;LONG lfOrientation;LONG lfWeight;BYTE lfItalic;BYTE lfUnderline;BYTE lfStrikeOut;BYTE lfCharSet;BYTE lfOutPrecision;BYTE lfClipPrecision;BYTE lfQuality;BYTE lfPitchAndFamily;TCHAR lfFaceNameLF_FACESIZE; LOGFONT;Here, member lfFaceName specifies the font name; lfHeight and lfWidth specify font size; lfWeight,lfItalic, lfUnderline and lfStrikeOut specify font styles. Besides these styles, there are two other styles that can be specified: lfEscapement and lfOrientation. If they are non-zero, the text will have an angle with respect to the horizontal border of the window when it is displayed . To display text this way, we must assign the angle to both lfEscapement and lfOrientation when creating the font, the unit of the angle is one tenth of a degree. Please note that only True Type fonts can have such orientation.节选自Advanced MFC Programming第八章 DC, Pen, Brush and Palette8.0 节:设备环境 DC 及 图形设备接口(GDI)对象从这一章开始,我们将要学习图形设备接口 GDI 编程。概述图形设备接口(GDI)是在程序员和物理设备之间的一个标准的接口。它提供了许多函数,调用这些函数可以将图形绘制在硬件(如显示器或打印机)上。可见图形设备接口GDI 非常重要,因为作为一个程序员,我们也许需要应用程序能适用于尽可能多的外围设备。举例来说,几乎每个应用软件都需要在显示器显示数气,而且同样多数应用软件也需要支持打印机输出。现在问题出现在这里:由于一个应用程序应该能支持不同的设备,而让程序员知晓每一个外围设备的细节并且事先写代码支持它,这几乎是一件不可能的事。解决方案是在设备和程序员之间引入图形设备接口GDI,它是一个标准的接口,有了它程序员可以不需要有任何的硬件设备知识就能实现对硬件的操作(输出)。只要硬件设备支持标准的图形设备接口GDI,应用程序就能正确的执行。设备环境(DC)作为一个程序员,我们不需要直接输出(应用程序的输出)到硬件设备诸如:显示器或打印机。而是输出到一个虚拟逻辑设备,由它来实现我们对物理设备输出的意图。这个虚拟逻辑设备就是设备环境DC,它是一个Windows数据结构,该结构包含向有关设备输出所需的信息。当我们调用一个标准的GDI 函数时,设备环境依照物理设备的属性和配置来实现对其的操作。 假如我们想要输出一个像素到显示的一个特定的坐标,如果我们没有图形设备接口GDI,为了实现这个简单的操作,我们需要下面的显示器信息。1. 视频设备存储配置信息。我们需要这些信息把逻辑坐标转化为物理缓存地址。2. 设备类型。如果是一个调色板设备,我们需要把一个 RGB 组合索引到一个颜色表,用颜色表来表示一个特定的颜色。而对于非调色板设备,我们能直接用RGB组合表示某种颜色。由于现实世界中的设备有多种多样,获得足够的信息以支持所有的设备对我们来说是不可能的。而由GDI函数取代由程序员处理物理设备输出,它让我们直接使用逻辑坐标和RGB组合,从而转换工作交给设备驱动来完成。图形设备接口(GDI)对象在Windows中,图形设备接口(GDI)对象是和设备环境一起实现绘图的工具。有了这些工具极大的方便了程序员。下面是一些常用的图形设备接口(GDI)对象列表:GDI对象 用法:画笔 用于画线,曲线,长方形,椭圆,多角形等的边缘。画刷 用于填充长方形,椭圆,或特殊的多边形的内部。字体 用于处理多种字型以方便文本输出。调色板 用于在调色板设置上设置颜色位图 用于处理图像生成,绘制,操作等等。以上的图形设备接口(GDI)对象与设备环境一起,都是通过句柄来处理(实现)。我们可以使用对象的句柄去定义和访问对象。除句柄外,每个GDI对象还有一个相应的MFC类,以下是句柄类型及相应的MFC类列表:GDI对象 句柄类 MFC 类设备环境 HDC CDC, CClientDC, CWindowDC, etc.画刷 HPEN CPen画刷 HBRUSH CBrush字体 HFONT CFont调色板 HPALETTE CPalette位图 HBITMAP CBitmap获取设备环境作为一个程序员,我们大多数时间的工作是要输出(数据)到一个特定的窗口,而不是整个显示器的银屏。因些就必须能系统中的任何窗口都可以获得设备环境,并且能用于调GDI函数。有许多方法可以从一个窗口获得设备环境。下面是其中一些方法的列表:1. 调用函数 CWnd:GetDC 。这个函数将返回一个CDC类指针,这个指针可用于在窗口中实现对图形的操作(输出)。2. 声明 CClientDC类型变量,并且传递一个CWnd类型指针给它的构造函数。类CClientDC是被设计用来实现窗口中客户区域的图形操作。3. 声明CWndowDC类型变量,并且传递一个CWnd类型指针给它的构造函数。类CWndowDC被设计用来实现整个窗口区域的图形操作(包括客户区域和非客户区域)。4. 在MFC中,某些成员函数是设计用来更新应用程序的界面(例如:Cview:OnDraw)。当一个窗口需要更新的时候,这些函数会被自动调用。对于这类函数,设备环境会通过函数的参数来传递。利用GDI对象使用设备环境在调用任何函数实现图形绘制之前,我们必须确保相应的GDI对象被设备环境所选择。举个例子来说,如果我们想要画一条宽度为2,颜色为红色的直线。我们必须选定一个红色实线的画笔并且它的宽度为2.下面怎样利用GDI对象使用设备环境的步骤:1. 获取或生成一个设备环境,它用来实施在目标窗口上绘图的操作。2. 获取或生成一个相应的图形设备接口GDI(画笔,画刷,字体等等)对象。3. 将图形设备接口(GDI)对象选入当前设备环境,(选择成功的话)将返回一个以前图形设备接口(GDI)对象的指针。4. 执行绘图操作。5. 绘图完成后,应当恢复以前设备环境的图形设备接口GDI对象。接下来我们来讨论怎样用一个特定的GDI对象来绘制一个图形如:长方形。绘制长方形在我们懂得前面的知道后是很容易实现长方形绘制的。为了画一个长方形,我们需要调用函数CDC:Rentangle()并且传递一个CRect类型的值给它。长方形的边可以通过设备环境所选的画笔来绘制,填允可以当前选择的画刷来实现。我们可以用类Cbrush来声明一个画刷类型,并且可以下面的函数产生各种类型的画刷,这些函数有:CBrush:CreateSolidBrush(), CBrush:CreateHatchBrush(),CBrush:CreatePatternBrush(),在windows程序中,有各种事先实现好了的(缺省的 )GDI对象可以任何时候利用,这些对象包括画笔,画刷,字体,等。可以通过调用:GetStockObject() API函数来得到这些对象,它返回一个相应类型的GDI的句柄。用它来绘制相应的图形。在一个长方形还没有最终完成时,也许我们仅仅想要有边缘内部没有填充,可以选择一个中空画刷(NULL画刷)来实现它。NULL画刷可以通过调用:GetStockObject() 使用HOLLOW_BTRUSH 或NULL_BURSH 标记。在一系列工作完成之后,就用程序可以让用户绘制出长方形。同样的道理,只要作小小的修改我们就可是绘制出一个椭圆,为了绘制椭圆,我们需要调用函数CDC:Ellipse() 并且传递一个CRect类型的值给它。和前面的调用函数

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论