Thursday, July 30, 2009

Can someone link me a tutorial for how to do this in c++?

I'm trying to make a console program that displays a string of characters on the screen, and then you can scroll left and right within that string and type over the characters to make new words.





like say you have the string "abcdefg" and the cursor is under the g character, and you can hit the left arrow key to move the cursor under the d key and change it to a q.





the only type of c++ programs I've ever written are those where you sequentially output a line of text at a time, like a forward only linear fashion. I want to be able to manipulate the string in place on the screen, but I have no idea how this approach is done. can someone give me a link to a site that explains how this can be done?





thank you!


-SelArom

Can someone link me a tutorial for how to do this in c++?
Look at ncurses (POSIX systems) or pdcurses (not sure if it works properly).





Otherwise, you'll have to implement it by yourself with the windows API.
Reply:C++ is a very powerful language, and it can do a lot more than the console display. Consider learning win32 c++, which is more advanced. Then you can do this and more with the GUI features. (or maybe not, I forgot already. sorry, not much help...)
Reply:Wow, this reminds me of the line editing BASIC programmers had to use in the early 80's. It is easier to do what you want to do in the console, because keeping track of the exact placement of text in a window is more work.





Information on Windows console programming and a reference of all the Windows console functions are in the links below. You should be able to accomplish your goal easily with these functions.


http://msdn2.microsoft.com/en-us/library...


http://msdn2.microsoft.com/en-us/library...





You need to create an input routine that moves the cursor when you use the arrow keys. The routine also needs to print out an ASCII character and move the cursor when you're typing text characters.


Getting the changes in a string can be done a couple different ways. If you have 1 string per line, then this makes life easier. You would just use the ReadConsoleOutputCharacter() function to read and copy the text on the line that you modified. Otherwise, you'll have to create your own 'text selection' code.


No comments:

Post a Comment