计算机专业外文资料翻译.doc

上传人:仙人指路1688 文档编号:2326098 上传时间:2023-02-11 格式:DOC 页数:9 大小:73.50KB
返回 下载 相关 举报
计算机专业外文资料翻译.doc_第1页
第1页 / 共9页
计算机专业外文资料翻译.doc_第2页
第2页 / 共9页
计算机专业外文资料翻译.doc_第3页
第3页 / 共9页
计算机专业外文资料翻译.doc_第4页
第4页 / 共9页
计算机专业外文资料翻译.doc_第5页
第5页 / 共9页
点击查看更多>>
资源描述

《计算机专业外文资料翻译.doc》由会员分享,可在线阅读,更多相关《计算机专业外文资料翻译.doc(9页珍藏版)》请在三一办公上搜索。

1、毕业设计(论文)外文资料翻译(用外文写)外文出处: Advanced MFC Programming 附 件: A.外文翻译 -原文部分 B.外文翻译 -译文部分 指导教师评语: 签名: 年 月 日附录A.外文翻译 -原文部分(写明出处)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 Interf

2、ace) 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 c

3、ompatible 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

4、 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

5、 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 obje

6、ct 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 informa

7、tion 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 tab

8、le 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 inst

9、ead 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

10、 for the convenience of programmers. The following is a list of some commonly used GDI objects:GDI objectsUsagePenUsed to draw line, curve, the border of a rectangle, ellipse, polygon, etc.BrushUsed to fill the interior of a rectangle, ellipse, polygon with a specified patternFontUsed to manage a va

11、riety of fonts that can be used to output textPaletteUsed to manage colors on a palette deviceBitmapUsed 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.

12、 Besides the handles, every GDI object has a corresponding MFC class. The following is a list of their handle types and classes:ObjectHandle TypeMFC ClassDevice ContextHDCCDC, CClientDC, CWindowDC, etc.PenHPENCPenBrushHBRUSHCBrushFontHFONTCFontPaletteHPALETTECPaletteBitmapHBITMAPCBitmapObtaining DCA

13、s 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

14、(). 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 CWndow

15、DC 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 fu

16、nctions 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

17、 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

18、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

19、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 recta

20、ngle, 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 k

21、ind 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. W

22、e 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 t

23、his, 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 c

24、an 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 b

25、e 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 p

26、arty. 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

27、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 an

28、d 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

29、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

30、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;LO

31、NG 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; lf

32、Weight,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 di

33、splay 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.Summary:1 Before drawing anything to a window, we must first obtain its device

34、context. There are many ways of obtaining a windows DC (Calling function CWnd:GetDC(), declaring CClientDC or CWindowDC type variables, etc.).2 A client DC can be used to paint a windows client area, and a window DC can be used to paint thewhole window (client and non-client area).3 Pen can be used

35、to draw line, the border of rectangle, polygon, ellipse, etc. A pen can have different styles: solid pen, dashed pen, etc.4 Brush can be used to fill the interior of rectangle, polygon, ellipse, etc. A brush can have differentpatterns: solid, hatched, etc.5 We can use an 88 image to create pattern b

36、rush.6On a palette device, there are two color approaching methods: dithering and using the nearest color.7The abilities of a device can be retrieved by calling function CDC:GetDeviceCaps().附录B. 外文翻译 -译文部分节选自Advanced MFC Programming第八章DC, Pen, Brush and Palette8.0节:设备环境DC 及 图形设备接口(GDI)对象从这一章开始,我们将要学

37、习图形设备接口GDI编程。概述图形设备接口(GDI)是在程序员和物理设备之间的一个标准的接口。它提供了许多函数,调用这些函数可以将图形绘制在硬件(如显示器或打印机)上。可见图形设备接口GDI 非常重要,因为作为一个程序员,我们也许需要应用程序能适用于尽可能多的外围设备。举例来说,几乎每个应用软件都需要在显示器显示数气,而且同样多数应用软件也需要支持打印机输出。现在问题出现在这里:由于一个应用程序应该能支持不同的设备,而让程序员知晓每一个外围设备的细节并且事先写代码支持它,这几乎是一件不可能的事。解决方案是在设备和程序员之间引入图形设备接口GDI,它是一个标准的接口,有了它程序员可以不需要有任何

38、的硬件设备知识就能实现对硬件的操作(输出)。只要硬件设备支持标准的图形设备接口GDI,应用程序就能正确的执行。设备环境(DC)作为一个程序员,我们不需要直接输出(应用程序的输出)到硬件设备诸如:显示器或打印机。而是输出到一个虚拟逻辑设备,由它来实现我们对物理设备输出的意图。这个虚拟逻辑设备就是设备环境DC,它是一个Windows数据结构,该结构包含向有关设备输出所需的信息。当我们调用一个标准的GDI 函数时,设备环境依照物理设备的属性和配置来实现对其的操作。 假如我们想要输出一个像素到显示的一个特定的坐标,如果我们没有图形设备接口GDI,为了实现这个简单的操作,我们需要下面的显示器信息。1.

39、视频设备存储配置信息。我们需要这些信息把逻辑坐标转化为物理缓存地址。2. 设备类型。如果是一个调色板设备,我们需要把一个 RGB 组合索引到一个颜色表,用颜色表来表示一个特定的颜色。而对于非调色板设备,我们能直接用RGB组合表示某种颜色。由于现实世界中的设备有多种多样,获得足够的信息以支持所有的设备对我们来说是不可能的。而由GDI函数取代由程序员处理物理设备输出,它让我们直接使用逻辑坐标和RGB组合,从而转换工作交给设备驱动来完成。图形设备接口(GDI)对象在Windows中,图形设备接口(GDI)对象是和设备环境一起实现绘图的工具。有了这些工具极大的方便了程序员。下面是一些常用的图形设备接口

