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

x
?
Solved

Working with a Rich Edit Text Control

Posted on 1998-10-01
9
Medium Priority
?
387 Views
Last Modified: 2013-11-20
I have a few problems on Rich Edit TextBox

Firstly, I would like to set different colors to different text in a rich edit textbox. Can anyone help me?

Another problem is that the program cannot detect any mouse event in the textbox (e.g. mouse click using NM_CLICK)

if I were to click a word from a line of text in the control, how can I know which word in the line did I clicked? Just click on the word and not double click or hilighting it.

I hope that someone can offer me help as soon as possible.
If possible, please give examples. Please email me at : tonyleung88@yahoo.com

Thanx in advance
0
Comment
Question by:winwin88
[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
9 Comments
 

Author Comment

by:winwin88
ID: 1322841
Adjusted points to 150
0
 
LVL 2

Expert Comment

by:cyrilbdt
ID: 1322842
void SetColor(int nStart, int nEnd, COLORREF crColor)
{
CHARFORMAT cf;
cf.cbSize = sizeof(cf);
cf.dwMask = CFM_COLOR;
cf.crTextColor = crColor;
TextBox.SetSel(nStart, nEnd);
TextBox.SetSelectionCharFormat(&cd);
}

I have the same problem. One posible way is to override WinProc - is't works.

You can use GetSel() to get current position of caret (nStartChar will be equal to nEndChar), but in wich word you clicked....

0
 

Author Comment

by:winwin88
ID: 1322843
Please give more details......
esp the mouse event problem
this is the cause of my "headache"
0
Technology Partners: 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!

 

Author Comment

by:winwin88
ID: 1322844
Not fully rejected!!!
sorry cyrilbdt anyway thanx for your help

Please give more details......
esp the mouse event problem
this is the cause of my "headache"
0
 
LVL 1

Expert Comment

by:VAM345
ID: 1322845
Go to www.codeguru.com and see can help you.
0
 

Author Comment

by:winwin88
ID: 1322846
I can't find what I need
If you found what I need please tell me so

thanx a lot VAM345
0
 
LVL 1

Expert Comment

by:Fargo
ID: 1322847
I hope, you found the answer to the question why you can't handle the event NM_CLICK. This problem is easy to solve, because there are not much pitfalls there.
Here's a solution to "how can get the character index by a point":

//CPoint pt;
//The point should be in client coordinates of the text-box

....
 m_wndTextBox.ScreenToClient(pt);

DWORD index = m_wndTextBox.SendMessage(EM_CHARFROMPOS, 0, (LPARAM)&pt);
...

//The result of sending this message to the CRichEditCtrl object is the index of the character,
//wich is in the place  of the given point.

I hope I was help :)
0
 

Author Comment

by:winwin88
ID: 1322848
Here again I don't really like to reject others
But I really hope that someone can help me with what I really want
I still can't handle the event NM_CLICK....
But I really thank you for the code that you gave me... I think it should work... I think the mouse event problem is the only problem for me now....
Thanx everyone who has tried to help me

0
 
LVL 1

Accepted Solution

by:
Fargo earned 300 total points
ID: 1322849
The problem with the NM_CLICK may be a general one and if you want to solve it, you have to jungle trough Extended Styles of the control, you're using in the dialog template (I assume you're talking about dialog window, because otherwise you wouldn't have such problem). The problem with the Extended Styles and the notification messages is, that there's a difference between the Win4.0 OS-es like Win95, Win98 and Win NT 4.0 and the Windows NT 3.51 platform. I won't advice you to use ANY of these styles when you develop, 'cause WinNT 3.51 doesn't support them.
Anyway, is there a problem with the ExStyles or not, is not so important. If you cannot get a message from a control in a dialog template, the solution is to subclass the control with your own, and catch the message trough its own message map.
I will recomend you to derive the CRichEditCtrl class with your class, say CMyRichEdit. Then you have to handle the message WM_LBUTTONDOWN in the code of your class. Note that this is NOT a notification message. After you do that, all that's left is the subclassing. Here's a sample code you have to add to your dialog class implementation:

//include the header of your class, representing the RichEdit control
#include "MyRichEditl.h"

...

virtual CMyDialog::OnInitDialog()
{
...
  SubclassRichEdit();
...
}

...

void CMyDialog::SubclassRichEdit()
{
  //suppose you have declared a member variable in your
  //dialog of type CMyRichedit, called m_myRichEdit
 
  VERIFY(m_myRichEdit.SubclassDlgItem(IDC_MY_RICHEDIT, this));

  //...where IDC_MY_RICHEDIT is the ID of the RichEdit control
  //you gave in the dialog template
}

After you subclass the control with your own class in the dialog's OnInitDialog, all the messages sent to the control are passed trough the class CMyRichEdit, so you can handle them without wondering why the notifications doesn't work. I do that really often, when such problem arise.
Hope it'll work, Bye :)

Fargo
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

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 …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

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