Is there any way to resize a console program while its running

also whats a better way to clear the console then

system("cls");

cheers

>Is there any way to resize a console program while its running
Perhaps.

>also whats a better way to clear the console then
The best way to clear the console is to not clear the console. But if you must, there really isn't a good way, so pick whichever you like the best.

thanks i get lost in msdn and cant find what im looking for or where to look first
to much info in that place for me

Narue's method should work. But I could not get it to compile in my machine. It needs Windows XP or higher.

Here is a small piece of code that resizes the window. But the dimensions should be specified in pixels, not by the number of characters as in Narue's method.

You can find a Screen Clearing Program in the Code Snippets section submited by vegaseat.

#if (_WIN32_WINNT < 0x0500) // This switch is needed to make the program compile
#undef _WIN32_WINNT	    // because GetConsoleWindow needs it. See Documentation
#define _WIN32_WINNT 0x0500 // for GetConsoleWindow in MSDN.
#endif

#include <windows.h> 
 
int main() 
{ 
	system( "pause" );

	// Get the window handle for Console Window
        HWND hwnd = GetConsoleWindow( );
	int newX		= 0; // We will ignore this parameter by using the SWP_NOMOVE flag in SetWindowPos
	int newY		= 0; // We will ignore this parameter by using the SWP_NOMOVE flag in SetWindowPos
	int newWidth	= 500;	// New Width in Pixels
	int newHeight	= 100;	// New Height in Pixels
	// Position the console window so that the left and right corners are not changed but the height and width are.
	SetWindowPos(hwnd, HWND_TOP, newX, newY, newWidth, newHeight, SWP_NOMOVE); // Using SWP_NOMOVE will cause newX and new Y to be ignored

	system( "pause" );

	return 0;
}
Comments
Nice Post:Sunny

I just tried that but i get 2 errors

13 c:\dev-c_~1\untitl~1.cpp
implicit declaration of function `int GetConsoleWindow(...)'

13 c:\dev-c_~1\untitl~1.cpp
initialization to `HWND__ *' from `int' lacks a cast

whats going wrong??

Beats me. Looks like a compiler issue. I dont know dev-cpp so I cant help on that. It ran fine under Visual Studio.Net and Windows 2000, so get someone who knows dev-cpp to figure it out or try using VC++.

By the way, what is the Operating System?

Dam dat msvc++ is a litle big for my dialup connection
the .net bit is 91 mb by its self

It looks like il just have to get the lastest update of Dev-C++

This article has been dead for over six months. Start a new discussion instead.