Solved

Visually selecting text in MS Visual C++

Posted on 1998-05-30
6
299 Views
Last Modified: 2008-03-06
How can I write some display logic in my WM_PAINT: section
that can show the user what text he is selecting with
the mouse??  I am not using MFC, as I am learning that on
the side, meanwhile, I need something quick.  I can't use
a text box or control that automatically has it, because
I have much custom display logic already.  I will always
accept suggestions for change however.
((I am using Microsoft Visual C++ 2.0.))


Side Question: Are there any tools that can speed up
development with MS VC++ ??  Any libraries??
I would prefer C, and non MFC. (I'm a caveman programmer.)
(This dosen't have anything to do with the main question
 And it dosen't need to be answered to obtain points.)
0
Comment
Question by:cwilliso
[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
  • 4
  • 2
6 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1164965
answer coming.
0
 
LVL 22

Accepted Solution

by:
nietod earned 100 total points
ID: 1164966
Opp's that was supposed to be an answer.

I don't use edit boxes (or any built in control) either.  I've written my own (they are substancially more powerful that window's.)

details to follow.


0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1164967
Simply change the font or text colour appropriately when you draw the text.  There is no need for text boxes or anything any more complicated.

Another way to show a selection is to use 'greying' function.  An easy one is to use a checkerboard patterns of bits and xor fill the bounding rect of the text, then draw the text and finally xor fill the rectangle again.  This will 'grey' the selected text only .. it is quite effective.

I use this techinqiue in my CAD/drawing package to display selected text (and other objects) in a drawing.

BTW: if this is helpful to you, don't forget that you need to reject the currently proposed answer in order to grade me .. or apply to EE customer service to split the points.

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 22

Expert Comment

by:nietod
ID: 1164968
First, what you need to do is maitain some information about the selection.  I use a structure that has an enumerated type that indicates if the cursor is in "insert", "overtype", or "selection".  It also has two ints.  One is the offset of the cursor, in terms of the number of characters into the edit box.  This is used for all cursor types.  The second integer is the length of the selection cursor, in terms of the number of characters selected.  Obviously this is used only in the selection cursor type.

I assume you want the text color to be the same throughout, but want to change the background where the cursor is.
When you set the DC's text color to what you want as the foreground color.  Ussualy black.  You set the DC's background color for the non-cursor color.  Probably white or maybe grey.  Then you TextOut() the characters that appear before the cursor.  (If there are no characters before the cursor, You can textout() zero characters safely).  Then you calculate the position of the end of wat you outputed (use one of the GetTextExtent() functions).  Set the background to the cursor color (I use different colors for each cursor type).  Then ouput the number of characters that are part of the cursor.  (1 for insert or overtype.  Multiple for a selection).  Then set the DC's background color back to you edit box's background color and print the remaining characters.

I hope this helps.  Let me know if you need more.

0
 
LVL 22

Expert Comment

by:nietod
ID: 1164969
One thing to be careful of is to make sure your painting procedure can safeuly handle the fact that the text's length changes as the characters change.  (Assuming you have a proportional font).  The problem is that if you type in a short character to replace a long character.  A i to replace a W for example.  The string gets shorter (in display length), so their is an area to the right of the end of the displayed string that used to contain displayed text, but should not be clear.  You need to clear this area by filling it with your background color.
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1164970
To reiterate (as my comment was in the midst of nietod's multi-part answer..

Simply change the font or text colour appropriately when you draw the text.  There is no need for text boxes or anything any more complicated.

Another way to show a selection is to use 'greying' function.  An easy one is to use a checkerboard patterns of bits and xor fill the bounding rect of the text, then draw the text and finally xor fill the rectangle again.  This will 'grey' the selected text only .. it is quite effective.

I use this techinqiue in my CAD/drawing package to display selected text (and other objects) in a drawing.

BTW: if this is helpful to you, don't forget that you need to reject the currently proposed answer in order to grade me .. or apply to EE customer service to split the points.

PS: I can provide some code to show hwo this is done (working out a bounding box, and doing the highlighting).

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

635 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