Solved

SetConsoleWindowInfo fails with "Parameter is incorrect"

Posted on 2010-09-24
6
1,345 Views
Last Modified: 2013-12-14
I'm trying to change the size of my console window using the standard methods in Visual Studio.  When I call SetConsoleWindowInfo() with my rectangle defined as anything bigger than 80 x 25 it blows up and gives me the oh-so-helpful error: "Parameter is incorrect".  I've called GetLargestConsoleWindowSize() and it returns 210 x 81, so I don't understand why SetConsoleWindowInfo() is failing.  I've tried to delete the 'console' key in the registry under HKEY_CURRENT_USER->Console, but still no luck.

Ideas?
0
Comment
Question by:JeepGuy
  • 3
  • 2
6 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
Comment Utility
can you post the source code?
0
 
LVL 8

Expert Comment

by:Pramod Bugudai
Comment Utility
Hi. You followed the right way to do that. Its not possible to do that using SetConsoleWindowInfo(). Further follow this link.

http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvc/thread/7eb84377-10e8-4ac4-889a-33ce6bdaa185
0
 
LVL 8

Accepted Solution

by:
Pramod Bugudai earned 500 total points
Comment Utility
One dirty way of doing this is follows:

#include <iostream>

//the following line is necessary for the
//  GetConsoleWindow() function to work!
//it basically says that you are running this
//  program on Windows 2000 or higher
#define _WIN32_WINNT 0x0500

//it is important that the above line be typed
//  BEFORE <windows.h> is included
#include <windows.h>

using namespace std;

int main (void)
{
  HWND console = GetConsoleWindow();
  RECT r;
  GetWindowRect(console, &r); //stores the console's current dimensions

  //MoveWindow(window_handle, x, y, width, height, redraw_window);
  MoveWindow(console, /*r.left*/0,/* r.top*/0, 800, 600, TRUE);
  for (int j = 0; j < 100; ++j)
    {
      for (int i = 0x41; i < 0x5B; ++i)
        cout << (char)i;
    }
  cout << endl;
  //Sleep(1000);    //To stay for a while and rollback to normal console window un-comment these two linens
  //MoveWindow(console, r.left, r.top, r.right - r.left, r.bottom - r.top, TRUE);
}
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:JeepGuy
Comment Utility
Still no workey.  I tried the recommended MoveWindow() call and it just moves it to a new location, but it still maxes out the same size as it defaults to when I call GetConsoleWindow().  The window is actually about 1/6 the size of the entire screen and I just want to make it a bit wider.  It doesn't seem to want to go bigger though.
0
 
LVL 8

Expert Comment

by:Pramod Bugudai
Comment Utility
Its working fine for me.

MoveWindow(console, /*r.left*/0,/* r.top*/0, 800, 600, TRUE);
The above API's 2nd, 3rd are fro left top corner and 4th,5th are right bottom corner. Try it with your requirement type. Just copy and paste the code to your code editor and try.

Remove this two line of code and compile. It should work.

 //Sleep(1000);    //To stay for a while and rollback to normal console window un-comment these two linens
  //MoveWindow(console, r.left, r.top, r.right - r.left, r.bottom - r.top, TRUE);


0
 

Author Comment

by:JeepGuy
Comment Utility
OK, I got it to work.  Not sure what my problem was before, but it's working now.  Thanks :-)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org (http://seleniumhq.org) Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now