• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

Making Home-Made Textbox Control With Text Selection

Started by Frederick J. Harris, July 04, 2011, 06:02:18 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Frederick J. Harris

Occasionally I use my own textbox class for various things - generally in grids I make.  In other words, I register a window class of my own and code up the necessary responses (message handlers) for WM_CHAR, WM_KEYDOWN, WM_LBUTTONDOWN, etc., and of course allocate my own buffer for text.  Generally my implementations are one line text boxes as opposed, for example, to full text editors.  As I mentioned, I use these in grids where each cell of the visible grid is an instance of my textbox class - in other words, a stripped down version of Charles Petzold's "Typer' program.

Anyway, I don't know how to code the text selection capability, that is, one clicks in the text box that already has text in it, presses the shift key down, then uses the right arrow key to select text which then becomes 'highlighted'.  This is probably a GDI thing, but I suspect that there is some sort of algorithm or procedure to invert the pen and background.  Would anyone know of a tutorial that explains how to do that or a book that explains it, or code they would be willing to share?

Just a little bit of context on my question...

It seems to be a common practice when creating grid custom controls to instantiate/move an edit control, i.e., "edit" class object over the grid cell where a user wishes to edit text.  This is no doubt done to capitalize on the already existing built in code of edit controls.  There are problems with this technique however - at least in my opinion, and I have always tended to prefer writting my own edit control code and that way wouldn't have to subclass an edit control to get the keyboard messages.  The downside to my technique though is that my edit control code is rather rudimentary - certainly not as good as Microsoft's, and I have never provided text selection capability or cut/copy/paste, fonts other than fixed pitch, etc. 

What I'd like to see is if I could code those capabilities up myself or learn from other's code if available.

Jules Marchildon

Maybe check out this article could give you some direction....  http://www.catch22.net/tuts/neatpad/5

I did do this long time ago, the code is sitting on one of  backup cd someplace,(which one?)  if I find it, will let you know.

Worked for single-multi Line, but never completed the scrolling part (with Text Selection highlighted). Think at the time Borje Hagsten released his EDM32.INC custom edit control and that met more than my needs.

regards,
Jules

Frederick J. Harris

Thanks for the info Jules!  Between those two I should be able to figure something out.  However, I just did a quick search of the PB website and wasn't able to come up with a link for getting Borje's edm32.inc.  There was a link, but it didn't work for me (at least on my work computer).  Would anyone know anything about that file or how to get it?  I guess, since Borje is back, I could always ask him.

I think I'd prefer looking at Borge's PowerBASIC procedural code, if it has in it what I want to learn, than C++ class stuff.

José Roca


Frederick J. Harris

Thanks Jose.  Got it!.  I'm almost embarressed to admit I never availed myself to POFFS, even though everybody raves about it.  With that link, maybe now's the time.

Jules Marchildon

Frederick,

I found the code snippet, can post here or send to you via private email?  It is SDK type code compiled with PB header, so not sure, Jose if I can post here?
(had to make a few modifications to recompile with PBWINv905)

Regards,
Jules

José Roca


José Roca

Posts of more than about 50 Kb are cut. Zip the code and attach it to the post.

Jules Marchildon

Blah!... Sorry about that... OK 2nd try, here you go...

Regards,
Jules

Frederick J. Harris

Thanks greatly for taking the time to find that for me and post it Jules!  Just downloaded it!

I have a grid control pretty much 'roughed out' and I used the technique of using Microsoft's "edit" control for editing in a grid cell.  First time I ever made a grid that way.  It worked out better and easier than I thought.   So I'd like to see how small I can get the home-made edit control code down to to support text selection (for the purpose of enabling cut/copy/paste).  Without text selection the code to produce a working single line edit control isn't too great - approx 75 - 100 code lines maybe.  I'm not sure if that will make a better grid or not, but its something that has been playing on my mind for quite a few years and I've finally gotten around to working on it. 

The grid I made has most of the basic features of a grid control but I purposely left out one essential feature - deletion.  I was thinking of posting the code - but I didn't want to interfere with those folks who sell grid controls, so my intention was to leave out quite a few features.  As a custom control what I have compiles to only 28K; as an ActiveX / Com based visual control I'm looking at 42K with the PowerBASIC declares and around 52K with Jose's.  Those numbers are actually somewhat better than I had hoped.  My guesstimate is that I could add all the features I'd need to use it in my apps (cell/row color capabilities, deletion, ability to use combo boxes for columns) with only another 6 - 8 K or so. 

Jules Marchildon

That's great to hear Frederick!

I'm glad you can possibly make some use out of it.  Don't worry about offending any Grid vendors by making your code public. I have my own simple grid, there has been a number of Grid demo's posts already and I purchased a few too, ...recently MLG w/Src.  So don't think it's going to phase their business, if a buyer is serious they will buy one.

Best Regards,
Jules

Frederick J. Harris

Just ran your code with PB9 Jules, and it works great!  I was happily surprised to see that those two PowerBASIC forum links from almost exactly ten years ago still come up and read fine...

http://www.powerbasic.com/support/forums/Forum6/HTML/001779.html

http://www.powerbasic.com/support/forums/Forum6/HTML/001137.html   

I'll be studying your code!  Looks good!