Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CRichEditCtrl and CHARFORMAT2

Posted on 1997-11-11
4
Medium Priority
?
573 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…

730 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