Solved

SetConsoleWindowInfo fails with "Parameter is incorrect"

Posted on 2010-09-24
6
1,373 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
ID: 33759539
can you post the source code?
0
 
LVL 8

Expert Comment

by:Pramod Bugudai
ID: 33768562
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
ID: 33769424
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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

Author Comment

by:JeepGuy
ID: 33774641
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
ID: 33776410
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
ID: 33811152
OK, I got it to work.  Not sure what my problem was before, but it's working now.  Thanks :-)
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Losing network connectivity 8 99
Win 2008 server lost access to network router 5 102
CKEditor - will not function 7 70
Configuring EIGRP with neighbor command 25 60
In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Understanding FTPS File transfer is a common requirement in most Enterprises. While there are numerous ways to get a file from Point A to Point B over a network, perhaps the most common method still in use is FTP – File Transfer Protocol. FTP is …
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
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…

810 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