?
Solved

SetConsoleWindowInfo fails with "Parameter is incorrect"

Posted on 2010-09-24
6
Medium Priority
?
1,406 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 2000 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
Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

 

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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

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…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
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…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

770 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