[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Highlighting in Edit Box

Posted on 2000-04-04
17
Medium Priority
?
483 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
[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
  • 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
Industry Leaders: 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: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
 

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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

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. …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

656 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