Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C Windows Linux Ubuntu
So, how does one code these methods/functions in Linux ?
 
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 17-Mar-13 16:37pm
Edited 18-Mar-13 6:25am
v3
Comments
Richard MacCutchan at 18-Mar-13 12:16pm
   
Google will find you lots of tutorials on programming for Linux, using curses or GTK.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
_Shepherd at 18-Mar-13 11:27am
   
Thank you for your answer. Please read my question again, I have edited it.
Matthew Faithfull at 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)

  Print Answers RSS
0 OriginalGriff 406
1 Marcin Kozub 225
2 Sergey Alexandrovich Kryukov 205
3 /\jmot 175
4 Shweta N Mishra 161
0 OriginalGriff 8,289
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,624
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 18 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100