将windows.h代码移植到Linux? [英] Porting windows.h code to Linux ?
本文介绍了将windows.h代码移植到Linux?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
那么,如何在Linux中对这些方法/函数进行编码?
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);
}
编辑:
对不起,我没解释清楚。我知道这些功能只适用于Windows环境。我要求替代方案而不是如何使这些Win32 API调用在Linux上运行。 Matthew Faithfull提到了NCurses,有人能给出一个简单的实现吗?或提供一个清晰教程的链接?
谢谢。
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.
推荐答案
简单的答案是你不能,但这不是完整的故事。
如果你想继续使用Win32 API调用,比如SetConsoleDisplayMode
然后你需要一个Win32的Linux实现。其中最着名的是''Wine Is Not a Emulator'' [ ^ ]。这将为您提供所需的信息。
另一种方法是更改代码(假设它基于所有控制台)以使用NCurses库。这可以完成您可能想要的所有Console实现的东西,并且是Linux Standard Base的一部分(即在每个发行版中都可用)。它也可以在Windows上作为PDCurses(Public Domain Curses)使用。使用这种方法可以为您提供极其可移植的代码,几乎可以为从Android到Windows到OSX的任何内容构建。
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 likeSetConsoleDisplayMode
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.
这篇关于将windows.h代码移植到Linux?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文