Using VC + + to develop ASP image processing components (1)

Source: Internet
Author: User

VC + + in the DC environment and the various objects related to the GUI

There are various graphical user interface GUI (Graphics user Interface) objects in Windows that we need to use when drawing. While various objects have various properties, here are a few GUI objects and the properties that are owned.

(i), GUI related to various objects

There are various graphical user interface GUI (Graphics user Interface) objects in Windows that we need to use when drawing. While various objects have various properties, here are a few GUI objects and the properties that are owned.

Font Object CFont

Font objects CFont fonts used in different styles and sizes when outputting text. Alternative styles include whether italic, bold, font name, underline, and so on.

Brush CBrush Object

The brush CBrush The object determines the color or template to use when populating the area. For a fixed-color brush, its properties are color, whether the grid and grid types such as horizontal, vertical, crossover and so on. You can also use a 8*8 bitmap to create a custom template brush that, when used with this brush, fills the area with a bitmap.

Brush CPen

Brush CPen objects are useful when drawing points and drawing lines. Its properties include color, width, line style, such as dotted lines, solid lines, dot dashes and so on.

Bitmap CBitmap Objects

Bitmap CBitmap objects can contain an image that can be saved in a resource.

CPalette Palette

The CPalette palette is a color mapping interface that allows applications to take full advantage of the color-depiction capabilities of output devices without affecting other applications.

In addition, the system also has some inventory GUI objects, you can use Cdc::selectstockobject (selectstockobject (int nindex) to select these objects, they include some fixed color brushes, brushes and some basic fonts. Such as:

Black_brush Black Brush

Null_brush Empty Brush

White_pen White Brush

Device_default_font default Font

You must follow certain rules for using GUI objects in Windows. First you need to create a legitimate object, different object creation methods. You then need to select the GUI object into the DC and save the original GUI object in the DC. If you select an illegal object, it will cause an exception. It is particularly important that you restore the original object after you use it, if you save a temporary object in a DC and you may cause an exception if the temporary object is destroyed. It is important to note that each object must be destroyed before it is recreated, and the following code demonstrates this safe way of using:

OnDraw (CDC* pDC)
{
  a) CPen pen1,pen2;
  b) pen1.CreatePen (PS_SOLID,2,RGB(128,128,128));//创建画笔对象一
  c) pen2.CreatePen (PS_SOLID,2,RGB(128,128,0));//创建画笔对象二
  d) CPen* pOldPen=(CPen*) pDC->SelectObject(&pen1);//选择对象进DC
  e) drawWithPen1...
  f)  (CPen*)pDC->SelectObject(&pen2);//选择对象进DC
  g) drawWithPen2...
  h)  pen1.DeleteObject();//再次创建前先销毁
  i) pen1.CreatePen(PS_SOLID,2,RGB(0,0,0));//再次创建对象
  j) (CPen*)pDC- >SelectObject(&pen1);//选择对象进DC
  k) drawWithPen1...
   l)  pDC->SelectObject(pOldPen);//恢复
}   

The OnDraw (cdc* PDC) function is the most common graphics output refresh function in VC, and the parameter PDC is a pointer to the CDC class, which we use for drawing operations.

The code a line defines the two brush object pen1,pen2 of the CPen class, and the CPen class member function CreatePen is created in row b,c to create two solid brushes with the RGB (128,128,128) RGB values, RGB (128,128,0), respectively. Row D Select the newly created brush pen1 into the current device context DC environment and save the old brush in Poldpen so that the graphics or text lines that are output on line E will be populated with PEN1 attributes. F, the G line is selected into the brush two and output. I,j line destroys the brush one and creates an RGB (0,0,0)-colored brush with a K-line output. Last line L ROW The old brush is selected into the current DC environment, and the output is complete. Font objects, brush objects and bitmap objects used in the same way as above, the specific use will be described in the following example.

A DC object is required for the drawing, and the DC (Device context device Environment) object is an abstract mapping environment, possibly a corresponding screen, or a corresponding printer or other. This environment is device-independent, so it is only necessary to use a different device environment when outputting different devices, and the drawing mode can be completely unchanged.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.