Console application for command line emulation

I am developing a console application. I need to emulate how the command line utility works when the F7 button is pressed as shown below:

alt text

Is this possible in C # 2008? If not, is there access to a workaround?

Any help is greatly appreciated.

+2


a source to share


2 answers


Windows has a whole API for writing Console Mode applications. It allows you to listen for mouse or keyboard input in event mode, as well as set foreground and background text colors, position the cursor, etc.

To make a box like the one displayed by CMD.EXE, you use certain special characters to make the border (there are various corner pieces and pieces), use the Symbol Map app to see them all).

To use the Console API from C # you probably need to use pinvoke like



[DllImport("kernel32.dll")] 
public static extern bool SetConsoleTextAttribute(
                            IntPtr hConsoleOutput, int wAttributes);

      

Refer to the docs for SetConsoleTextAttribute for how to use it to set color.

0


a source


I'm not sure if .NET includes wrappers for them or if you have to use them via P / Invoke, but the Win32 API includes functions to do this. For example, you can use ReadConsoleOutput

to read the block of the display you are going to hide. Then you can use WriteConsoleOutput

to display the list (including border). When you're done with the overlay, you'll restore the previous content with another call WriteConsoleOutput

, specifying the block where you saved the underlying data.



Edit: doing a quick check, the correct functionality doesn't jump out at me anyway. Maybe I missed something obvious though ...

+1


a source







All Articles