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

Recommended Answers

All 12 Replies

>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

UMMMM could u plese xplain how and what it does

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;
}
commented: Nice Post:Sunny +1

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?

xp and im only 14 so i cnt realy afford VC++

Owww wicked i thought it costed a fourtune
thanks alot

Wolfpack's program works ok with Dev-C++ too. I have version 4.9.9.2, but some previous versions should work too.

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++

Thanks wolfpack i got the new dev-c++ 4.9.9.2 and that code works now

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.