Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,878 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,316 people online right now. Registration is fast and FREE... Join Now!




Make Console Full Screen?

 
Reply to this topicStart new topic

Make Console Full Screen?, How Can I make my console full screen?

irsmart
14 Jan, 2007 - 04:02 PM
Post #1

New D.I.C Head
*

Joined: 29 Sep, 2006
Posts: 3


My Contributions
I am a very beginning programmer and I was wondering if I could make the console full screen. I searched on Google, but I couldn't find anything. I know that you can press Alt + Enter and it will do it, but is there anything I can embed into the code? I remember using a system command somewhere:
CODE
system("command");
, but I don't remember how to do it. If you know anything that can help... thanks!

User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Make Console Full Screen?
14 Jan, 2007 - 06:04 PM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,351



Thanked: 51 times
Dream Kudos: 25
My Contributions
What operating system are you using?
User is online!Profile CardPM
+Quote Post

jstephens
RE: Make Console Full Screen?
14 Jan, 2007 - 07:09 PM
Post #3

D.I.C Head
**

Joined: 7 Nov, 2005
Posts: 192



Thanked: 1 times
My Contributions
He is more than likely using windows as that is a windows key to expand the command prompt to take up the full screen.
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Make Console Full Screen?
14 Jan, 2007 - 07:15 PM
Post #4

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,351



Thanked: 51 times
Dream Kudos: 25
My Contributions
I agree, but making assumptions is one of the biggest cause of errors in programming, so I try to ensure that solutions provided are in fact the solutions required.
User is online!Profile CardPM
+Quote Post

irsmart
RE: Make Console Full Screen?
14 Jan, 2007 - 09:22 PM
Post #5

New D.I.C Head
*

Joined: 29 Sep, 2006
Posts: 3


My Contributions
I'm using Windows XP (to be exact). I don't need to worry about this being able to work on other operating systems because I am the only one who would use it.

Thanks.
User is offlineProfile CardPM
+Quote Post

born2c0de
RE: Make Console Full Screen?
14 Jan, 2007 - 11:31 PM
Post #6

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 4,029



Thanked: 38 times
Dream Kudos: 2800
Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
Use the SetConsoleWindowInfo API along with the GetLargestConsoleWindowSize API Function.

You can also use the SetConsoleDisplayMode() API Function or Simulate KeyStrokes using keybd_event() or SendInput().
User is offlineProfile CardPM
+Quote Post

jmtboz
RE: Make Console Full Screen?
2 Mar, 2007 - 03:20 PM
Post #7

New D.I.C Head
*

Joined: 2 Mar, 2007
Posts: 7


My Contributions
QUOTE(born2c0de @ 15 Jan, 2007 - 12:31 AM) *

Use the SetConsoleWindowInfo API along with the GetLargestConsoleWindowSize API Function.

You can also use the SetConsoleDisplayMode() API Function or Simulate KeyStrokes using keybd_event() or SendInput().


born2c0de,

This is my first time asking a question, so go easy on me...

I have a similar problem manipulating the console size; I actually found several references to the msdn website, but I don't understand how to implement setConsoleWidowInfo API

I've included windows.h but C++ still has a problem with the setConsoleWidth line.

-Jeremy
User is offlineProfile CardPM
+Quote Post

born2c0de
RE: Make Console Full Screen?
2 Mar, 2007 - 10:42 PM
Post #8

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 4,029



Thanked: 38 times
Dream Kudos: 2800
Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
QUOTE
This is my first time asking a question, so go easy on me...

Am I really that rude?

You can use two techniques to set the console in fullscreen mode.
  • SetConsoleDisplayMode
  • Simulating the Alt+Enter KeyStrokes (using SendInput() or keybd_event()

I've provided the code for both these methods.
Which compiler are you using?
I'm not sure if Dev C++ supports this, although Borland,VC++ and others do.

MSDN Recommends usage of SendInput rather than keybd_event.
But I'm not sure how it can be done using SendInput, so i've implemented it using the latter.

Here's the code.
CODE

#include <windows.h>
#include <conio.h>
#include <iostream.h>

void AltEnter()
{
    keybd_event(VK_MENU,0x38,0,0);
    keybd_event(VK_RETURN,0x1c,0,0);
    keybd_event(VK_RETURN,0x1c,KEYEVENTF_KEYUP,0);
    keybd_event(VK_MENU,0x38,KEYEVENTF_KEYUP,0);
}

BOOL NT_SetConsoleDisplayMode(HANDLE hOutputHandle, DWORD dwNewMode)
{
    typedef BOOL (WINAPI *SCDMProc_t) (HANDLE, DWORD, LPDWORD);
    SCDMProc_t SetConsoleDisplayMode;
    HMODULE hKernel32;
    BOOL bFreeLib = FALSE, ret;
    const char KERNEL32_NAME[] = "kernel32.dll";

    hKernel32 = GetModuleHandleA(KERNEL32_NAME);
    if (hKernel32 == NULL)
    {
        hKernel32 = LoadLibraryA(KERNEL32_NAME);
        if (hKernel32 == NULL)
            return FALSE;

        bFreeLib = true;
    }

    SetConsoleDisplayMode =
        (SCDMProc_t)GetProcAddress(hKernel32, "SetConsoleDisplayMode");
    if (SetConsoleDisplayMode == NULL)
    {
        SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
        ret = FALSE;
    }
    else
    {
        DWORD tmp;
        ret = SetConsoleDisplayMode(hOutputHandle, dwNewMode, &tmp);
    }

    if (bFreeLib)
        FreeLibrary(hKernel32);

    return ret;
}

int main( void )
{
  int x;
  cout<<"1) Using SetConsoleDisplayMode  (Press Return)\n";
  NT_SetConsoleDisplayMode( GetStdHandle( STD_OUTPUT_HANDLE ), 1 );
  getch();
  NT_SetConsoleDisplayMode( GetStdHandle( STD_OUTPUT_HANDLE ), 0 );
  cout<<"2) Simulating Alt+Enter KeyStrokes  (Press Return)\n";
  getch();
AltEnter();
  getch();
  return 0;
}

User is offlineProfile CardPM
+Quote Post

razvan1024
RE: Make Console Full Screen?
15 Mar, 2008 - 02:54 PM
Post #9

New D.I.C Head
*

Joined: 15 Mar, 2008
Posts: 1

I have a problem with a full screen console application. I'm using the SetConsoleDisplayMode to make my console full screen. I write data to my console using a console buffer. I set the buffer to display a character on the console but it only displays on the left side of the console. Can someone help me, pls? My console is 80 chars wide and 40 chars in height.
User is offlineProfile CardPM
+Quote Post

born2c0de
RE: Make Console Full Screen?
16 Mar, 2008 - 05:28 AM
Post #10

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 4,029



Thanked: 38 times
Dream Kudos: 2800
Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
Could you post your code as well?
It's rather difficult to track errors without the code.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 11:51AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month