Solved

CRichEditCtrl and CHARFORMAT2

Posted on 1997-11-11
4
556 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

809 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