Click here to Skip to main content
15,887,944 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
So, how does one code these methods/functions in Linux ?

C++
void drawengine::gotoxy(int x, int y)
{
	COORD pos;

	pos.X = x;
	pos.Y = y;

	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}

void drawengine::setcursor(bool visible)
{
	CONSOLE_CURSOR_INFO ccinfo;

	ccinfo.dwSize = 1;
	ccinfo.bVisible = visible;

	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &ccinfo);
}

void drawengine::consolesize(int x, int y)
{
	SMALL_RECT windowSize = {0, 0, x, y};
	
	SetConsoleWindowInfo(GetStdHandle(STD_OUTPUT_HANDLE), TRUE, &windowSize);
}

void drawengine::fullscreen()
{
	SetConsoleDisplayMode(GetStdHandle(STD_OUTPUT_HANDLE), CONSOLE_FULLSCREEN_MODE, 0);
}


EDIT:
I'm sorry, I didn't explain well. I am aware that these functions only work on a windows environment. I am asking for an alternative and not how to make these Win32 API calls work on Linux. Matthew Faithfull mentioned NCurses, can someone give a simple implementation? or provide a link to a clear tutorial?

Thank you.
Posted
Updated 18-Mar-13 5:25am
v3
Comments
Richard MacCutchan 18-Mar-13 12:16pm    
Google will find you lots of tutorials on programming for Linux, using curses or GTK.

1 solution

The simple answer is that you can't but that's not quite the whole story.

If you want to continue to use Win32 API calls like SetConsoleDisplayMode then you're going to need a Linux implementation of Win32. The best known of these is 'Wine Is Not an Emulator'[^]. This will give you what you need.

Another alternative is to change your code ( assuming it's all console based ) to use the NCurses library. This does all the Console realted stuff you could want and is part of the Linux Standard Base ( i.e. available in every distro ). It's also available on Windows as PDCurses ( Public Domain Curses ). Using this approach would give you extremely portable code that could be built for almost anything from Android to Windows to OSX.
 
Share this answer
 
Comments
_Shepherd 18-Mar-13 11:27am    
Thank you for your answer. Please read my question again, I have edited it.
Matthew Faithfull 18-Mar-13 11:57am    
No problem. There seem to be lots of NCurses tutorials on the web.
http://www.writeka.com/ed/ncurses_library.html looks very basic.
There's even a You Tube Video series.
http://www.youtube.com/playlist?list=PL2C01CC54638DD952

You aren't however going to find one-to-one matches for functions like SetConsoleWindowInfo NCurses has it's own way of doing things. You could however 'borrow' the whole implementation of SetConsoleWindowInfo from the WINE sources if you wanted.

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