Thread: [Q]Dos in fullscreen

  1. #1
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133

    [Q]Win32 Console in fullscreen

    Hi.
    I have a (simple) question: is there a command or something that if you execute your program (*.exe file) that it opends it in full DOS screen, so that your cursor is some sort of little white block? So, a command that you can use in your source, that the program (if you execute it (by dubble clikking on it)) automaticly opens a fullscreen?
    Last edited by Yuri; 08-12-2005 at 06:27 AM.

  2. #2
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    not anything standard... and it's not a DOS screen - it's actually a Win32 Console. The difference is that DOS is a (mostly) dead operating system, whereas a console is another method of access the OS allows a user or program. what you're using could also be called an operating system shell

    one way you can do it: while you're program's running, go to options and choose fullscreen. there's also something in there that asks if you want to modify the source program. if you do so, every time you run the program, windows will give it a full-screen console.

    note that that only works on the system it was changed on.
    Last edited by major_small; 08-11-2005 at 09:24 AM. Reason: more.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  3. #3
    Banned
    Join Date
    Jun 2005
    Posts
    594
    i dont know how you could do it with source code,
    but you can do it by pressing Alt-Enter, give them the option
    to do that?

    that is assumming you mean the command prompt, because
    dos would be an operating system on its on and last time i
    seen dos it already took the full screen.

  4. #4
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133
    Yeah I mean the Win32 Console, I know how to choose the option fullscreen but I wanted to know how you can do it in the source, so that when you (compile and) run, that it automaticly opens in a fullscreen Win32 Console. So... is there a command for, just like... ehh... system("cls"); and then something like: system("ofs"); (open fullscreen, :P), thanks anyway.
    Last edited by Yuri; 08-11-2005 at 10:07 AM.

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Code:
    // Simulate ALT-ENTER keystrokes
    void AltEnter()
    {
        // NOTE: This method only works if the console window has the keyboard 
        //       focus and the user isn't hitting keys on the keyboard.
        SetForegroundWindow(GetConsoleWindow()); 
        keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), 0, 0); 
        keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), 0, 0); 
        keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), KEYEVENTF_KEYUP, 0); 
        keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), KEYEVENTF_KEYUP, 0); 
    }//AltEnter
    If you're running on an NT based verison of Windows, here is the best way to do it:
    Code:
    /*-----------------------------------------------------------------------------
    NT_SetConsoleDisplayMode - Set the console display to fullscreen or windowed.
    
    Parameters:
        hOutputHandle - Output handle of cosole, usually 
                            "GetStdHandle(STD_OUTPUT_HANDLE)"
        dwNewMode - 0=windowed, 1=fullscreen
    
    Returns Values: 
        TRUE if successful, otherwise FALSE is returned. Call GetLastError() for 
        extened information.
    
    Remarks:
        This only works on NT based versions of Windows.
    
        If dwNewMode is anything other than 0 or 1, FALSE is returned and 
        GetLastError() returns ERROR_INVALID_PARAMETER.
        
        If dwNewMode specfies the current mode, FALSE is returned and 
        GetLastError() returns ERROR_INVALID_PARAMETER. Use the (documented) 
        function GetConsoleDisplayMode() to determine the current display mode.
    -----------------------------------------------------------------------------*/
    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;
        }//if
    
        SetConsoleDisplayMode = 
            (SCDMProc_t)GetProcAddress(hKernel32, "SetConsoleDisplayMode");
        if (SetConsoleDisplayMode == NULL)
        {
            SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
            ret = FALSE;
        }//if
        else
        {
            DWORD dummy;
            ret = SetConsoleDisplayMode(hOutputHandle, dwNewMode, &dummy);
        }//else
            
        if (bFreeLib)
            FreeLibrary(hKernel32);
    
        return ret;
    }//NT_SetConsoleDisplayMode
    gg

  6. #6
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133
    if I use the first one it sais: 47 `GetConsoleWindow' undeclared (first use this function)
    and if I use the second above int main(); it doesn't do anything. Maybe I did something wrong, I don't know but thanks for trying.

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    For both you need to include <windows.h>.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #8
    Registered User
    Join Date
    Jul 2005
    Posts
    69
    This has been working ok for me on XP. Haven't tried backward compatability:
    Code:
    /* set screen mode, b == TRUE -> fullscreen, b == FALSE -> windowed */
    BOOL setScreenMode( BOOL b )
    {
    	COORD coord;
    	BOOL success = 0;
    	
    	HANDLE hConsole = GetStdHandle( STD_OUTPUT_HANDLE );
    	if(hConsole == NULL || hConsole == INVALID_HANDLE_VALUE )
    		return success;
    	
    	if(b)
    		success = SetConsoleDisplayMode( hConsole, CONSOLE_FULLSCREEN_MODE, &coord);
    	else
    		success = SetConsoleDisplayMode( hConsole, CONSOLE_WINDOWED_MODE, &coord);
    		
    	return success;
    }

  9. #9
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Scratch all that and get a DOS-based compiler if you really want DOS. I don't know why you would, but here is a link that will lead you to just that.

    Get DJGPP from here: www.delorie.com

  10. #10
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133
    1. Yes I had include <windows.h> and it still doesn't work.
    2. If I use Br5an's code above int main(); it sais In function `BOOL setScreenMode(BOOL)': `CONSOLE_FULLSCREEN_MODE' undeclared (first use this function)
    (Each undeclared identifier is reported only once for each function it appears in.)
    `SetConsoleDisplayMode' undeclared (first use this function)
    `CONSOLE_WINDOWED_MODE' undeclared (first use this function)

    Thanks for trying but I don't understand anything of it (why it doesn't work, etc.)
    3. I mean Win32 Console not DOS.
    It would be verry helpfull if someone could help me with my error's or something like that, till now on I don't get anything to work, please help me.

  11. #11
    Rabite SirCrono6's Avatar
    Join Date
    Nov 2003
    Location
    California, US
    Posts
    269
    Code:
    #include <windows.h>
    #include <iostream>
    
    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;
        }//if
    
        SetConsoleDisplayMode = 
            (SCDMProc_t)GetProcAddress(hKernel32, "SetConsoleDisplayMode");
        if (SetConsoleDisplayMode == NULL)
        {
            SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
            ret = FALSE;
        }//if
        else
        {
            DWORD dummy;
            ret = SetConsoleDisplayMode(hOutputHandle, dwNewMode, &dummy);
        }//else
            
        if (bFreeLib)
            FreeLibrary(hKernel32);
    
        return ret;
    }//NT_SetConsoleDisplayMode
    
    int main( void )
    {
      NT_SetConsoleDisplayMode( GetStdHandle( STD_OUTPUT_HANDLE ), 1 );
      std::cin.get();
      return 0;
    }
    Did you pass those parameters? If so, you're probably not running an NT based version of Windows.

    I don't know where those functions Br5an uses are, neither where GetConsoleWindow(); is

    However, you can delete GetConsoleWindow, but it just won't work if they don't have the window in focus.

    I know I'm mostly just repeating other people, but it seems you didn't hear it

    - SirCrono6
    From C to shining C++!

    Great graphics, sounds, algorithms, AI, pathfinding, visual effects, cutscenes, etc., etc. do NOT make a good game.
    - Bubba

    IDE and Compiler - Code::Blocks with MinGW
    Operating System - Windows XP Professional x64 Edition

  12. #12
    Registered User
    Join Date
    Jul 2005
    Posts
    69
    Just a follow up with example, please pardon that I didn't change printf's to cout, ect... The problem is probably with _WIN32_WINNT, I put a little comment in the code. Works with DevC++ 4.9.9.2 (MinGW compiler) on XP for sure.

    Edit: _WIN32_WINNT 0x0501 should also work. I noticed after looking in wincon.h

    Code:
    #include <stdio.h>
    
    /* Must be running a 'new' enough version of Windows or it's not
       going to work. How 'new' 0x0502 is I don't know off hand. */
    #ifndef _WIN32_WINNT
    #define _WIN32_WINNT 0x0502
    #endif
    
    #include <windows.h>
    
    #define FULL_SCREEN TRUE
    #define WINDOWED FALSE
    
    /* set screen mode, b == TRUE -> fullscreen, b == FALSE -> windowed */
    BOOL setScreenMode( BOOL b )
    {
    	COORD coord;
    	BOOL success = 0;
    	
    	HANDLE hConsole = GetStdHandle( STD_OUTPUT_HANDLE );
    	if(hConsole == NULL || hConsole == INVALID_HANDLE_VALUE )
    		return success;
    	
    	if(b)
    		success = SetConsoleDisplayMode( hConsole, CONSOLE_FULLSCREEN_MODE, &coord);
    	else
    		success = SetConsoleDisplayMode( hConsole, CONSOLE_WINDOWED_MODE, &coord);
    		
    	return success;
    }
    
    int main( )
    {
    	BOOL mode;
    	mode = setScreenMode( FULL_SCREEN );
    	if(mode)
    		printf("Full screen mode set");
    	else
    		printf("Full screen mode failed");
    		
    	getchar( );
    		
    	mode = setScreenMode( WINDOWED );
    	if(mode)
    		printf("Windowed screen mode set");
    	else
    		printf("Windowed screen mode failed");
    		
    	getchar( );
    	
    	return(0);
    }
    Last edited by Br5an; 08-13-2005 at 12:59 AM.

  13. #13
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133
    Cool it works. There is only one problem, this is for C not C++. Really thanks for your help, it's awesome only to bad that it's not for C++.

    Edit

    Ow, sorry I noticed that the one under my previus post also worked and for C++, Thanks dude!

    Edit

    Hehe, nevermind I got them both to work now in C++. Hehe . Thanks.
    Last edited by Yuri; 08-13-2005 at 01:27 PM.

  14. #14
    Registered User
    Join Date
    Aug 2005
    Posts
    1
    Quote Originally Posted by Br5an
    Just a follow up with example, please pardon that I didn't change printf's to cout, ect... The problem is probably with _WIN32_WINNT, I put a little comment in the code. Works with DevC++ 4.9.9.2 (MinGW compiler) on XP for sure.

    Edit: _WIN32_WINNT 0x0501 should also work. I noticed after looking in wincon.h

    Code:
    #include <stdio.h>
    
    /* Must be running a 'new' enough version of Windows or it's not
       going to work. How 'new' 0x0502 is I don't know off hand. */
    #ifndef _WIN32_WINNT
    #define _WIN32_WINNT 0x0502
    #endif
    
    #include <windows.h>
    
    #define FULL_SCREEN TRUE
    #define WINDOWED FALSE
    
    /* set screen mode, b == TRUE -> fullscreen, b == FALSE -> windowed */
    BOOL setScreenMode( BOOL b )
    {
    	COORD coord;
    	BOOL success = 0;
    	
    	HANDLE hConsole = GetStdHandle( STD_OUTPUT_HANDLE );
    	if(hConsole == NULL || hConsole == INVALID_HANDLE_VALUE )
    		return success;
    	
    	if(b)
    		success = SetConsoleDisplayMode( hConsole, CONSOLE_FULLSCREEN_MODE, &coord);
    	else
    		success = SetConsoleDisplayMode( hConsole, CONSOLE_WINDOWED_MODE, &coord);
    		
    	return success;
    }
    
    int main( )
    {
    	BOOL mode;
    	mode = setScreenMode( FULL_SCREEN );
    	if(mode)
    		printf("Full screen mode set");
    	else
    		printf("Full screen mode failed");
    		
    	getchar( );
    		
    	mode = setScreenMode( WINDOWED );
    	if(mode)
    		printf("Windowed screen mode set");
    	else
    		printf("Windowed screen mode failed");
    		
    	getchar( );
    	
    	return(0);
    }
    _WIN32_NT 0x502 means Windows Server 2003. _WIN_NT 0x501 means Windows XP. This code can also be run on _WIN32_NT 0x500 (Windows 2000. MSDN tries to screw you up by saying SetConsoleDisplayMode won't work there. It just needs some defining). However, one thing I don't get is that _WIN32_NT not defined thing. In all systems I have compiled things I get _WIN32 defined but not _WIN32_WINDOWS or _WIN32_NT. Anyway, here's what it needs to work with systems >= Windows 2000.
    Code:
    #include <stdio.h>
    
    #ifndef _WIN32_NT
    #define _WIN32_NT 0x500
    #endif
    
    #include <windows.h>
    
    typedef BOOL (WINAPI *SetConsoleDisplayModeProc) (HANDLE, DWORD, PCOORD);
    HMODULE dll = LoadLibrary("kernel32.dll");
    SetConsoleDisplayModeProc SetConsoleDisplayMode = (SetConsoleDisplayModeProc)GetProcAddress(dll, "SetConsoleDisplayMode");
    
    #define FULL_SCREEN TRUE
    #define WINDOWED FALSE
    After that it's like in the example. Works perfectly on my Windows 2000. Btw, I was using MSVC++ toolkit 2003 with SDK, just for the record. I don't have WINAPI installed on my mingw.
    ps. The function declarations are not made up by me. If the original writer ever bothers coming here, feel free to get the credit.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  2. This is how to get your program to run fullscreen (console)
    By Raigne in forum Windows Programming
    Replies: 11
    Last Post: 11-25-2005, 08:26 AM
  3. Going to fullscreen with DEVMODE
    By Da-Nuka in forum Windows Programming
    Replies: 2
    Last Post: 06-15-2005, 08:13 AM
  4. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 10:50 AM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM