can anyone teach me how to set the size of console window?

Recommended Answers

All 8 Replies

To adjust size of your console window, only modify the size of cmd.exe console.
Because implicitly cmd.exe provides console to our exe

Here is the steps:
1. Goto Run
2. type cmd
3. Right click on TitleBar
4. Goto Property
5. Set the height and width as per your requirement
6. Press OK and Check option "Save properties for future windows".

I mean set the console window size when executing a program. I'm currently trying to created a snake game but I dont know how to set window size.

Are you creating Win32 GUI application?

If yes, in your
HWND CreateWindow( LPCTSTR lpClassName,
LPCTSTR lpWindowName,
DWORD dwStyle,
int x,
int y,
int nWidth,
int nHeight,
HWND hWndParent,
HMENU hMenu,
HINSTANCE hInstance,
LPVOID lpParam
);
function set the nWidth and nHeight parameter.

This will solve your problem

HWND console = GetConsoleWindow();
  RECT ConsoleRect;
  GetWindowRect(console, &ConsoleRect); 

   MoveWindow(console, ConsoleRect.left, ConsoleRect.top, 800, 600, TRUE);

I get it wrong.It say GetConsoleWindow was not in scope. Do I need to include any library here other than iostream?

Yes, #include "windows.h"

I've included the windows.h header but still the have an error here. It say GetConsoleWindow was not declared in this scope. FYI Im using MinGW g++ compiler.

#include <iostream>
#include <windows.h>

using namespace std;

int main () {
	HWND console = GetConsoleWindow();
	RECT ConsoleRect;
	GetWindowRect(console, &ConsoleRect); 
 
   MoveWindow(console, ConsoleRect.left, ConsoleRect.top, 60, 40, TRUE);
   
   system ("pause");

}

Ohh its ok now. problem solved. many thanks.. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.