Solved

CRichEditCtrl and CHARFORMAT2

Posted on 1997-11-11
4
566 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

627 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