7 Replies - 315 Views - Last Post: 24 April 2013 - 07:33 AM Rate Topic: -----

#1 lewm  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 160
  • Joined: 29-March 13

Console Size

Posted 19 April 2013 - 05:24 PM

#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#include <math.h>

main()
{
    char mod[13]="MODE 14, 1", a[1]={0};
    int i=0, x=14, y=1;
    
    do
    {
        sprintf(mod, "MODE %d, %d", x, y);
        system(mod);
        printf("x = %d  y = %d", x, y);
        a[0]=getch();
        a[1]='\0';
        if(a[0] != 'q' && a[0] != 'a' && a[0] != 'o' && a[0] != 'p')
            i=1;
        else
        {
            if(a[0] == 'p')
                x++;
            else
            if(a[0] == 'o')
            {
                x--;
                if(x < 14)
                    x=14;                    
            }  
            else
            if(a[0] == 'a')
                y++;
            else
            if(a[0] == 'q')
            {
                y--;
                if(y < 1)
                    y=1;
            }    
        }
    }while(i == 0);
    a[1]='\0';
    return 0;
}


Is This A Good Question/Topic? 0
  • +

Replies To: Console Size

#2 lewm  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 160
  • Joined: 29-March 13

Re: Console Size

Posted 19 April 2013 - 05:33 PM

View Postlewm, on 19 April 2013 - 05:24 PM, said:

#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#include <math.h>

main()
{
    char mod[13]="MODE 14, 1", a[1]={0};
    int i=0, x=14, y=1;
    
    do
    {
        sprintf(mod, "MODE %d, %d", x, y);
        system(mod);
        printf("x = %d  y = %d", x, y);
        a[0]=getch();
        a[1]='\0';
        if(a[0] != 'q' && a[0] != 'a' && a[0] != 'o' && a[0] != 'p')
            i=1;
        else
        {
            if(a[0] == 'p')
                x++;
            else
            if(a[0] == 'o')
            {
                x--;
                if(x < 14)
                    x=14;                    
            }  
            else
            if(a[0] == 'a')
                y++;
            else
            if(a[0] == 'q')
            {
                y--;
                if(y < 1)
                    y=1;
            }    
        }
    }while(i == 0);
    a[1]='\0';
    return 0;
}

Improvements welcome?
Was This Post Helpful? 0
  • +
  • -

#3 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1274
  • View blog
  • Posts: 4,393
  • Joined: 19-February 09

Re: Console Size

Posted 19 April 2013 - 06:53 PM

Does mode work? What are you trying to do?
Was This Post Helpful? 0
  • +
  • -

#4 lewm  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 160
  • Joined: 29-March 13

Re: Console Size

Posted 21 April 2013 - 05:09 AM

View Post#define, on 19 April 2013 - 06:53 PM, said:

Does mode work? What are you trying to do?

It does on wxDev, although I have been told this is not the way to do it. I have looked around for the best way but had no luck, I have looked on Microsoft website but still couldn't get it to work.
Was This Post Helpful? 0
  • +
  • -

#5 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3160
  • View blog
  • Posts: 9,529
  • Joined: 05-May 12

Re: Console Size

Posted 21 April 2013 - 12:58 PM

As I'd noted in the past, use SetConsoleWindowInfo() to change the console size on Windows.

This post has been edited by Skydiver: 21 April 2013 - 12:59 PM
Reason for edit:: Put in link.

Was This Post Helpful? 0
  • +
  • -

#6 lewm  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 160
  • Joined: 29-March 13

Re: Console Size

Posted 21 April 2013 - 01:39 PM

View PostSkydiver, on 21 April 2013 - 12:58 PM, said:

As I'd noted in the past, use SetConsoleWindowInfo() to change the console size on Windows.

once again thank you but I still cant get it to work, just cant get my head round it.
I will keep trying.
Was This Post Helpful? 0
  • +
  • -

#7 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3160
  • View blog
  • Posts: 9,529
  • Joined: 05-May 12

Re: Console Size

Posted 21 April 2013 - 01:59 PM

*sigh*

Here's a freebie sample. I only give one out once a month, and you got lucky. This code set the console to my favorite dimensions.
#include <Windows.h>
#include <iostream>

int main()
{
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD coordSize = { 120, 50 };
    int ret = SetConsoleScreenBufferSize(hConsole, coordSize);
    std::cout << ret << std::endl;
    SMALL_RECT rect = { 0, 0, 120-1, 50-1 };
    int ret2 = SetConsoleWindowInfo(hConsole, TRUE, &rect);
    std::cout << ret2 << std::endl;
    Sleep(5000);
    return 0;
}


Was This Post Helpful? 0
  • +
  • -

#8 lewm  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 160
  • Joined: 29-March 13

Re: Console Size

Posted 24 April 2013 - 07:33 AM

View PostSkydiver, on 21 April 2013 - 01:59 PM, said:

*sigh*

Here's a freebie sample. I only give one out once a month, and you got lucky. This code set the console to my favorite dimensions.
#include <Windows.h>
#include <iostream>

int main()
{
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD coordSize = { 120, 50 };
    int ret = SetConsoleScreenBufferSize(hConsole, coordSize);
    std::cout << ret << std::endl;
    SMALL_RECT rect = { 0, 0, 120-1, 50-1 };
    int ret2 = SetConsoleWindowInfo(hConsole, TRUE, &rect);
    std::cout << ret2 << std::endl;
    Sleep(5000);
    return 0;
}


Thanks that has helped loads, just need to convert it to c and not ++.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1