在Dev C ++中将控制台设置为最大化 [英] Setting Console to Maximized in Dev C++

查看:1002
本文介绍了在Dev C ++中将控制台设置为最大化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

更改Windows控制台窗口的宽度

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

Im writing a simple brick breaker program. How do I maximize the console window, when the program starts.

#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);
}


推荐答案

http://msdn.microsoft.com/en-us/library/ms686028%28v=vs.85%29.aspx =nofollow> SetConsoleDisplayMode()函数与CONSOLE_FULLSCREEN_MODE标志。

Call the SetConsoleDisplayMode() function with the CONSOLE_FULLSCREEN_MODE flag.

[如果你想使窗口最大化,但不进入全屏模式,那么它是一个非常复杂,因为你必须计算多少列和行将完全适合屏幕以当前屏幕分辨率,考虑到窗口家具的大小(标题,滚动条,边框)。这不是一个简单的任务。请参阅GetSystemMetrics(),EnumDisplayMonitors(),GetMonitorInfo(),SetConsoleScreenBufferSize()等。]

[If you want to make the window maximise but not go into full screen mode then it is a lot more complicated because you have to calculate how many columns and rows will exactly fit the screen at the current screen resolution, taking into account the size of the window furniture (caption, scrollbars, borders). That isn't a trivial task. See GetSystemMetrics(), EnumDisplayMonitors(), GetMonitorInfo(), SetConsoleScreenBufferSize(), etc.]

这篇关于在Dev C ++中将控制台设置为最大化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