【问题标题】:Setting Console to Maximized in Dev C++ [duplicate]在 Dev C++ 中将控制台设置为最大化 [重复]
【发布时间】:2011-09-30 05:11:56
【问题描述】:

可能重复:
Changing the width of a Windows console window?

我正在编写一个简单的破砖程序。如何在程序启动时最大化控制台窗口。

#include <iostream>
#include <windows.h>
#include <algorithm>
#include <conio.h>
#define _WIN32_WINNT 0x500
using namespace std;
int lives = 2;
void gotoxy(int x , int y);
void hideCursor();
class Grid
{
      public:
      char grid[20][79];
      void fill()
      {
           for(int i = 0; i < 20; i++)
           {
                   for(int j = 0; j < 79; j++)
                   {
                           grid [i][j] = (char)176;
                   }
            }
      }
      void print()
      {
           gotoxy(0,0);
           for(int i = 0; i < 20; i++)
           {
                   for(int j = 0; j < 79; j++)
                   {
                           cout << grid [i][j];
                   }
                   cout << endl;
           }
      }    
};

class Paddle
{
      public:
      int x_pos;
      char paddle[7];    
      void fill()
      {
           x_pos = 35;
           for (int i = 0; i < 7; i++)
               paddle [i] = (char)219;
      }

      void print()
      {
           gotoxy (x_pos,23);
           for (int j = 0; j < 7; j++)
               cout << paddle [j];
      }
      void redraw()
      {
           for(int i = 0; i < 80; i++)
           {
                   gotoxy (0+i,23);
                   cout << " ";

           } 
           print();  
      }
};
class Ball
{
      public:
      int x_pos, y_pos;
      bool crashed;
      char ball;
      void create()
      {
           ball = 'O';
           crashed = false;
           x_pos = 38;
           y_pos = 22;     
      }
      void show()
      {
           gotoxy (x_pos,y_pos);
           cout << ball;
      }
};

int main()
{ 
    char move;
    Grid grid;
    Paddle paddle;
    Ball ball;
    grid.fill();
    paddle.fill();
    grid.print();
    paddle.print();
    ball.create();
    ball.show();
    hideCursor();
    while(!ball.crashed)
    {
          move = getch();
          move = getch();
          if(move ==  75)
               paddle.x_pos--;
          else if(move == 77)
               paddle.x_pos++;
          paddle.redraw(); 
    }
    cin.get();
    return 0;
}
void hideCursor()
{
    HANDLE cmd;
    CONSOLE_CURSOR_INFO cur;
    char *str = (char*)malloc(32);
    cur.dwSize = 1;
    cur.bVisible = FALSE;  
    cmd = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleCursorInfo(cmd, &cur);
}
void gotoxy(int x , int y)
{
     COORD coord;
     coord.X = x;
     coord.Y = y;
     SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}

【问题讨论】:

标签: c++ windows console-application


【解决方案1】:
HWND hWnd = GetConsoleWindow();
ShowWindow(hWnd,SW_SHOWMAXIMIZED);

这对我有用(开发 - C++)

【讨论】:

    【解决方案2】:

    使用 CONSOLE_FULLSCREEN_MODE 标志调用 SetConsoleDisplayMode() 函数。

    [如果你想让窗口最大化但不进入全屏模式,那么它要复杂得多,因为你必须计算在当前屏幕分辨率下有多少列和行将完全适合屏幕,同时考虑到窗户家具的大小(标题、滚动条、边框)。这不是一项微不足道的任务。请参阅 GetSystemMetrics()、EnumDisplayMonitors()、GetMonitorInfo()、SetConsoleScreenBufferSize() 等]

    【讨论】:

    • 全屏更适合我。但是我该如何实现呢?我不熟悉win32 API,所以我不能自己写。得到任何代码sn-ps。
    • SetConsoleDisplayMode(GetStdHandle(STD_OUTPUT_HANDLE), CONSOLE_FULLSCREEN_MODE, NULL);
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-29
    • 2012-10-11
    • 1970-01-01
    • 1970-01-01
    • 2019-09-01
    • 1970-01-01
    • 2011-12-02
    相关资源
    最近更新 更多