Solved

Highlighting in Edit Box

Posted on 2000-04-04
17
416 Views
Last Modified: 2013-11-20
I want to highlight several words in my edit box, can anybody tell me how to do it ?
Some codes will be help ful
0
Comment
Question by:Iswandi
  • 7
  • 6
  • 2
  • +2
17 Comments
 
LVL 12

Expert Comment

by:migel
ID: 2686470
Hi!
Use CEdit::SetSel(int nIindexStart,  int nIndexEnd)
0
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 2686676
use setsel to select a range as mentioned above else if you wanted to highlight individual words i.e. all 'the's in the
'the quick brown fox jumps over the lazy dog'
then, I think you will have to use an owner draw edit box
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 2688398
an edit box only has a single selection allowed.

you also cannot change the colours of part of the text within an edit box (all text (other than selected) is displayed in the same colours and fonts etc).

if you want to be able to highlight text etc, then use a rich edit control, which lets you contorl font, colour etc of inidividula characters/words etc.

0
 

Author Comment

by:Iswandi
ID: 2689021
Can I use the Rich Edit in dialog box ? I don't know why but my Visual C++ seems to shut the application if I put a rich edit inside the dialog box, and I would like to listen more about owner draw edit box... Can you give me more details Shawn, because I want to do exactly what you tell me? Like I want to highlight all "me" in this comments, and I want the highlight to stays permanently...
0
 

Author Comment

by:Iswandi
ID: 2689025
I'm a beginner programmer, but I have looked through the library of CEdit and Rich Edit, and I do pick up things quite fast and I don't think the question has quite straight forward answer, I would like to post more points, but this is all I got...
0
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 2689053
have a look at http://www.codeguru.com/editctrl/color_edit.shtml - it might even do what you want - it depends on whether you wish to roll your own or not - either way read the code and understand it if you are going to use it
0
 

Expert Comment

by:trraj
ID: 2689239
Hi ,
    As mentioned in previous comment,
   1. use CEdit:SetSet() to select the text.
   2. Get the DC of the Edit box using CWnd:GetDC()
   3. Set the text color using pDC->SetTextColor().

You should be able to do in this way.

0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 2689415
Iswandi .. You can use richedit control in a dialog.  See MS JB article to stop it from crashing... PRB: Dialog With RichEdit May Fail During Creation ID: Q166132

trraj .. SetSsel will only do a single selection .. not multiple as Isawndi requires.  SetTextColor won't help much unless you do in in an WM_CTLCOLOR handler

There is code at codeguru for richedit controls (including a color-highlighted text editor).

look at:
http://www.codeguru.com/richedit/syntax_hilight.shtml
http://www.codeguru.com/richedit/RichSyntaxView.shtml
http://www.codeguru.com/editctrl/syntax_coloring.shtml (CWnd-derived)

0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:Iswandi
ID: 2691913
Adjusted points from 65 to 70
0
 

Author Comment

by:Iswandi
ID: 2691914
I'll try it out and tell you guys how it goes a long
0
 

Author Comment

by:Iswandi
ID: 2742739
trraj, it won't work for multiselection
sorry
0
 
LVL 10

Accepted Solution

by:
RONSLOW earned 70 total points
ID: 2743204
You can display any words highlighted using a rich-edit control.

What you cannot do (easily at least) is multply-select the words with control+click etc.  To do something like that, you'd need to handle the clicking yourself, remember what was selected and change the text colour (and background) appropriately.
0
 

Author Comment

by:Iswandi
ID: 2743235
Can you give me a simple example ?
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 2747004
to highlight a word, select it (programmatically) and change character format.

is it something like syntax highlighting you want?  In that case, then you won't need the ctrl+click (say) to dynamically highlight words selected by the user).  Can you give a better indication of what it is you are trying to do?
0
 

Author Comment

by:Iswandi
ID: 2749924
I just want to highlight a certain words and let the highlighting stays...
let say there is a document containing as follow :

This is a car. This is a book and that is not a pen.

let's say I want is to be highlighted, I want every is in the document to somehow appear differently in color. In this example I'll make them in quotation mark.

Th"is" "is" a car. Th"is" "is" a book and that "is" not a pen.

I want the words in the quotation mark has different color.
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 2750039
in that case, search through the rich-text document looking for the letters "is" and select each one in turn (temporarily) and change the character formatting for the selection to highlight it.

This is the sort of thing syntax colour highlighting does.  Have a look at the examples at codeguru that use the richedit control for syntax colour highlighting and see how they change the colour of the individual words.
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 2750052
see also the MFC docs on CRichEdit for FindText and SetSelectionCharFormat
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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 …
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

746 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

10 Experts available now in Live!

Get 1:1 Help Now