Solved

Working with a Rich Edit Text Control

Posted on 1998-10-01
9
378 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
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
 

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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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 150 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now