Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 77727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:52:32+00:00 2026-05-10T20:52:32+00:00

Problem: How can I tell if a selection of text in the CRichEditCtrl has

  • 0

Problem: How can I tell if a selection of text in the CRichEditCtrl has multiple font sizes in it?


Goal: I am sort of making my own RichEdit toolbar (bold, italic, font type, font size, etc). I want to emulate what MS Word does when a selection of text has more than a single font size spanning the selection.

Ex – You have a line of text with the first 10 characters 9 pt font and the next 15 characters 14 pt font. If you highlight the first 5 characters, the ‘Font Pt Selection’ drop down displays ‘9’. If you then select the first 20 characters, the same drop down should have a empty/blank display.


What I have going so far: I am getting the necessary notification when the selection changes inside of the CRichEditCtrl. Also, if there is only a single font size in the selection I am able to figure that out

CHARFORMAT cf; cf.cbSize = sizeof(CHARFORMAT); CRichEditCtrl ctrl; ctrl.GetSelectionCharFormat( cf ); int nFontPtSize = cf.yHeight / 20; 

This will give me the needed info for the first case of my example above. Unfortunately, what I seem to get for the second part of my example only gives me back the info for where the selection ends (instead of the entire selection).

In conclusion, is there some info I am missing in the CHARFORMAT or some other struct I can get from the CRichEditCtrl or some kind of interesting calculation I can do to make the decision that there are multiple sizes in the selection? So far my only idea is to chug through the selection a character at a time and see if the current font size of that character is different than any of the previous characters. I am mostly just hoping the info I need is there, and I just don’t see it (In a similar way that from the CHARFORMAT’s dwMask member tells me that any or all of Bold, Italic, Underline, etc are turned on).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T20:52:33+00:00Added an answer on May 10, 2026 at 8:52 pm

    As the above answer notes, the easiest way I can think of to do this is to use the Text Object Model (TOM), which is accessed through the ITextDocument COM interface. To get at this from your rich edit control (note code not tested, but should work):

    CComPtr<IRichEditOle> richOle; richOle.Attach(edit.GetIRichEditOle()); CComQIPtr<ITextDocument> textDoc(richOle); 

    Then get a range. Here this is for the selected text, but one of the advantages of TOM is that you can operate on any range, not just what’s selected.

    CComPtr<ITextSelection> range; textDoc->GetSelection(&range); 

    Then get the font for the range, and see what its characteristics are, e.g.

    CComPtr<ITextFont> font; range->GetFont(&font); long size; font->GetSize(&size); 

    If the range is formatted with a single font size, you’ll get that back in ‘size’. If there’s multiple font sizes, you’ll get the value ‘tomUndefined’ instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 61k
  • Answers 61k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Here's a straightforward way to do grouping if your source… May 11, 2026 at 9:51 am
  • added an answer The k means constant in hungarian notation... see Lower case… May 11, 2026 at 9:51 am
  • added an answer You can write it like this: { Name : 'ObjectName',… May 11, 2026 at 9:51 am

Related Questions

Problem: How can I tell if a selection of text in the CRichEditCtrl has
How can I setup a shared ccache without falling into a permissions problem? I
I need some ideas on how I can best solve this problem. I have
This seems like such a trivial problem, but I can't seem to pin how
[update2] One of those problems I solved & can't remember how... :) [update1] could
Given a columns' index, how can you get an Excel column name? The problem
Can anyone recommend some best-practices on how to tackle the problem of starting to
Problem: How to most efficiently move data from an array into a SQL Server
Problem: how to provide a distributed, scalable and disaster resistant pub/sub service with WCF.
I have a problem with how ASP.Net generates the img tag. I have a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.