40、(GDI)对象列表:GDI对象用法:画笔用于画线,曲线,长方形,椭圆,多角形等的边缘。画刷用于填充长方形,椭圆,或特殊的多边形的内部。字体用于处理多种字型以方便文本输出。调色板用于在调色板设置上设置颜色位图用于处理图像生成,绘制,操作等等。以上的图形设备接口(GDI)对象与设备环境一起,都是通过句柄来处理(实现)。我们可以使用对象的句柄去定义和访问对象。除句柄外,每个GDI对象还有一个相应的MFC类,以下是句柄类型及相应的MFC类列表:GDI对象句柄类MFC 类设备环境HDCCDC, CClientDC, CWindowDC, etc.画刷HPENCPen画刷HBRUSHCBrush字体HFO

41、NTCFont调色板HPALETTECPalette位图HBITMAPCBitmap获取设备环境作为一个程序员,我们大多数时间的工作是要输出(数据)到一个特定的窗口,而不是整个显示器的银屏。因些就必须能系统中的任何窗口都可以获得设备环境,并且能用于调GDI函数。有许多方法可以从一个窗口获得设备环境。下面是其中一些方法的列表:1. 调用函数 CWnd:GetDC 。这个函数将返回一个CDC类指针,这个指针可用于在窗口中实现对图形的操作(输出)。2. 声明 CClientDC类型变量,并且传递一个CWnd类型指针给它的构造函数。类CClientDC是被设计用来实现窗口中客户区域的图形操作。3. 声

42、明CWndowDC类型变量,并且传递一个CWnd类型指针给它的构造函数。类CWndowDC被设计用来实现整个窗口区域的图形操作(包括客户区域和非客户区域)。4. 在MFC中,某些成员函数是设计用来更新应用程序的界面(例如:Cview:OnDraw)。当一个窗口需要更新的时候,这些函数会被自动调用。对于这类函数,设备环境会通过函数的参数来传递。利用GDI对象使用设备环境在调用任何函数实现图形绘制之前,我们必须确保相应的GDI对象被设备环境所选择。举个例子来说,如果我们想要画一条宽度为2,颜色为红色的直线。我们必须选定一个红色实线的画笔并且它的宽度为2.下面怎样利用GDI对象使用设备环境的步骤:1

43、. 获取或生成一个设备环境,它用来实施在目标窗口上绘图的操作。2. 获取或生成一个相应的图形设备接口GDI(画笔,画刷,字体等等)对象。3. 将图形设备接口(GDI)对象选入当前设备环境,(选择成功的话)将返回一个以前图形设备接口(GDI)对象的指针。4. 执行绘图操作。5. 绘图完成后,应当恢复以前设备环境的图形设备接口GDI对象。接下来我们来讨论怎样用一个特定的GDI对象来绘制一个图形如:长方形。绘制长方形在我们懂得前面的知道后是很容易实现长方形绘制的。为了画一个长方形,我们需要调用函数CDC:Rentangle()并且传递一个CRect类型的值给它。长方形的边可以通过设备环境所选的画笔来

44、绘制,填允可以当前选择的画刷来实现。我们可以用类Cbrush来声明一个画刷类型,并且可以下面的函数产生各种类型的画刷,这些函数有:CBrush:CreateSolidBrush(), CBrush:CreateHatchBrush(),CBrush:CreatePatternBrush(),在windows程序中,有各种事先实现好了的(缺省的 )GDI对象可以任何时候利用,这些对象包括画笔,画刷,字体,等。可以通过调用:GetStockObject() API函数来得到这些对象,它返回一个相应类型的GDI的句柄。用它来绘制相应的图形。在一个长方形还没有最终完成时,也许我们仅仅想要有边缘内部没有

45、填充,可以选择一个中空画刷(NULL画刷)来实现它。NULL画刷可以通过调用:GetStockObject() 使用HOLLOW_BTRUSH 或NULL_BURSH 标记。在一系列工作完成之后,就用程序可以让用户绘制出长方形。同样的道理,只要作小小的修改我们就可是绘制出一个椭圆,为了绘制椭圆,我们需要调用函数CDC:Ellipse() 并且传递一个CRect类型的值给它。和前面的调用函数CDC:Rentangle()完全相同,如果我们改变所有的“Rectangle”关键字变为“Ellipse”,应用程序就可以代替绘制长方形而实现绘制椭圆。字体字体是另一项非常重要的GDI对象,每一个应用程序涉

46、及的字体。通常系统包含一些默认的字体,可用于所有应用程序。除了这些默认的字体,我们也可以安装的字体所提供的30种类。对于文书处理的软件,使用的字体是一个复杂的问题。有很多事情我们需要照顾。举例来说,当创建这种类型的程序时,我们需要思考下列问题:如何显示不同风格的字体;如何改变文本对齐;如何添加特殊效果字符。当我们应用一个字体对话框,所有可用的字体都会在上面列出。我们可以选择字体大小,字体名称,特殊的风格,和文字颜色。 像其他的GDI对象一样,例如笔和刷子,我们需要创造字体的具体样式并且把它选入设备环境,以便用它来输出文本。在MFC中,用CFont来创建一个字体,我们可以调用CFont:crea

47、tefont()或cfont:createfontindirect()其格式列出如下: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 );第一个函数有许多参数和第二个函数只需要一logfont类型的指针。两个成员函数的运行结果是完全一样的,在第一个函数中一种字体需要我们指定每个风格,它对应结构一个LOGFONT结构体:typedef struct tagLOGFONTLONG lfHeight;LONG lfWidth;LONG lfEscapement

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 建筑/施工/环境 > 项目建议


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号