Full Screen Console

This is a discussion on Full Screen Console within the C++ Programming forums, part of the General Programming Boards category; Ok I have this code... Code: #include <windows.h> #include <stdio.h> #include <conio.h> // prototypes BOOL FullScreenConsole9x(void); BOOL FullScreenConsoleNT(void); // --------------------------------------------------------------------------- ...

  1. #1
    using namespace Trooper; St0rmTroop3er's Avatar
    Join Date
    Sep 2003
    Posts
    77

    Full Screen Console

    Ok I have this code...

    Code:
    #include <windows.h>
    #include <stdio.h>
    #include <conio.h>
    
    
    // prototypes
    BOOL FullScreenConsole9x(void);
    BOOL FullScreenConsoleNT(void);
    
    // ---------------------------------------------------------------------------
    BOOL FullScreenConsole9x(void)
    {
        BOOL ok = FALSE;
    
    	// console finding guid
    	// a unique number to identify this console - replace this with your own
    	#define CON_GUID TEXT("CON_GUID-{68E311EF-BF32-4b0f-8D35-E84E4A463096}")
    
    	// hwnd for console window
    	HWND hConWnd = NULL;
    
        // magic command
        WPARAM magic = 57359;
    
    	// buffer for storing a substitute title
    	TCHAR szTempTitle[] = CON_GUID;
    
    	// buffer for storing current console title
    	TCHAR szTempString[MAX_PATH];
    
    	// obtain the current console title
    	if( GetConsoleTitle(szTempString, sizeof(szTempString)/sizeof(TCHAR) ) )
    	{
    		// replace the current title with substitute title
    		SetConsoleTitle(szTempTitle);
    
    		// give it a chance to set in
    		Sleep(50);
    
    		// locate the console window
    
    		// console window class on W9x is "tty"
    		hConWnd = FindWindow(TEXT("tty"), szTempTitle);
    
    		// restore the original console title
    		SetConsoleTitle(szTempString);
    
    	}
    
    	// verify the console hwnd
    	if ( hConWnd != NULL ) {
    
    	    // pause before changing to fullscreen
        	Sleep(450);
    
            // this method works by faking a keyboard command
            SendMessage(hConWnd,WM_COMMAND,magic,0);
    
            ok = TRUE;
    
    	}
    
        return ok;
    
    }
    
    // ---------------------------------------------------------------------------
    BOOL FullScreenConsoleNT(void)
    {
        // typedef function pointer for undocumented API
        typedef BOOL WINAPI (*SetConsoleDisplayModeT)(HANDLE,DWORD,DWORD*);
    
        // declare one such function pointer
        SetConsoleDisplayModeT SetConsoleDisplayMode;
    
    	// load kernel32.dll
    	HINSTANCE hLib = LoadLibrary("KERNEL32.DLL");
        if ( hLib == NULL ) {
            // highly unlikely but good practice just the same
            return FALSE;
        }
    
    	// assign procedure address to function pointer
    	SetConsoleDisplayMode = ( SetConsoleDisplayModeT )
    		GetProcAddress(hLib,"SetConsoleDisplayMode");
    
    	// check if the function pointer is valid
        // since the function is undocumented
    	if ( SetConsoleDisplayMode == NULL ) {
            // play nice with windows
    	    FreeLibrary(hLib);
    		return FALSE;
    	}
    
    	DWORD newmode = 1;	// fullscreen mode
    	DWORD oldmode;
    
    	// get handle to stdout
    	HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
    
    	// pause before changing to fullscreen
    	Sleep(500);
    
    	// set full screen mode
    	SetConsoleDisplayMode(hStdOut,newmode,&oldmode);
    
        // play nice with windows
    	FreeLibrary(hLib);
    
        return TRUE;
    
    }
    
    // ---------------------------------------------------------------------------
    int main(void)
    {
    
        OSVERSIONINFO VerInfo;
        ZeroMemory(&VerInfo,sizeof(VerInfo));
        VerInfo.dwOSVersionInfoSize = sizeof(VerInfo);
        GetVersionEx(&VerInfo);
    
    	// Why a switch? because I felt like switching... har har
        switch ( VerInfo.dwPlatformId ) {
    
    		case VER_PLATFORM_WIN32_NT :
            	FullScreenConsoleNT();
    			break;
    
    		case VER_PLATFORM_WIN32_WINDOWS	:
            	FullScreenConsole9x();
    			break;
    
    		default:
    			break;
    
        }
    
    	// issue a report
    	printf("This is a test.\nHit enter to exit");
    
    	// wait for keyboard hit
    	getch();
    
        return 0;
    
    }
    I found on a Here. Now, when I try to compile the code in VC++6 I get errors, but when I compile in Dev-c++ it works perfectly, any ideas why?

    Here are the errors for VC++6:
    --------------------Configuration: fullscreenconsole - Win32 Debug--------------------
    Compiling...
    fullscreenconsole.c
    c:\documents and settings\rcapote\local settings\temp\rar$dr03.922\fullscreenconsole.c(71) : error C2059: syntax error : '('
    c:\documents and settings\rcapote\local settings\temp\rar$dr03.922\fullscreenconsole.c(74) : error C2065: 'SetConsoleDisplayModeT' : undeclared identifier
    c:\documents and settings\rcapote\local settings\temp\rar$dr03.922\fullscreenconsole.c(74) : error C2146: syntax error : missing ';' before identifier 'SetConsoleDisplayMode'
    c:\documents and settings\rcapote\local settings\temp\rar$dr03.922\fullscreenconsole.c(74) : error C2065: 'SetConsoleDisplayMode' : undeclared identifier
    c:\documents and settings\rcapote\local settings\temp\rar$dr03.922\fullscreenconsole.c(77) : error C2275: 'HINSTANCE' : illegal use of this type as an expression
    c:\program files\microsoft visual studio\vc98\include\windef.h(252) : see declaration of 'HINSTANCE'
    c:\documents and settings\rcapote\local settings\temp\rar$dr03.922\fullscreenconsole.c(77) : error C2146: syntax error : missing ';' before identifier 'hLib'
    c:\documents and settings\rcapote\local settings\temp\rar$dr03.922\fullscreenconsole.c(77) : error C2065: 'hLib' : undeclared identifier
    c:\documents and settings\rcapote\local settings\temp\rar$dr03.922\fullscreenconsole.c(77) : warning C4047: '=' : 'int ' differs in levels of indirection from 'struct HINSTANCE__ *'
    c:\documents and settings\rcapote\local settings\temp\rar$dr03.922\fullscreenconsole.c(78) : warning C4047: '==' : 'int ' differs in levels of indirection from 'void *'
    c:\documents and settings\rcapote\local settings\temp\rar$dr03.922\fullscreenconsole.c(85) : error C2146: syntax error : missing ';' before identifier 'GetProcAddress'
    c:\documents and settings\rcapote\local settings\temp\rar$dr03.922\fullscreenconsole.c(85) : warning C4047: 'function' : 'struct HINSTANCE__ *' differs in levels of indirection from 'int '
    c:\documents and settings\rcapote\local settings\temp\rar$dr03.922\fullscreenconsole.c(85) : warning C4024: 'GetProcAddress' : different types for formal and actual parameter 1
    c:\documents and settings\rcapote\local settings\temp\rar$dr03.922\fullscreenconsole.c(89) : warning C4047: '==' : 'int ' differs in levels of indirection from 'void *'
    c:\documents and settings\rcapote\local settings\temp\rar$dr03.922\fullscreenconsole.c(91) : warning C4047: 'function' : 'struct HINSTANCE__ *' differs in levels of indirection from 'int '
    c:\documents and settings\rcapote\local settings\temp\rar$dr03.922\fullscreenconsole.c(91) : warning C4024: 'FreeLibrary' : different types for formal and actual parameter 1
    c:\documents and settings\rcapote\local settings\temp\rar$dr03.922\fullscreenconsole.c(95) : error C2275: 'DWORD' : illegal use of this type as an expression
    c:\program files\microsoft visual studio\vc98\include\windef.h(141) : see declaration of 'DWORD'
    c:\documents and settings\rcapote\local settings\temp\rar$dr03.922\fullscreenconsole.c(95) : error C2146: syntax error : missing ';' before identifier 'newmode'
    c:\documents and settings\rcapote\local settings\temp\rar$dr03.922\fullscreenconsole.c(95) : error C2065: 'newmode' : undeclared identifier
    c:\documents and settings\rcapote\local settings\temp\rar$dr03.922\fullscreenconsole.c(96) : error C2275: 'DWORD' : illegal use of this type as an expression
    c:\program files\microsoft visual studio\vc98\include\windef.h(141) : see declaration of 'DWORD'
    c:\documents and settings\rcapote\local settings\temp\rar$dr03.922\fullscreenconsole.c(96) : error C2146: syntax error : missing ';' before identifier 'oldmode'
    c:\documents and settings\rcapote\local settings\temp\rar$dr03.922\fullscreenconsole.c(96) : error C2065: 'oldmode' : undeclared identifier
    c:\documents and settings\rcapote\local settings\temp\rar$dr03.922\fullscreenconsole.c(99) : error C2275: 'HANDLE' : illegal use of this type as an expression
    c:\program files\microsoft visual studio\vc98\include\winnt.h(207) : see declaration of 'HANDLE'
    c:\documents and settings\rcapote\local settings\temp\rar$dr03.922\fullscreenconsole.c(99) : error C2146: syntax error : missing ';' before identifier 'hStdOut'
    c:\documents and settings\rcapote\local settings\temp\rar$dr03.922\fullscreenconsole.c(99) : error C2065: 'hStdOut' : undeclared identifier
    c:\documents and settings\rcapote\local settings\temp\rar$dr03.922\fullscreenconsole.c(99) : warning C4047: '=' : 'int ' differs in levels of indirection from 'void *'
    c:\documents and settings\rcapote\local settings\temp\rar$dr03.922\fullscreenconsole.c(105 ) : error C2063: 'SetConsoleDisplayMode' : not a function
    c:\documents and settings\rcapote\local settings\temp\rar$dr03.922\fullscreenconsole.c(108 ) : warning C4047: 'function' : 'struct HINSTANCE__ *' differs in levels of indirection from 'int '
    c:\documents and settings\rcapote\local settings\temp\rar$dr03.922\fullscreenconsole.c(108 ) : warning C4024: 'FreeLibrary' : different types for formal and actual parameter 1
    Error executing cl.exe.

    fullscreenconsole.exe - 18 error(s), 10 warning(s)

  2. #2
    Registered User
    Join Date
    Nov 2004
    Posts
    69
    I think its because your compiler (Visual Studio) is detecting it as a C project and not C++ hence the ".c" extension.

    I may be wrong, but that's a REALLY bad habit of making it .c instead of .cpp for a C++ project.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Detecting Full Screen Mode
    By ldd7812 in forum Windows Programming
    Replies: 2
    Last Post: 05-29-2008, 10:36 PM
  2. console screen (Windows)
    By hakan in forum C++ Programming
    Replies: 1
    Last Post: 03-12-2008, 06:35 AM
  3. Taking Screenshot - Full Screen Dos
    By loko in forum C Programming
    Replies: 12
    Last Post: 07-16-2005, 01:23 AM
  4. Maximizing a Console Window Full Screen
    By philvaira in forum Windows Programming
    Replies: 10
    Last Post: 08-13-2004, 02:27 AM
  5. Running in full screen mode!
    By Skute in forum Game Programming
    Replies: 0
    Last Post: 12-10-2001, 02:56 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21