GDI graphics, C \ HDC \ CDC

Source: Internet
Author: User

L GDI graphic interface

L Drawing Graphics

L DC, HDC device CDC

L draw a rectangle

1. Learn about GDIAnd Gui

GDIIt is the abbreviation of graphics device interface. It meansGraphical Device InterfaceIts main task is to exchange information between the system and the drawing program, and process the graphics output of all Windows programs.

In Windows, most applications with graphical interfaces are inseparable from GDI. With the many functions provided by GDI, We can conveniently output graphics on screens, printers, and other output devices, text and other operations. With the advent of GDI, programmers can convert the output of applications into outputs on hardware devices without having to care about hardware devices and device drivers, thus realizing the isolation between program developers and hardware devices, this greatly facilitates development.

GDI:Graphical Device InterfaceIt includes all the elements of the drawing, such as paint brush, paint brush, line, point, rectangle, and so on. These are all encapsulated by MFC in the CDC class, which contains all the drawing functions.
Gui:Graphical user interfaceThis is a concept introduced in windows. It means that the user and the computer have an operation interface, and the operations on this interface are visible to the user. Unlike dos, only input commands are executed by the computer.

Differences:

GUI is the man-machine interface of the program. Compared with the character interface of the DOS class, GDI is a programming interface, which generally refers to the graphical device programming interface in windows.

Ii. DC and HDCAnd CDC

The DC device environment (device context) is a data structure in windows, it contains all the Description fields required by GDI for display interface conditions, including connected physical devices and various status information.

HDC is a data type in API and a DC handle.

CDC is an encapsulation class for DC-related data and functions in MFC.

The relationship between HDC and CDC is like the relationship between hwnd and cwnd;

 

3. Draw a rectangle

1, // APIDraw

BoolRectangle(

HDC, // device description table handle (specify a place for drawing)

Int nleftrect, // X coordinate of the upper left corner of the rectangle

Int ntoprect, // y coordinate of the upper left corner of the rectangle

Int nrightrect, // X coordinate of the bottom right corner of the rectangle

Int nbottomrect // y coordinate of the lower left corner of the rectangle

);

HDC acquisition

HDC getdc (
Hwnd
Hwnd// Handle to a window
);

HDC getwindowdc (
Hwnd
Hwnd// Handle of window
);

 

2, CDCClass plotting

CDC: rectangle //Class member functions

BoolRectangle(INT X1, int Y1, int X2, int Y2 );

BoolRectangle(Lpcrect lprect );

 

Obtain from CDC

Cwnd: getdc

CDC * getdc ();

Cwnd: getwindowdc

CDC * getwindowdc ();

 

// Remember to release it after use; otherwise, it will occupy more resources and be prone to errors.

Int releasedc (

Hwnd Hwnd,// Window handle

 HDC HDC// Dc device handle
);

4. In DCUpperTest the code for drawing a rectangle

Void cdialog_thread_priority_test: onbnclickedbutton4 ()

{

// Todo: add the control notification handler code here

HDC Dc =: getdc (m_hwnd); // obtain the DC

// HDC Dc =: getwindowdc (m_hwnd); // contains non-customer areas (title bar and menu bar toolbar)

: Rectangle (DC,); // draw a rectangle.

: Releasedc (m_hwnd, DC); // release the DC

 

// CDC version

// CDC * PDC = getdc (); // cwnd

// PDC-> rectangle );

// Releasedc (PDC );

}

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.