Solved

SetConsoleWindowInfo fails with "Parameter is incorrect"

Posted on 2010-09-24
6
1,380 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
IPv6 Address reservation on Cisco router 3 64
FILEZILLA Client "default"? 2 53
Resolve Dependency Issues 4 86
route-map permit with a number 1 54
Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
The viewer will learn how to use and create new code templates 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…

733 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