Allegro 5 & C++ - 创建全屏控制台?
Allegro 5 & C++ - Creating a fullscreen console?
好了,这是我的主要目标:得到一个全屏,非窗口控制台程序(当你打开它时看起来像DOS操作系统)。我已经定义了ALLEGRO_USE_CONSOLE
和所有这些东西。下面是我的完整代码:
#define _WIN32_WINNT 0x0500
#define ALLEGRO_USE_CONSOLE
#include <iostream>
#include <windows.h>
#include <stdio.h>
#include <string>
#include <time.h>
#include "include/allegro.h"
using namespace std;
void SetColor(unsigned short hColor) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), hColor);
}
void Dots() {
int i = 1;
while (i <= 3) {
cout << ".";
Sleep(750);
i++;
}
}
void ClearConsoleScreen() {
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD count;
DWORD cellCount;
COORD homeCoords = { 0, 0 };
if (hStdOut == INVALID_HANDLE_VALUE) return;
/* Get the number of cells in the current buffer */
if (!GetConsoleScreenBufferInfo( hStdOut, &csbi )) return;
cellCount = csbi.dwSize.X *csbi.dwSize.Y;
/* Fill the entire buffer with spaces */
if (!FillConsoleOutputCharacter(
hStdOut,
(TCHAR) ' ',
cellCount,
homeCoords,
&count
)
) return;
/* Fill the entire buffer with the current colors and attributes */
if (!FillConsoleOutputAttribute(
hStdOut,
csbi.wAttributes,
cellCount,
homeCoords,
&count
)
) return;
/* Move the cursor home */
SetConsoleCursorPosition( hStdOut, homeCoords );
}
int main() {
ALLEGRO_DISPLAY *display = NULL;
ALLEGRO_DISPLAY_MODE disp_data;
al_init(); // I'm not checking the return value for simplicity.
al_get_display_mode(al_get_num_display_modes() - 1, &disp_data);
al_set_new_display_flags(ALLEGRO_FULLSCREEN);
display = al_create_display(disp_data.width, disp_data.height);
al_rest(3);
al_destroy_display(display);
}
那么我到底需要做些什么才能使控制台全屏(非窗口&无边界)并且能够使用cout
之类的?我用的是Win7
ALLEGRO_USE_CONSOLE只是告诉Allegro你计划在一个控制台窗口中运行程序;您仍然需要在链接器选项中将子系统设置为"console"。Allegro与创建控制台窗口无关。
现在,如果你只是想让控制台在windows上全屏,有SetConsoleDisplayMode,但这与Allegro无关。你不能使用Allegro的绘图API,因为没有Direct3D或OpenGL上下文可以使用。
编辑:似乎上述功能不再适用于现代版本的windows…
使用控制台是非常特定于平台的,这是allegro_native_dialog存在的部分原因。但是没有办法把它放到全屏模式。
如果你想要跨平台的功能,你可以使用Allegro的绘图API创建你自己的模拟控制台,但这将是一项艰巨的任务。
一般来说,想要一个控制台应用程序的人并不关心它到底是什么样子,只关心你输入的数据是否正确。
相关文章:
- 如何从Windows控制台调用.exe(C++)以在不同的目录(或任何目录)中创建文件夹?
- 是否可以从控制台应用程序使用 C++/WinRT 创建窗口?
- 如何创建一个使用开源c项目的c++控制台应用程序
- 创建控制台菜单C++的最佳方式
- VS2017 中缺少 Win32 控制台应用程序.如何创建C++空项目?
- 有没有办法为使用 Boost 生成的进程创建新的控制台窗口
- 在视觉工作室中创建了一个空项目,它似乎不再打开控制台?
- 使用 PowerShell 作为控制台,就像它是使用 AllocConsole 创建的一样
- 来自 c++ 服务的 CreateProcessAsUser 创建进程,但没有控制台
- 在 macOS 上的 Visual Studio 中创建C++控制台应用程序
- 如何在Xcode中创建多个控制台窗口
- 从 WinAPI 窗口创建控制台窗口
- 可以控制台应用程序自行创建窗口
- 如何运行由 Code::Block 创建的控制台应用程序
- 在Xcode控制台项目中创建和使用C++库
- 无法在VS 2013、Windows 8.1中创建Win32控制台应用程序
- 如何在作为控制台启动的应用程序中创建窗口
- 从控制台应用创建新控制台?C++
- 如何在VS Community 2015中创建C++控制台应用程序
- 如何在控制台应用程序中创建命令历史记录