From the beginning of this article, I will not blow the cowhide, then blow the rabbit skin. Talk about the stuff that is related to drawing.
To draw, you first have to get a DC, what is a DC? The literal translation is called the device context, or it can be translated into the device description table, which mainly refers to the API for us to encapsulate some of the display equipment related to the interactive operation, we are talking about the drawing of graphics, naturally refers to the graphics card. Of course, for the same objective things, the world does not exist the only understanding of the program, the technical things ultimately to use, should not have rigid to unify. The biggest failure of many of us is that he has no doubt that he will understand it in such a way that, as the authorities say, he will not go through his brain thinking and follow that.
Although my alma mater is an obscure three-stream university, but memories of my university, very fortunate, I have met a few good teachers, real good teachers, not those so-called animal brick home. Remember a teacher said: This book, if you have finished reading, then you are too defeated, if you have mastered the contents of the book, barely Pass, if you can put all the ideas in the book, you are excellent.
In many cases, our drawings are followed by the first GetDC-----drawing------〉RELEASEDC,DC is a resource, used up to release, we go to the library to borrow books, read the book. However, when the WM_PAINT message is processed, the BeginPaint function is invoked and the drawing is started, and the call to EndPaint is finished. Of course, this does not violate what we said before the use of HDC to release the truth, just beginpaint function will automatically call GETDC, EndPaint will automatically call ReleaseDC.
OK, first let's write a few words. Drawing text can use the DrawText function, and his last argument is the alignment of the text, such as left-aligned, centered, right-aligned, and so on.
Paintstruct PS;
Switch (msg)
{case
wm_paint:
BeginPaint (hwnd, &PS);
Declare a variable of a PAINTSTRUCT structure and pass it to the BeginPaint function, and then you can draw something.
DrawText (ps.hdc,l "The bright Moonlight before the bed",-1, &rect, dt_center);
However, if I want the color of the text to be not the default black, we can consider calling the SetTextColor function to set the color, after which all of the text we draw is the color, and if you want to change the color of the text, call the SetTextColor function again.
SetTextColor (PS.HDC, RGB (0,150,255));
RGB macro can be three values to determine the color value, this estimate does not need me to introduce, if you do not understand RGB, you can go to ask sister Furong.
I want the newly drawn text to be in the next line of the previous text, and, of course, you might say, use the DrawText to change the coordinates of the rect that are passed to it. Although this method can, but we do not adjust the coordinates. In fact, if we know the height of the text character, it is good to do, right, to get the text height, you can call the GetTextMetrics function. Now all the tools we have to use are complete.
Case Wm_paint:beginpaint (hwnd, &PS);
Textmetric TM;
Obtain the data related to the text gettextmetrics (PS.HDC, &TM);
RECT RECT;
Rect.top = 0L;
Rect.left = Ps.rcPaint.left;
Rect.right = Ps.rcPaint.right;
Rect.bottom = Rect.top + tm.tmheight;
The first line of text SetTextColor (PS.HDC, RGB (0,150,255));
DrawText (ps.hdc,l "The bright Moonlight before the bed",-1, &rect, dt_center);
The second line of text rect.top + = Tm.tmheight;
Rect.bottom + = Tm.tmheight;
SetTextColor (PS.HDC, RGB (220, 12, 50));
DrawText (PS.HDC, L "suspected to be on the ground frost",-1, &rect, dt_left);
The third line of text rect.top + = Tm.tmheight;
Rect.bottom + = Tm.tmheight;
SetTextColor (PS.HDC, RGB (30,255,7));
DrawText (PS.HDC, L "looked up to the moon",-1, &rect, dt_right);
The four lines of text rect.top + = Tm.tmheight;
Rect.bottom + = Tm.tmheight;
SetTextColor (PS.HDC, RGB (0,40,210)); DrawText (PS.HDC, L "bow and think.Township ",-1, &rect, dt_right);
EndPaint (hwnd, &PS); return 0;