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.