How to rotate and output text in BCB

zhaozj2021-02-11  206

How to rotate and output text in BCB

There are a lot of articles to show how to output a rotating text in the VC, but which article rarely sees which article introduces a similar effect in BCB. . So many people think that there is no similar effect in BCB, of course, these people have reason to say how BCB has a difference between the mouth!

This is certainly a big relationship with the design of the BCB itself.

The VCL graphics assembly encapsulates the Windows Graphics Device Interface (GUI), making it easy to add graphics in the Windows programming. BCB is designed to be excellent! Its intent is to design the VCL graphics components into three levels:

The highest layer: draw lines and graphics, such as: Moveto, Lineto, Rectangle, And Ellipse output and control text, such as TextOut, TextHeight, TextWidth, And TextRect fill shape, such as FillRect and floodfill

Middle-layer: customized text and graphics, by controlling the following properties: Pen, Brush, And Font, Pixels replication, and consolidation graphics, such as: Draw, StretchDraw, Brushcopy, and CopyRect methods; CopyMode properties

Bottom: Directly calls Windows GDI functions, VCL graphics components provide a Handle property, through it, you can control everything!

Most of the BCB users will only use some of the high-level and middle-level methods and attributes, they don't know what Handle property! For these users, as well as those who have objection to BCB, I provide the following example to illustrate the power of BCB and ease of use.

Very simple, a few code:

Void __fastcall tform1 :: formpaint (TOBJECT * Sender) {logfont lf;

GetObject (canvas-> font-> handle, sizeof (logfont), & lf;

Lf.LFEScapement = 450; // set to 450 to make 45 deterree Angle lf.lirtation = 450; lf.lfoutPrecision = OUT_TT_ONLY_PRECIS;

Canvas-> font-> Handle = CreateFontIndirect (& lf); canvas-> brush-> style = bsclear; canvas-> pen-> color = CLRED; canvas-> textout (20, 120, "wow !! Angled Text!" }

how about it? Is it very simple. . . I remember that more than ten parameters are defined in the VC order! Let's simply analyze this example:

The first sentence: logfont lf; logfont variable can completely control the properties of the font, is defined in Wingdi.h as: typedef logfonta logfont; and logfonta is defined as:

typedef struct tagLOGFONTA {LONG lfHeight; LONG lfWidth; LONG lfEscapement; LONG lfOrientation; LONG lfWeight; BYTE lfItalic; BYTE lfUnderline; BYTE lfStrikeOut; BYTE lfCharSet; BYTE lfOutPrecision; BYTE lfClipPrecision; BYTE lfQuality; BYTE lfPitchAndFamily; CHAR lfFaceName [LF_FACESIZE];} Logfonta; second sentence:

GetObject (canvas-> font-> handle, // look! Use the handle attribute! This sentence is used to get the handle sizeof (logfont) of the canvas font, // This sentence gains LogFont Size & LF);

The following sentences control font by adjusting the properties of logfont

LF.LFESCAPEMENT = 450; // set to 450 to make 45 deterree anglerf.lirtation = 450; lf.lfoutPrecision = out_tt_only_precis;

Below, a new font is created, and it is used to set the font of Canvas-> Font.

Canvas-> font-> Handle = CreateFontIndirect (& lf); canvas-> brush-> style = bsclear; canvas-> pen-> color = CLRED; canvas-> textout (20, 120, "wow !! Angled Text!" );

It's that simple. . . In the underlying control, other graphics are similar to this method, everyone does not try :)

转载请注明原文地址:https://www.9cbs.com/read-3850.html

New Post(0)