Beginner mfc--Portrait dot draw line Draw Rectangle

Source: Internet
Author: User


Defining a coordinate system


CRect rect;
GetClientRect (&rect);//actually now I do not quite understand this sentence has any specific meaning! @@!!



The coordinate system of the custom Form window and viewport is defined by itself
Pdc->setmapmode (Mm_anisotropic);

Commonly used patterns are also mm_text (each logical coordinate corresponds to a device coordinate positive x right y downward)


Defines the viewport, which is set to x right by the comparison to the window setting, and Y is up pdc->setwindowext (rect. Width (), Rect. Height ());
Pdc->setviewportext (rect. Width (),-rect. Height ());


Sets the viewport origin, where the viewport origin is in the device coordinate system
Pdc->setviewportorg (rect. Width ()/2,rect. Height ()/2);

To create a brush----draw an outer boundary of an area

Brush three elements 1, line 2, Width 3, color
Dash dashed/dashdot dot dotted line/dot dots/solid
The third parameter is a color type, which is essentially a 32-bit colour data type, such as 0X0000FF (red)
You can also use RGB macros to create RGB (255,0,0) also red RGB (ff,0,0)

Create a brush to use
BOOL CreatePen (Ps_dash,1,rgb (255,0,0));

You can also use constructors

CPen (Npenstyle,nwidth,crcolor)


Create a brush-----the inside of a drawing to fill so that only the closed graphic is valid

The default brush is white, so when you draw a rectangle, such as closed graphics, the internal use of the default white brush fill, it will not appear to fill the color
Painting brush is divided into 1, solid brush CreateSolidBrush (),

2, Shadow painting brush createhatchbrush (int nindex,colorref,crcolor)
The following three brushes can be created using CBrush () to create different brushes than the number of parameters.
BOOL CreateSolidBrush (RGB (255,0,0));
BOOL Createhashbrush (hs_cross,0xff0000);
CreatePatternBrush (*PBITMAP) Creating a logical brush bitmap allows you to import a DDB bitmap from a resource

To make sure that the bitmap is in the same position as the brush, use setbrushorg () to set the starting point of the paint brush


GDI objects are selected for GDI objects can be used only after they are created in the context of the selection
cpen* Pdc->selectobject (cpen* CPen)
cbrush* Pdc->selectobject (CBrush *cbrush)
cbitmap* pdc->selectobject (CBitmap * pbitmap)
The three functions above are the brushes, brushes, and bitmaps selected by the context class, and the returned pointer is a pointer to the replaced brush, brush, bitmap


Draw pixel point function 2 kinds of 1, return the PIP's RGB value SetPixel (10,10,rgb (255,0,0));

2, do not return RGB value Setpixelv (10,10,rgb (255,255,0))
COLORREF Color=getpixel (10,10);//returns the RGB value of the point

To draw a segment, first create a brush CPen *poldpen,newpen;

Newpen. Createcpen (Ps_solid,1,rgb (0,ff,0));

Poldpen=pdc->selectobject (&newpen);

2 bool LineTo (x, y), from current position to XY, and change current position to XY
CPoint MoveTo (x, y); just move the current position to XY, not underlined


Draw Rectangle Rectangle

Beginner mfc--Portrait dot draw line Draw Rectangle

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.