First of all, four API functions, respectively, are deltetobject,createfontindirect,selectobject,textout. The descriptions of these functions are described separately.
Deltetobject
function function: This function deletes a logical pen, brush, font, bitmap, region, or palette, releasing all system resources associated with the object, and the specified handle is invalidated after the object is deleted.
Function prototype: BOOL DeleteObject (Hgdiobj hobject);
Parameters:
Hobject: A handle to a logical pen, brush, font, bitmap, region, or palette.
Return value: Successful, returns a value other than 0, or zero if the specified handle is invalid or if it has been selected into the device context.
CreateFontIndirect
function function: This function creates a logical font that defines its attributes in the specified structure. This font can be selected as a font in any device environment in later applications.
Function prototype: Hfont createfontindirect (CONST LOGFONT *LPLF);
Parameters:
LPLF: A pointer to the LOGFONT structure that defines this logical font attribute.
Return value: If the function call succeeds, the return value is a handle to the logical font, and if the function call fails, the return value is null
SelectObject
function function: This function selects an object into the specified device context and replaces the previous object of the same type. Function prototypes: Hgdiobj SelectObject (hdc hdc, hgdiobj hgdiobj) parameter: HDC: A handle to the device context environment. Hgdiobj: The handle of the selected object, which must be created by the following function. Bitmaps: CreateBitmap, Createbitmapindirect, createcompatible Bitmap, CreateDIBitmap, CreateDIBSection (only the memory device context can select bitmaps, And at the same time only one device context selection bitmap). Painting brushes: CreateBrushIndirect, CreateDIBPatternBrush, Createdibpatternbrushpt, Createhatchbrush, CreatePatternBrush, CreateSolidBrush. Font: CreateFont, CreateFontIndirect. Pen: CreatePen, Createpenindirect. Area: Combinergn, CreateEllipticRgn, CreateEllipticRgnIndirect, CreatePolygonRgn, Createrectrgn,createrectrgnindirect. Return value: If the Selection object is not a zone and the function executes successfully, the return value is the handle to the superseded object, and if the Selection object is a region and the function succeeds, the following value is returned: Simpleregion: The area consists of a single rectangle; Complexregion: The region consists of multiple rectangles ; Nullregion: The area is empty. If an error occurs and the Selection object is not an area, the return value is NULL, otherwise hgdi_error is returned.TextOutThe function writes a string to the specified position with the currently selected font, background color, and body colorfunction PrototypesBOOL TextOut (HDC hdc,//Device description table handle int Nxstart,//string start position x coordinate int Nystart,//string start position y coordinate lpctstr lpstring,//String int Cbstri Number of characters in ng//String);Parameters hdc[input] The handle of the device environment nxstart[input] Specifies the logical x-coordinate of the datum point used for string alignment. nystart[Input] Specifies the logical y-coordinate of the datum point used for string alignment. lpstring[input] points to the pointer that will be drawn to the string. This string does not have to end with a, because the length of the string is specified in Cbstring. cbstring[Input] Specifies the length of the stringreturn valueIf the function call succeeds, the return value is a value other than 0. If the function call fails, the return value is 0. We need 5 tags, 5 edit boxes, 3 selection boxes, 2 buttons and 4 UpDown controls, directly on the source code
Option explicitprivate Declare function DeleteObject Lib "GDI32" (ByVal Hobject as Long) as Longprivate Declare function C Reatefontindirect Lib "gdi32" Alias "Createfontindirecta" (lpLogFont as LOGFONT) as Longprivate Declare Function selectobj ECT Lib "GDI32" (ByVal hdc as Long, ByVal hobject as Long) as Longprivate Declare Function TextOut Lib "gdi32" Alias "Text OutA "(ByVal hdc as Long, ByVal x as Long, ByVal y as Long, ByVal lpstring as String, ByVal ncount as Long) as Longprivate Type RECT left as long Top as long right as long Button as Longend typeprivate Type LOGFONT lfheight as Lo Ng Lfwidth as Long lfescapement as long lforientation as long lfweight as Long lfitalic as Byte Lfunderl INE as Byte lfstrikeout as Byte lfCharSet as Byte lfoutprecision as Byte lfclipprecision as Byte lfquality As Byte lfpitchandfamily as byte lffacename as String * 50End typeprivate RF as Logfontprivate NewFont as Longprivat E Oldfont as Longfunction fontoption () rf.lfwidth = Int (val (Me.txtWidth.Text)) rf.lfheight = Int (val (Me.txtHeight.Text)) rf.lfescapement = Int (val (Me.txtEscapement.Text)) rf.lfweight = Int (val (Me.txtWeight.Text)) Rf.lfitalic = Me.chkItalic.Value RF.L Funderline = Me.chkUnderline.Value rf.lfstrikeout = Me.chkStrikeOut.ValueEnd functionprivate Sub command1_click () Di M Throw as Long Dim x, y as Long fontoption ' Set font parameter NewFont = createfontindirect (RF) ' Create new font oldfont = Sele Ctobject (ME.PICTURE1.HDC, NewFont) ' Apply new font x = picture1.scalewidth/2 y = Picture1.scaleheight/2 ' Displays the position of the text Thr ow = TextOut (ME.PICTURE1.HDC, x, Y, Me.txtShow.Text, Len (Me.txtShow.Text)) ' Display text NewFont = SelectObject (Me.Picture1.hd C, Oldfont) ' Select old Font Throw = DeleteObject (NewFont) ' Delete font End subprivate Sub command2_click () Me.Picture1.ClsEnd SubPrivate Sub form_load () rf.lfheight = 50 ' Set font height rf.lfwidth = 10 ' Set Font average width rf.lfescapement = 0 ' Set text tilt Rf.lfweight = 400 ' SetPlace font Weight rf.lfitalic = 0 ' Set font not italic rf.lfunderline = 0 ' font not underlined rf.lfstrikeout = 0 ' font not strikethrough Rf.lfoutprecisio n = 0 ' Set output progress rf.lfclipprecision = 0 ' Set clip precision rf.lfquality = 0 ' Set output quality rf.lfpitchandfamily = 0 ' Set font kerning and font Family Rf.lfcharset = 0 ' Set character set rf.lffacename = "Arial" + Chr (0) ' Set font name Me.txtEscapement.Text = Rf.lfescapeme NT Me.txtHeight.Text = rf.lfheight Me.txtWeight.Text = rf.lfweight Me.txtWidth.Text = Rf.lfwidth ' Set text box to display text end Sub
Operating effects such as
VB API The Fourth Lesson font application Chapter Two