1

I have read the official docs but still was not able to figure this out.

Since English is not my native, I have a hard time constructing effective Google query. I am still trying though...

I would like to enter fractions into RichEdit control, something like the image below:

enter image description here

Can this be done? If so, can you show me how, on a smallest possible example?

AlwaysLearningNewStuff
  • 2,939
  • 3
  • 31
  • 84
  • You want to mix fractions with other text? Or you just want to use a richedit control as a fraction-entering field? Either way I don't think it's going to be possible/easy. – Jonathan Potter Jun 13 '15 at 07:30
  • *Or you just want to use a richedit control as a fraction-entering field?* At the moment, users just want to enter mathematical formulas, so I guess the answer to your question is: I want to use it as fraction entering field. – AlwaysLearningNewStuff Jun 13 '15 at 13:03

1 Answers1

1

I don't think that you're going to get this to work with RichEdit - later versions do have at least some math display support, but as I understand it they don't handle direct input of it. At least, I couldn't find anything online that described how you might enter a formula.

If you can rely on clients having at least Windows 7, you could pop up the Math Input Panel, which will put the resulting equation in MathML format on the clipboard - see, for example, this blog post. Whether that really helps or not depends on what you want to do with the resulting equation. Without more context it's impossible to say.

EDIT1: A few more suggestions occur to me. If you can rely on Microsoft Office being installed you could access the Microsoft Equation Editor from OLE. The catch there is that that's old and there is a danger they might drop it, as it's only now present to allow equations in old Word documents to be edited.

A more interesting approach would be to allow user input in some form (e.g. LaTeX) and then process it to produce an image. For example, you could run the equation through LaTeX in the background, as this website does, or you could investigate MathJax, which is a Javascript library to render equations - you could run this in an MSHTML instance. None of these are particularly easy, of course.

EDIT2: If you can rely on RichEdit 8 (for which you'll need either Windows 8, or a recent Office version), you do get some math support in RichEdit. With some testing, I can turn the linear form entry of "M_0,3/b" into this:

Example equation

This used the following code (a recent Windows SDK is needed) to build up the math zone from the "M_0,3/b" text:

  CWnd* edit = GetDlgItem(IDC_RICHEDIT);
  CComPtr<IRichEditOle> reo;
  edit->SendMessage(EM_GETOLEINTERFACE,0,(LPARAM)&reo);
  CComQIPtr<ITextDocument2> doc = reo;
  CComPtr<ITextRange2> range;
  doc->Range2(0,0,&range);
  range->Expand(tomStory,0);
  range->BuildUpMath(0);
DavidK
  • 3,929
  • 1
  • 19
  • 26
  • *If you can rely on clients having at least Windows 7* Yes I can, it is not a problem. *you could pop up the Math Input Panel* Deserves attention, I just have to figure out how to generate input from keyboard, instead from pointing device. *Whether that really helps or not depends on what you want to do with the resulting equation.* I haven't decided yet, precisely because my task is very difficult as you have noticed. For now I am concerned just with displaying math formula in edit control. – AlwaysLearningNewStuff Jun 19 '15 at 15:18
  • Hey, I have one question: did you use the rich edit from Office? Because I can't make it work with the Windows version. – Xam Sep 19 '19 at 02:57
  • 1
    I think at the time I used a version from Office. When you're using one of the RichEdits that come with Windows, it's worth checking which version you've actually ended up with - I think that msftedit.dll is the one that contains the latest version. – DavidK Sep 29 '19 at 11:49