Add font in Properties dialog box

Source: Internet
Author: User

 

 

Mfc provides three property page classes: cfontproppage, ccolorproppage, and cpictureproppage.

However, they can onlyOle automation is used together. This article describes how to add

Font property page.

 

The solution is to create a font property page by yourself. To allow you to customize the General dialog box behavior, the sdk

These dialog box resources are provided. "The choose font dialog box is in the include directory.

In the font. dlg file, the corresponding symbols are in the dlgs. h file. Using these files as the starting point, we

You can create resources for the font property page and add a resourceCpropertypage inheritance class.

The implementation below may be limited, but it also has some reference value. If you want to enhance it, you can view

Cfontproppage source file in the mfc source program directory.

 

Step 1: Add a dialog Resource

You can open the following rc file devstudio in devstudio and copy the dialog box resources

In your primary resource file, or you can include this resource file.

 

To copy the resource file, open the "fontpage. rc" file in devstudio and expand the resource

OfOutline. Open resourceview to make the resources in the dialog box visible. Finally

Drag the idd_fontpage resource in fontpage. rc to the resource of your application resourceview.

 

If you want to include the fontpage resource file, you just need to put "fontpage. rc" and "fontpagerc. h"

File(Listed below) go to the "res" directory in the project directory. Then the existing

"Add the following section to the rc2 file. Resource images are also listed below.

 

# Include "fontpage. rc"

Listing of fontpage. rc

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

// Listing of fontpage. rc

//

# Include "winresrc. h"

# Include "fontpagerc. h"

Idd_fontpage dialog discardable 13, 54,264,133

Style ws_child | ws_caption | ws_sysmenu

Caption "font"

Font 8, "helv"

Begin

Ltext "& font:", stc1, 6, 3, 40, 9

Combobox idc_font, 6,13, 131,54, cbs_simple | cbs_autohscroll |

Cbs_sort | cbs_disablenoscroll | ws_vscroll | ws_tabstop

Ltext "font st & yle:", stc2, 153,3, 44,9

Combobox idc_style, 153,13, 64,54, cbs_simple | cbs_disablenoscroll |

Ws_vscroll | ws_tabstop

Ltext "& size:", stc3, 224,3, 30,9

Combobox idc_fontsize, 224,13, 32,54, cbs_simple |

Cbs_disablenoscroll | ws_vscroll | ws_tabstop

Groupbox "effects", grp1, 6, 72, 84,34, ws_group

Control "stri & keout", idc_strikeout, "button", bs_autocheckbox |

Ws_tabstop

Control "& underline", idc_underline, "button", bs_autocheckbox, 10,

94,51, 10

Groupbox "sample", grp2, 98,72, 160,49, ws_group

Ctext "aabbyyzz", idc_sample, 104,81, 149,37, ss_noprefix

End

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

// Listing of fontpagerc. h

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

# Define idc_strikeout 0x0410

# Define idc_underline 0x0411

# Define grp1 0x0430

# Define grp2 0x0431

# Define stc1 0x0440

# Define stc2 0x0441

# Define stc3 0x0442

# Define idc_sample 0x0444

# Define idc_font 0x0470

# Define idc_style 0x0471

# Define idc_fontsize 0x0472

# Define idd_fontpage 1543

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

Step 2: include source files in your project

The header file and implementation file are provided below. You just need to include them in your project, and

UseCfontpage class. The implementation of this class is relatively simple. Cfontpage constructor get 1

PointThe pointer of the logfont structure. It uses the structure information to initialize itself. If the logfont structure does not exist

If yes, the current font of the window is used. InThe oninitdialog () function lists the fonts required.

And font combo box. However, any changes to font features must be called.Onselchange () function.

All information ing entries point to this function.The onselchange () function updates internal information and displays a sample

This text.

 

Related Article

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.