VC implementation of Karaoke subtitles overlay

Source: Internet
Author: User
Tags inheritance

A. GDI Programming basics

Subtitle overlay, should belong to the category of graphics, image processing. On the Windows platform, the graphics, image processing methods of course preferred GDI (Graphics Device Interface, Graphics Device interface). What is GDI? GDI is actually a set of API functions, they are rich in functionality, simple and flexible to use. Next, let's start with some basic knowledge of GDI programming.

There are a number of GDI functions that we can roughly divide into the following categories:

· Device contexts (Device context, referred to as DC) functions, such as GETDC, CreateDC, DELETEDC, etc.

· Draw line functions, such as LineTo, polyline, arc, etc.;

· Fill drawing functions, such as ellipse, fillrect, pie, etc.

· Drawing property functions, such as SetBkColor, SetBkMode, SetTextColor, etc.

· text, font functions, such as TextOut, GetTextExtentPoint32, getfontdata, etc.;

· Bitmap functions, such as SetPixel, BITBLT, StretchBlt, etc.;

· Coordinate functions, such as DPTOLP, LPTODP, screentoclient, clienttoscreen, etc.;

· Mapping functions, such as Setmapmode, Setwindowextex, Setviewportextex, etc.;

· Meta-file (MetaFile) functions, such as playmetafile, setwinmetafilebits, etc.

· Regional (Region) functions, such as FILLRGN, Framergn, invertrgn, etc.;

· Paths (path) functions, such as Beginpath, Endpath, Strokeandfillpath, etc.;

· cropping (clipping) functions, such as SELECTCLIPRGN, Selectclippath, and so on.

These functions allow you to complete the drawing of various parts of the user interface, including Windows, menus, toolbars, buttons, and so on, which are commonplace on the Windows platform. In addition to completing the display operation, GDI also provides drawing objects to render the display. These GDI objects include:

Device context (DC)-a data structure that has information about the drawing properties of output devices such as displays or printers;

Brush (pen)--for drawing lines;

Brush (Brush)--used for pattern filling;

Font--used to determine the style of text characters;

Bitmap (Bitmap)--for storing images;

Palette (Palette)--a collection of colors that can be used when drawing on the screen.

DC is a very important concept in GDI. Looking at the usage instructions for each GDI function on MSDN, we find that most GDI functions have a hdc type parameter; HDC is the DC handle. The general procedure for graphics and image processing for Windows applications is as follows:

1. Obtain the DC of the specified window;

2. Determine the use of the coordinate system and mapping method;

3. For graphics, images or word processing;

4. Release the DC used.

To further simplify the use of GDI functions, or to adapt to object-oriented programming styles, Microsoft's MFC Class Library provides several DC encapsulation classes. The inheritance relationships for these classes are as follows:

Figure 1 Inheritance relationships for several MFC classes of DCS

As we know, most MFC classes derive from the CObject class, and the CDC class is no exception. We see that the CDC class is the most basic DC encapsulation class; It almost encapsulates all GDI functions. In addition, each derived class of the CDC class has a specific purpose:

cclientdc--the client area of the window to paint the DC;

cmetafiledc--the DC that is used to manipulate Windows meta files;

cpaintdc--in response to WM_PAINT messages, the graphics used by the DC, more common in the MFC program OnDraw function;

cwindowdc--the DC that is drawing in the entire window range (including frames, toolbars, and so on).

In addition to the class encapsulation of DCs, MFC also has a class encapsulation of other GDI objects. The inheritance relationships for these classes are as follows:

Figure 2 Inheritance relationships for MFC encapsulated classes of GDI objects

The parent class of the Cgdiobject--gdi object defines some public function interfaces of the GDI object encapsulation class;

cbitmap--Bitmap-related operations of the encapsulation class, including bitmap loading or creation, etc.

cbrush--Painting Brush object encapsulation class;

cfont--font properties and related operations of the encapsulation class;

cpalette--palette of encapsulation class;

cpen--the wrapper class of the Brush object;

crgn--the encapsulation class for the area object and the region-related operations.

Through the above introduction, I believe that the reader has a certain understanding of GDI programming. Next, we will discuss the implementation principle of the karaoke overlay.

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.