Click here to Skip to main content
15,888,181 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
just working stuff with winapi, and i'm not sure how to approach something. my goal here is to have a control that will simply print things to the screen just like a command prompt would. for example, i would like to be a able to have a function that would very simply just add a string onto a printout rather than replace the text every call. first question, should i just try to make a brand new control that prints text to the screen in lines, or should i try modifying or subclassing the EDIT control? second quesiton, I would rather not do this with just one massive string which i would concat strings to and redraw everytime text is entered, but is there any other way?

Also, am i making mountains out of molehills and just overlooking a common control that does just this?
Posted

1 solution

No, I don't think you will find some well-known control to do this, simply because this task is quite unusual. You need to do it from scratch. There is no such thing as "screen" it terms of any Windows object. You have to type in the desktop, which is a normal window. None of the approaches you listed can help. If you use EDIT control, it would be pretty much developing of a quite usual Windows application. If this is what you need, stop here.

If you really want to work with the desktop; it's not so easy. First, find the HWND of the desktop using the function GetDesktopWindow. Than inject new Windows procedure using SetWindowLong with the first parameter of desktop HWND and second parameter of GWL_WNDPROC. Don't forget to get all Windows procedure using SetWindowLong — you will need it to implement yours. Modify processing of the message WM_PAINT. Now, you need to organize some "virtual screen" which will reflect all text input/output of your command interpreter. In your handler of WM_PAINT provide rendering of your "virtual screen" onto desktop graphics. Simulate text caret; you may need to use timer to simulate blinking. Every change will need a call to Invalidate which will trigger sending of new WM_PAINT and re-rendering. You may want to use InvalidateRect or InvalidateRgn to improve performance by invalidating only a part of the scene.

For a command interpreter you can use available "CMD.EXE", only you will need to redirect all output (stderr and stdoutput) to your custom streams to process them in your desktop rendering procedure. Your input you can simply echo and put to redirected stdoutput via Invalidate.

This is all is quite doable but will take good amount of patience and attention to detail. Good exercise!

—SA
 
Share this answer
 
v3
Comments
FatalCatharsis 28-Aug-11 0:16am    
wow, that was entirely not what i meant, i just meant a child window within an application that printed text with a very simple command from the main window procedure, which i later found out was a lot easier than i was about to make it out to be :P. but this little article here has also given me quite a few ideas for some awesome future projects, so i'll accept your solution. Thank you for your input!
Sergey Alexandrovich Kryukov 28-Aug-11 0:28am    
Well, thank you for accepting it. (I just added few more words, please see.) I mentioned that what you need is pretty much like a regular application. All you need it to simulate text input/output like in command interpreter. The redirection will solve the problem.

Good luck, call again.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900