Allegro 5 & C++ - 创建全屏控制台?

Allegro 5 & C++ - Creating a fullscreen console?

本文关键字:控制台 创建 C++ Allegro      更新时间:2023-10-16

好了,这是我的主要目标:得到一个全屏,非窗口控制台程序(当你打开它时看起来像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创建你自己的模拟控制台,但这将是一项艰巨的任务。

一般来说,想要一个控制台应用程序的人并不关心它到底是什么样子,只关心你输入的数据是否正确。