Learning to use visual c ++ 6.0 in a step-by-step manner

Source: Internet
Author: User
Step-by-Step Learning Visual c ++ 6.0 Reading Notes (7) )

LQuestion:Draw a dialog boxMydlg,OneList box(Idc_lb),

A static text (Idc_stext),List boxCreate an empty member variable

M_ctllistboxAnd string member variablesM_strlistbox.

Today we want to learn about font control, but we must understand some essential knowledge.

LLogfontStructure

 

 

 

 

 

 

 

 

 

 

 

 

 

 

There are too many member variables in this structure.OkeyYes. Check if necessary.Msdn.

Typedef struct taglogfont {

LongLfheight;//Height

LongLfwidth;//Width

LongLfescapement;//Print angle,900Vertical print,0Horizontal printing.

LongLforientation;//Font printing angle,1800Invert,900Invert the left and right.

LongLfweight;//Font width. Default Value:0, Also commonly used400,700

ByteLfitalic;//Italics, default0Non-italic,1Italic.

ByteLfunderline;//Underline, default0None.

ByteLfstrikeout;//The font is crossed by a straight line. The default value is0None.

ByteLfcharset;//Character Set, such as simplified Chinese characters. Generally setDefaul_charset.

ByteLfoutprecision;//Conformity. Can't you see it? Generally setOut_defaul _

PRECIS.

ByteLfclipprecision;//Do not understand, generally setClip_deafaul_precis

ByteLfquality;//Font and Image Quality,No matter, setDefaul_quality

ByteLfpitchandfamily;//Word spacing, no matter, setDefaul_pitch + ff_don

Tcare

TcharLffacename[Lf_facesize]; //All font style arrays,

Used to call the font callback function.

} Logfont;

For example:

Logfont lf ;//DeclareLogfontStructure Variable

Lf. lfcharset = defual_charset ;//Set to simplified Chinese characters

Lf. lfpitchandfamily = 0 ;//Here0YesDefaul_quality

Lf. lffacename [] = NULL; //Character style set of dynamic array, initialization cleared

//////////////////////////////////////// //////////////////////////////////////// //////////////////

LEnumfontfamfamiliesex ()Request the available font list function.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

SeeExAt the end, we know that this isAPIFunction, look at the original function:

E ..... Ex ("Device scenario",LogfontStructure pointer , Font callback function address,

Lparam, 0)

//The canvas is one of the device scenarios,

Create a canvas, for example:Cclientdc DC (this)

//The callback function was mentioned last time, but will be discussed later.

//LparamIt is used by the callback function.

//The last one is always0It is said to be used for future extension.

For example:

Cclientdc DC (Thist );

LogfontLf;

.....// Lf.

::Enumfontfamfamiliesex (HDC) DC ,//Forced conversionHDCType

& Lf, (fontenumproc) enumfontfamproc //Forced conversion to font callback function

(Lparam)This, 0 )//Convert the current form pointerLparamReceive callback function usage.

//////////////////////////////////////// //////////////////////////////////////// ////////////////////

LHow to Create a font callback function?

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Let's look at a typical font callback function example:

Int callback enumfontfamproc (lpenumlogfont lpelf,

Lpnewtextmetric lpntm, DWORD nfonttype,

Long lparam)

{

Mydlg * pwnd = (mydlg *) lparam;

Pwnd-> m_ctllistbox.addstring (lpelf-> elflogfont. lffacename)

Return ture;

}

//////////////////////////////////////// //////////////////////////////////////// ////////////////////

This callback function is created by us.3Parameters seem to be very deep, in factLogfontStructure

The first parameter isEnumlogfontStructure pointer, which is used to set

The font is underlined in width. The second parameter isNewtextmetricStructure pointer.

The third parameter is used to set the font display style.,For example

Turetype,The last parameter is required by the callback function. It seems that there are some hidden operations in the call,

We don't need to worry about it.

The first statement is a dialog box.MydlgSet pointer, which is equalLparam.

The second statement isMydlgUnderList boxEmpty parts add project, project name is equal to that of the Structure

Style name.

The third statement is required by the callback function.

LCfontClass

 

 

 

 

 

 

 

 

 

 

 

 

 

 

CfontClass can be viewedLogfontStructure extension, their member variables are the same, but the class

There are member functions, such:CreatfontMethod andSetfontMethod

Example:

Cfont m_ffont ;//Create a single-byte instance;

M_ffont.creatfont (12, 0, 0 ,..... LogfontThe parameters are the same. For details, see the preceding section.....);

LInMydlg. hHeader file, add the callback function declaration.

 

 

 

 

 

 

Int callback enumfontproc (lpenumlogfont lpnlf,

Lpnewtextmetric lpntm, DWORD nfonttype, long lparam );

LInMydlg. cppFile, write your own font callback function.

You can copy the example here.

LIsMydlgClass to create member functionsFillfont ();

Because this function is not created for messages, it is created and used by ourselves.

To integrate a series of operation functions.

InViewPanel, PointMydlgClass, add at the right, and enter a name to create it.

CodeList:

Void mydlg: fillfont ();

{

Logfont lf;

Lf. setchar = defualt_charset;

Strcpy (LF. lffacename, "");

M_ctllistbox.resetcontext ();

Cclientdc DC (this );

: Enumfontfamilesex (HDC) DC, & lf,

(Fontenumproc) enumfontproc, (lparam) This, 0 );

}

// Strcpy (Target, Source)Is a string replication function.

Initialize here. Note thatLf. lffacenameIs a string array.

// List boxThere is a methodResetcontext ()Is to clear the drop-down list.

//The following sentence describes the request font list.

LSetFillfont ()JoinMydlg.

 

 

 

 

 

 

Void mydlg: initdialog ()

{

.....

Fillfont ();

....

}

LEdit boxOfEn_changeMessages andList boxOfLbn_selchangeMessage.

 

 

 

 

 

 

WhenEdit boxIf the content is changed by the userEn_changeMessage.

WhenList boxIf you select a project from the drop-down listLbn_selchangMessage.

Both messages are easy to understand, and the book selects fonts for these two messages.

Example. I will not go into detail here

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.