Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

SetConsoleWindowInfo fails with "Parameter is incorrect"

Posted on 2010-09-24
6
Medium Priority
?
1,432 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 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
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!

 

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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

A few months ago I attended the Rocky Mountain IPv6 Summit which was a two-day educational event; it was the 3rd annual conference held here in Denver, Colorado that was held at the Hyatt Regency Denver at the Colorado Convention Center. It was an e…
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses
Course of the Month20 days, 15 hours left to enroll

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