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

时间:2013-06-17 20:43:01

标签: c++ windows-7 mingw codeblocks allegro5

好的,这是我的主要目标:获得一个全屏,非窗口控制台程序(当你打开它时看起来像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。

1 个答案:

答案 0 :(得分:0)

ALLEGRO_USE_CONSOLE告诉Allegro你计划用控制台窗口运行程序;您仍然必须在链接器选项中将子系统设置为“console”。 Allegro与创建控制台窗口无关。

现在,如果你只是想在windows上全屏显示控制台,那就是SetConsoleDisplayMode,但这与Allegro无关。您不能使用Allegro的绘图API,因为没有Direct3D或OpenGL上下文可供使用。

编辑:似乎以上功能不再适用于现代版本的Windows ...

使用控制台是特定于平台的,这是allegro_native_dialog存在的部分原因。但是没有办法将其置于全屏模式。

如果您需要跨平台功能,可以使用Allegro的绘图API创建自己的模拟控制台,但这将是一项艰巨的任务。

一般来说,想要控制台应用程序的用户并不关心它的外观,只是为您输入的数据提供了正确的数据。