Solved

CRichEditCtrl and CHARFORMAT2

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Include multiple hostnames in this command? 3 56
not able to insert into temp table 68 179
ShiftLeft challenge 21 96
Adjust the codes 3 65
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: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

710 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