Setting console cursor and font color - c++

How can I set console cursor and its font color without including windows.h? is there any alternative way available?

There is no platform-independent method for doing this.

Since it seems you are using windows you can use the console calls
see http://msdn.microsoft.com/en-us/library/ms685032(v=vs.85).aspx
alternatively you can use the old ANSI.SYS to color the text, but you would need to load the driver in config.sys for your console.

Related

WebStorm wraps text not as expected

How can I configure WebStorm so that it wraps text near the restriction line but not at the window corner?
There's currently no native setting that can enable this directly.
However, someone wrote a plugin for this : WrapToColumn.

How to get the window state of a C++ console application

I'm writing a console app in C++ but can't seem to find how to figure out the console window state (i.e. normal, minimized, etc.). Any idea on how to do this?
For Windows use GetConsoleWindow to get a handle to the window, then e.g. GetWindowPlacement.
But what on Earth are you planning to use this information for?

getenv("LINES") doesnt work on windows

i tried to use LINES = atoi(getenv("LINES")) in windows (visual studio 2012), but it doesn't work. Someone told me that I have to add export LINES to .bashrc or .profile. Will that solve my problem?
If it does, how to add export LINES to .bashrc or .profile?
You almost certainly want GetConsoleScreenBufferInfo to retrieve the screen buffer info (and GetStdHandle to get the console handle).
There's neither .bashrc nor .bash_profile on Windows. In order to get the current console window size, use the GetConsoleScreenBufferInfo API. Look it up. Since the window is resizable, you might want to watch that size. Use ReadConsoleInput or PeekConsoleInput to check for window resizing.
Why are you trying to get the console window dimensions, and why won't you write a proper GUI application instead?
If you are working in Visual Studio, and you just set the LINES variable, you need to first restart the IDE after setting the environment variable. Otherwise, getenv() will not return it in the processes spawned by the IDE.

Console App Whereabouts c++

How would you set the initial position of a Console App on your Screen?
It's a console app, so it has no concept of where its window is, as it doesn't know what a window is.
For Windows, you could use the GetConsoleWindow function followed by SetWindowPos with the SWP_NOSIZE and SWP_NOZORDER flags set.
I think that you're going to be more specific. With a console app, the output goes to stdout without any real control over how the console deals with it. The console deals with displaying it and normally just prints it out.
If you want more control over the console like being able to reposition the cursor or being able to erase or redraw portions of the console, then you'll likely need to look into a library like ncurses.
You can't. Put simply. If you use non-standard extensions, for example, if you made your own console via WinAPI, you might be able to make such an effect. However, within terms of just cin/cout, then you can't.
If you're in windows, then you have to set the position of the final executable. If you click the application icon and then click "Defaults" on the resulting menu, one of the options is for position.
Unfortunately, no idea how to do that on other platforms.

Implementing my own print preview?

I have developed my own Report Control which is simply nothing but drawing text on a CDC of the control window's client DC. I have got the printing function to work too. The report output is sent to the printer directly. However I want to let the user know the output before the report is actually printed.
I cannot do this using MFC's print preview architecture as my project is not using the doc/view architecture. Is it possible for me to create a print preview window myself ? How does MFC handle this ? Are there any special processing need to be done or keep in mind when showing the printer output on screen ? I've read that MFC used 2 DCs for print preview purposes. Do I need to do this as well if Im goin for a custom print preview ?
Your input is highly appreciated !
tia.
P.S. i use Visual Studio 6 and there is no option to change this to a newer version just as there is no way for me to add doc/view support.
Print preview isn't that special. It just means that you have to render to screen (or bitmap) what you'd otherwise would render to the printer DC. This primarly means using the page size, and providing a UI control for the prev/next page.
I had tweeked this code in order to compile it as static lib. It is for dialog based applications.If you don't need special functionality it will work ok for you.
I had to dig through MFC mechanisms to add extra functionality but at the end I dropped it. If you know other programming languages, try to find a print preview control in that language, make it a dll and use it from your MFC application.
For example, I found the NicePreview control for Delphi and it worked, for me, beautifully !
if you managed to print your output to a file in an RTF format and displayed it on screen would this solve the problem?
There is a class CPreviewView in MFC. Maybe you can find a way to instantiate it without MDI structure.
Otherwise, you can simply paint on screen whatever you are painting on the printer DC. Just remember that you will probably need to scale it down for lower dpi.