Solved

CRichEditCtrl and CHARFORMAT2

Posted on 1997-11-11
4
546 Views
Last Modified: 2013-11-19
Dear Experts,

in my application I'm using a CRichEditCtrl on a PropertyPage to design context specific help texts. For this, I have to set double underline and hidden style to selected text portions. The usual CHARFORMAT doesn't support this.

In \MSDEV\INCLUDE\RICHEDIT.H there is a CHARFORMAT2 which has such flags and I derived a new Class from CRichEditCtrl to overwrite SetSelectionCharFormat() to have a correct dwSize set before posting the message.

BOOL CMyRichEditCtrl::SetSelectionCharFormat(CHARFORMAT2 &cf)
{
      ASSERT(::IsWindow(m_hWnd));
      cf.cbSize = sizeof(CHARFORMAT2);
      return (BOOL)::SendMessage(m_hWnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
}

But this has no effect. Neither the new styles are visible (which is ok coz it's mensioned in RICHEDIT.H) nor the styles are stored when streaming out with SF_RTF.

Does anyone have an idea? Answers are highly appreciated. Thanx in advance.

Environment: WIN NT 4.0, MSVC 4.2

Best regards,
Teff
0
Comment
Question by:teff
  • 2
  • 2
4 Comments
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1309821
If you take a look at CRichEditCtrl's source code in WinCtrl4.cpp, you'll see that the class has been hardcoded to use version 1.0 of the richedit control. You can derive your own class from CRichEditCtrl to override the create to use the version 2.0 of RICHEDIT.

Note that you should use the class name of RICHEDIT_CLASS instead of a string constant.


0
 

Author Comment

by:teff
ID: 1309822
Hello thui,

thanx for your answer. I derived my class as you proposed and overrode the create as follows:

BOOL CHelpEditCtrl::Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID)
{
      m_hInstRichEdit = LoadLibraryA("RICHED32.DLL");
      if (m_hInstRichEdit == NULL)
            return FALSE;

      CWnd* pWnd = this;
      return pWnd->Create(RICHEDIT_CLASS, NULL, dwStyle, rect, pParentWnd, nID);
}

But with this, the WIN-API ::CreateEx returns NULL and the GetLastError() returns 0x057F.

What have I done wrong? Do I need the complete _AFX_RICHEDIT_STATE stuff from WinCtrl4.cpp?

I'm looking forward to your answer.

Yours,
Teff
0
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 200 total points
ID: 1309823
If you look in Winerror.h, GetLastError() returning 057F means it cannot find the wndclass. That means that the RichEdit control does not exist on your system. Or it means you did not initialize the rich edit control correctly. You should probably load riched20.dll I would assume.
0
 

Author Comment

by:teff
ID: 1309824
Hello thui,

thanx again. I will now close this question, but I'm not absolutely happy with it.
As you see in my code example I load RICHED20.DLL, in a wrong way I assume. But I'm not experienced enough to do this AFX_ stuff as in WINCTRL4.CPP. So if you have a final proposal (or example) please let me know.

Bye, Teff
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
GIF file bit manipulation for color change 5 104
Generic progress indicator 6 109
only14 challenge 19 63
isEverywhere  challenge 19 64
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now