1

Possible Duplicate:
Changing the width of a Windows console window?

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); } 
2
  • stackoverflow.com/questions/190543/… Commented Jul 7, 2011 at 6:51
  • 2
    This isn't a duplicate. The linked question is about changing the number of columns in a console window. This one is about going into full screen mode. Commented Apr 23, 2014 at 8:54

2 Answers 2

3
HWND hWnd = GetConsoleWindow(); ShowWindow(hWnd,SW_SHOWMAXIMIZED); 

This works for me (Dev - C++)

Sign up to request clarification or add additional context in comments.

Comments

2

Call the SetConsoleDisplayMode() function with the CONSOLE_FULLSCREEN_MODE flag.

[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.]

2 Comments

Full screen suits me better. But how do I implement it ? Im not familiar with the win32 API, so I cant write it myself. Got any code snippets.
SetConsoleDisplayMode(GetStdHandle(STD_OUTPUT_HANDLE), CONSOLE_FULLSCREEN_MODE, NULL);

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.