Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Visually selecting text in MS Visual C++

Posted on 1998-05-30
6
Medium Priority
?
308 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
  • 4
  • 2
6 Comments
 
LVL 22

Expert Comment

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

Accepted Solution

by:
nietod earned 200 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Independent Software Vendors: 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!

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses
Course of the Month10 days, 16 hours left to enroll

886 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