Console Font Size

This is a discussion on Console Font Size within the Windows Programming forums, part of the Platform Specific Boards category; Using CodePlugs code, here: Code: #define _WIN32_WINNT 0x0500 #include <iostream> #include <string> #include <windows.h> using namespace std; //------------------------------------------------------------------------------ struct CONSOLE_FONT ...

  1. #16
    Registered User bradszy's Avatar
    Join Date
    Jan 2008
    Posts
    114
    Using CodePlugs code, here:

    Code:
    #define _WIN32_WINNT 0x0500
    #include <iostream>
    #include <string>
    #include <windows.h>
    using namespace std;
    
    //------------------------------------------------------------------------------
    
    struct CONSOLE_FONT
    {
        DWORD index;
        COORD dim;
    };//CONSOLE_FONT
    
    BOOL (WINAPI *SetConsoleFont)(HANDLE, DWORD);
    BOOL (WINAPI *GetConsoleFontInfo)(HANDLE, BOOL, DWORD, CONSOLE_FONT*);
    DWORD (WINAPI *GetNumberOfConsoleFonts)();
    
    //------------------------------------------------------------------------------
    
    template<typename pfn_t>
    inline bool LoadFunc(HMODULE hmod, const char *name, pfn_t &fn)
    {
        fn = (pfn_t)GetProcAddress(hmod, name);
        return fn != 0;
    }//LoadFunc
    
    //------------------------------------------------------------------------------
    
    
    
    int main()
    {
        
        
        
        
        
        
        
        
        
        
        
        
        char title[MAX_PATH];
        HWND hwnd;
    
        if (!::GetConsoleTitleA(title, sizeof(title)) || 
            !(hwnd = ::FindWindowA(0, title)))
        {
            cerr << "Failed to find console window" << endl;
            return 1;
        }//else
    
        // Undocumented API's
        HMODULE hmod = ::GetModuleHandleA("KERNEL32.DLL");
        if (!hmod || 
            !LoadFunc(hmod, "SetConsoleFont", SetConsoleFont) ||
            !LoadFunc(hmod, "GetConsoleFontInfo", GetConsoleFontInfo) ||
            !LoadFunc(hmod, "GetNumberOfConsoleFonts", GetNumberOfConsoleFonts))
        {
            cerr << "Failed to load API(s): " << ::GetLastError() << endl;
            return 1;
        }//if
    
        HANDLE hOut = ::GetStdHandle(STD_OUTPUT_HANDLE);
    
        // number of console fonts
        const DWORD MAX_FONTS = 40;
        DWORD num_fonts = GetNumberOfConsoleFonts();
        if (num_fonts > MAX_FONTS)
            num_fonts = MAX_FONTS;
    
        CONSOLE_FONT fonts[MAX_FONTS] = {0};
        GetConsoleFontInfo(hOut, 0, num_fonts, fonts);
    
        for (DWORD n = 0; n < num_fonts; ++n)
        {
            fonts[n].dim = GetConsoleFontSize(hOut, fonts[n].index);
    
            if (fonts[n].dim.X == 6 && 
                fonts[n].dim.Y == 8)
            {
                SetConsoleFont(hOut, fonts[n].index);
                ::InvalidateRect(hwnd, 0, FALSE);
                ::UpdateWindow(hwnd);
        
    
    char CM[9999];
    char PAATH[9999];
    system("color 0e");
    ::GetCurrentDirectory(50,PAATH);
    while (1)
    {
          cout<<"______________________________________________________________________________"<<endl;
          cout<<endl<<PAATH<<"> ";
          cin.getline(CM, 9999);
          cout<<endl;
          if (!stricmp(CM, "close"))
    {
                           return 0;
    }
          
          if (!stricmp(CM, "exit"))
    {
                           return 0;
    }
          
          
    
          if ( !stricmp(CM, "thanks"))
    {
             cout<<endl<<"You're welcome"<<endl;
             goto LULZ;
    }
    
          if (!stricmp(CM, "cd"))
    {
                           cout<<endl<<"Path: ";
                           cin.getline(PAATH, 9999);
                           cout<<endl;
                           ::SetCurrentDirectory(PAATH);
                           cout<<"Path Changed to: "<<PAATH<<endl;
                           goto LULZ;
    }
    
    
          
          
          
          else
    {
          system(CM);
    }
          LULZ:;
          
    } 
          return 0;
    }
    }
    }
    I get
    Code:
    80 C:\Users\bradszy\Desktop\Test.cpp `GetConsoleFontSize' undeclared (first use this function)
    This is in Dev-C++ btw. I don't like VC++.
    OS: Windows XP Home Edition SP3, Windows 7 Ultimate Beta Build 7000
    LANGUAGES: C++, VB6
    SKILL: Novice/Intermediate

  2. #17
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    perhaps the windows.h that you get with gcc-mingw doesn't have that function? You should be able to produce a prototype for it by copying from the MSDN WebSite if you are really desperate.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #18
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    sometimes MSDN prototypes have incorrect calling conventions...

    For calling functions it is not important info, but for manual prototyping the WinAPI functions - it is essential
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #19
    Registered User bradszy's Avatar
    Join Date
    Jan 2008
    Posts
    114
    So what do I do?
    I'm kind of stuck...
    OS: Windows XP Home Edition SP3, Windows 7 Ultimate Beta Build 7000
    LANGUAGES: C++, VB6
    SKILL: Novice/Intermediate

  5. #20
    Registered User
    Join Date
    Nov 2005
    Posts
    673
    If your programming windows, why don't you get VC++ express?

  6. #21
    Registered User bradszy's Avatar
    Join Date
    Jan 2008
    Posts
    114
    Because VC++ gives me SIX errors using that code that I posted, instead of 1.

    Build Log:
    Build Log Build started: Project: CMDTEST, Configuration: Debug|Win32
    Command Lines Creating temporary file "c:\Users\bradszy\Documents\Visual Studio 2008\Projects\CMDTEST\CMDTEST\Debug\RSP00000134165 972.rsp" with contents
    [
    /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /MDd /Fo"Debug\\" /Fd"Debug\vc90.pdb" /W3 /c /ZI /TP ".\CMDTEST.cpp"
    ]
    Creating command line "cl.exe @"c:\Users\bradszy\Documents\Visual Studio 2008\Projects\CMDTEST\CMDTEST\Debug\RSP00000134165 972.rsp" /nologo /errorReportrompt"
    Output Window Compiling...
    CMDTEST.cpp
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(154) : warning C4005: 'DM_BITSPERPEL' : macro redefinition
    c:\program files\microsoft sdks\windows\v6.0a\include\wingdi.h(2165) : see previous definition of 'DM_BITSPERPEL'
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(155) : warning C4005: 'DM_PELSWIDTH' : macro redefinition
    c:\program files\microsoft sdks\windows\v6.0a\include\wingdi.h(2166) : see previous definition of 'DM_PELSWIDTH'
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(156) : warning C4005: 'DM_PELSHEIGHT' : macro redefinition
    c:\program files\microsoft sdks\windows\v6.0a\include\wingdi.h(2167) : see previous definition of 'DM_PELSHEIGHT'
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(157) : warning C4005: 'DM_DISPLAYFLAGS' : macro redefinition
    c:\program files\microsoft sdks\windows\v6.0a\include\wingdi.h(2168) : see previous definition of 'DM_DISPLAYFLAGS'
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(158) : warning C4005: 'DM_DISPLAYFREQUENCY' : macro redefinition
    c:\program files\microsoft sdks\windows\v6.0a\include\wingdi.h(2169) : see previous definition of 'DM_DISPLAYFREQUENCY'
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(2370) : error C2011: 'HHOOK__' : 'struct' type redefinition
    c:\program files\microsoft sdks\windows\v6.0a\include\windef.h(209) : see declaration of 'HHOOK__'
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(3115) : error C2143: syntax error : missing ';' before ''
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(3115) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(3305) : error C2061: syntax error : identifier 'PCVOID'
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(3435) : warning C4273: 'FrameRgn' : inconsistent dll linkage
    c:\program files\microsoft sdks\windows\v6.0a\include\wingdi.h(3175) : see previous definition of 'FrameRgn'
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(3560) : warning C4273: 'GetWindowExtEx' : inconsistent dll linkage
    c:\program files\microsoft sdks\windows\v6.0a\include\wingdi.h(3644) : see previous definition of 'GetWindowExtEx'
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(3891) : warning C4273: 'WinExec' : inconsistent dll linkage
    c:\program files\microsoft sdks\windows\v6.0a\include\winbase.h(4675) : see previous definition of 'WinExec'
    c:\program files\microsoft sdks\windows\v6.0a\include\imm.h(408) : warning C4005: 'MOD_ALT' : macro redefinition
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(2135) : see previous definition of 'MOD_ALT'
    c:\program files\microsoft sdks\windows\v6.0a\include\imm.h(409) : warning C4005: 'MOD_CONTROL' : macro redefinition
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(2136) : see previous definition of 'MOD_CONTROL'
    c:\program files\microsoft sdks\windows\v6.0a\include\imm.h(410) : warning C4005: 'MOD_SHIFT' : macro redefinition
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(2137) : see previous definition of 'MOD_SHIFT'
    c:\program files\microsoft sdks\windows\v6.0a\include\imm.h(412) : warning C4005: 'MOD_LEFT' : macro redefinition
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(2142) : see previous definition of 'MOD_LEFT'
    c:\program files\microsoft sdks\windows\v6.0a\include\imm.h(413) : warning C4005: 'MOD_RIGHT' : macro redefinition
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(2141) : see previous definition of 'MOD_RIGHT'
    c:\program files\microsoft sdks\windows\v6.0a\include\imm.h(415) : warning C4005: 'MOD_ON_KEYUP' : macro redefinition
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(2140) : see previous definition of 'MOD_ON_KEYUP'
    c:\program files\microsoft sdks\windows\v6.0a\include\imm.h(416) : warning C4005: 'MOD_IGNORE_ALL_MODIFIER' : macro redefinition
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(2139) : see previous definition of 'MOD_IGNORE_ALL_MODIFIER'
    c:\users\bradszy\documents\visual studio 2008\projects\cmdtest\cmdtest\cmdtest.cpp(93) : error C2664: 'GetCurrentDirectoryW' : cannot convert parameter 2 from 'char [9999]' to 'LPWSTR'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    c:\users\bradszy\documents\visual studio 2008\projects\cmdtest\cmdtest\cmdtest.cpp(123) : error C2664: 'SetCurrentDirectoryW' : cannot convert parameter 1 from 'char [9999]' to 'LPCWSTR'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    Results Build log was saved at "file://c:\Users\bradszy\Documents\Visual Studio 2008\Projects\CMDTEST\CMDTEST\Debug\BuildLog.htm"
    CMDTEST - 6 error(s), 15 warning(s)
    OS: Windows XP Home Edition SP3, Windows 7 Ultimate Beta Build 7000
    LANGUAGES: C++, VB6
    SKILL: Novice/Intermediate

  7. #22
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    'SetCurrentDirectoryW' : cannot convert parameter 1 from 'char [9999]' to 'LPCWSTR'
    You are compiling UNICODE version while using ANSI version of strings

    make it consistent - for example disable UNICOCDE support in the project settings
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  8. #23
    Registered User
    Join Date
    Nov 2005
    Posts
    673
    so your getting errors with a windows header on a window compiler. That one is kinda odd to me.

  9. #24
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    or just use GetCurrentDirectoryA instead of GetCurrentDirectory
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  10. #25
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    Quote Originally Posted by Raigne View Post
    so your getting errors with a windows header on a window compiler. That one is kinda odd to me.
    Probably - wrong order of header files...
    For example this simplified part of the code compiles without warning on VS2008 Express
    Code:
    #include <windows.h>
    #include <iostream>
    #include <string>
    #include <vector>
    
    struct CONSOLE_FONT
    {
    	DWORD index;
    	COORD dim;
    };//CONSOLE_FONT
    BOOL (WINAPI *SetConsoleFont)(HANDLE, DWORD);
    BOOL (WINAPI *GetConsoleFontInfo)(HANDLE, BOOL, DWORD, CONSOLE_FONT*);
    DWORD (WINAPI *GetNumberOfConsoleFonts)();
    
    //------------------------------------------------------------------------------
    
    
    //------------------------------------------------------------------------------
    
    template<typename pfn_t>
    inline bool LoadFunc(HMODULE hmod, const char *name, pfn_t &fn)
    {
    	fn = (pfn_t)GetProcAddress(hmod, name);
    	return fn != 0;
    }//LoadFunc
    
    //------------------------------------------------------------------------------
    
    int main()
    {
    	TCHAR title[MAX_PATH];
    	HWND hwnd;
    
    	if (!::GetConsoleTitle(title, sizeof(title)/sizeof(title[0])) || 
    		((hwnd = ::FindWindow(0, title)) == NULL))
    	{
    		std::cerr << "Failed to find console window" << std::endl;
    		return 1;
    	}//else
    
    	// Undocumented API's
    	HMODULE hmod = ::GetModuleHandle(TEXT("KERNEL32.DLL"));
    	if (!hmod || 
    		!LoadFunc(hmod, "SetConsoleFont", SetConsoleFont) ||
    		!LoadFunc(hmod, "GetConsoleFontInfo", GetConsoleFontInfo) ||
    		!LoadFunc(hmod, "GetNumberOfConsoleFonts", GetNumberOfConsoleFonts))
    	{
    		std::cerr << "Failed to load API(s): " << ::GetLastError() << std::endl;
    		return 1;
    	}//if
    
    	HANDLE hOut = ::GetStdHandle(STD_OUTPUT_HANDLE);
    
    	// number of console fonts
    	DWORD num_fonts = GetNumberOfConsoleFonts();
    	if (num_fonts ==0)
    	{
    		std::cerr << "No fonts found" << std::endl;
    		return 1;
    	}
    
    	std::vector<CONSOLE_FONT> fonts(num_fonts);
    	GetConsoleFontInfo(hOut, 0, num_fonts, &fonts[0]);
    
    	for (DWORD n = 0; n < num_fonts; ++n)
    	{
    		fonts[n].dim = GetConsoleFontSize(hOut, fonts[n].index);
    
    		SetConsoleFont(hOut, fonts[n].index);
    		::InvalidateRect(hwnd, 0, FALSE);
    		::UpdateWindow(hwnd);
    		std::cout << "Found font X("<<fonts[n].dim.X<<") Y("<<fonts[n].dim.Y << ")\n";
    		std::cin.get();
    	}
    return 0;
    }
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  11. #26
    Registered User bradszy's Avatar
    Join Date
    Jan 2008
    Posts
    114
    Quote Originally Posted by vart View Post
    You are compiling UNICODE version while using ANSI version of strings
    make it consistent - for example disable UNICODE support in the project settings
    Turning UNICODE off in general project settings, I lost 2 errors, but still have some.

    Build log AFTER UNICODE was disabled:

    Build Log Build started: Project: CMDTEST, Configuration: Debug|Win32
    Command Lines Creating temporary file "c:\Users\bradszy\Documents\Visual Studio 2008\Projects\CMDTEST\CMDTEST\Debug\RSP00000434165 132.rsp" with contents
    [
    /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Gm /EHsc /RTC1 /MDd /Fo"Debug\\" /Fd"Debug\vc90.pdb" /W3 /c /ZI /TP ".\CMDTEST.cpp"
    ]
    Creating command line "cl.exe @"c:\Users\bradszy\Documents\Visual Studio 2008\Projects\CMDTEST\CMDTEST\Debug\RSP00000434165 132.rsp" /nologo /errorReportrompt"
    Output Window Compiling...
    CMDTEST.cpp
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(154) : warning C4005: 'DM_BITSPERPEL' : macro redefinition
    c:\program files\microsoft sdks\windows\v6.0a\include\wingdi.h(2165) : see previous definition of 'DM_BITSPERPEL'
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(155) : warning C4005: 'DM_PELSWIDTH' : macro redefinition
    c:\program files\microsoft sdks\windows\v6.0a\include\wingdi.h(2166) : see previous definition of 'DM_PELSWIDTH'
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(156) : warning C4005: 'DM_PELSHEIGHT' : macro redefinition
    c:\program files\microsoft sdks\windows\v6.0a\include\wingdi.h(2167) : see previous definition of 'DM_PELSHEIGHT'
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(157) : warning C4005: 'DM_DISPLAYFLAGS' : macro redefinition
    c:\program files\microsoft sdks\windows\v6.0a\include\wingdi.h(2168) : see previous definition of 'DM_DISPLAYFLAGS'
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(158) : warning C4005: 'DM_DISPLAYFREQUENCY' : macro redefinition
    c:\program files\microsoft sdks\windows\v6.0a\include\wingdi.h(2169) : see previous definition of 'DM_DISPLAYFREQUENCY'
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(2370) : error C2011: 'HHOOK__' : 'struct' type redefinition
    c:\program files\microsoft sdks\windows\v6.0a\include\windef.h(209) : see declaration of 'HHOOK__'
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(3115) : error C2143: syntax error : missing ';' before ''
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(3115) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(3305) : error C2061: syntax error : identifier 'PCVOID'
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(3435) : warning C4273: 'FrameRgn' : inconsistent dll linkage
    c:\program files\microsoft sdks\windows\v6.0a\include\wingdi.h(3175) : see previous definition of 'FrameRgn'
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(3560) : warning C4273: 'GetWindowExtEx' : inconsistent dll linkage
    c:\program files\microsoft sdks\windows\v6.0a\include\wingdi.h(3644) : see previous definition of 'GetWindowExtEx'
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(3891) : warning C4273: 'WinExec' : inconsistent dll linkage
    c:\program files\microsoft sdks\windows\v6.0a\include\winbase.h(4675) : see previous definition of 'WinExec'
    c:\program files\microsoft sdks\windows\v6.0a\include\imm.h(408) : warning C4005: 'MOD_ALT' : macro redefinition
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(2135) : see previous definition of 'MOD_ALT'
    c:\program files\microsoft sdks\windows\v6.0a\include\imm.h(409) : warning C4005: 'MOD_CONTROL' : macro redefinition
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(2136) : see previous definition of 'MOD_CONTROL'
    c:\program files\microsoft sdks\windows\v6.0a\include\imm.h(410) : warning C4005: 'MOD_SHIFT' : macro redefinition
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(2137) : see previous definition of 'MOD_SHIFT'
    c:\program files\microsoft sdks\windows\v6.0a\include\imm.h(412) : warning C4005: 'MOD_LEFT' : macro redefinition
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(2142) : see previous definition of 'MOD_LEFT'
    c:\program files\microsoft sdks\windows\v6.0a\include\imm.h(413) : warning C4005: 'MOD_RIGHT' : macro redefinition
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(2141) : see previous definition of 'MOD_RIGHT'
    c:\program files\microsoft sdks\windows\v6.0a\include\imm.h(415) : warning C4005: 'MOD_ON_KEYUP' : macro redefinition
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(2140) : see previous definition of 'MOD_ON_KEYUP'
    c:\program files\microsoft sdks\windows\v6.0a\include\imm.h(416) : warning C4005: 'MOD_IGNORE_ALL_MODIFIER' : macro redefinition
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(2139) : see previous definition of 'MOD_IGNORE_ALL_MODIFIER'
    Results Build log was saved at "file://c:\Users\bradszy\Documents\Visual Studio 2008\Projects\CMDTEST\CMDTEST\Debug\BuildLog.htm"
    CMDTEST - 4 error(s), 15 warning(s)
    OS: Windows XP Home Edition SP3, Windows 7 Ultimate Beta Build 7000
    LANGUAGES: C++, VB6
    SKILL: Novice/Intermediate

  12. #27
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    try my sample... if it works - use the include order from it...
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  13. #28
    Registered User bradszy's Avatar
    Join Date
    Jan 2008
    Posts
    114
    Yeah, so using your code here:
    Code:
    #define _WIN32_WINNT 0x0500
    #include <windows.h>
    #include <iostream>
    #include <string>
    #include <vector>
    
    struct CONSOLE_FONT
    {
    	DWORD index;
    	COORD dim;
    };//CONSOLE_FONT
    BOOL (WINAPI *SetConsoleFont)(HANDLE, DWORD);
    BOOL (WINAPI *GetConsoleFontInfo)(HANDLE, BOOL, DWORD, CONSOLE_FONT*);
    DWORD (WINAPI *GetNumberOfConsoleFonts)();
    
    //------------------------------------------------------------------------------
    
    
    //------------------------------------------------------------------------------
    
    template<typename pfn_t>
    inline bool LoadFunc(HMODULE hmod, const char *name, pfn_t &fn)
    {
    	fn = (pfn_t)GetProcAddress(hmod, name);
    	return fn != 0;
    }//LoadFunc
    
    //------------------------------------------------------------------------------
    using namespace std;
    int main()
    {
    	TCHAR title[MAX_PATH];
    	HWND hwnd;
    
    	if (!::GetConsoleTitle(title, sizeof(title)/sizeof(title[0])) || 
    		((hwnd = ::FindWindow(0, title)) == NULL))
    	{
    		std::cerr << "Failed to find console window" << std::endl;
    		return 1;
    	}//else
    
    	// Undocumented API's
    	HMODULE hmod = ::GetModuleHandle(TEXT("KERNEL32.DLL"));
    	if (!hmod || 
    		!LoadFunc(hmod, "SetConsoleFont", SetConsoleFont) ||
    		!LoadFunc(hmod, "GetConsoleFontInfo", GetConsoleFontInfo) ||
    		!LoadFunc(hmod, "GetNumberOfConsoleFonts", GetNumberOfConsoleFonts))
    	{
    		std::cerr << "Failed to load API(s): " << ::GetLastError() << std::endl;
    		return 1;
    	}//if
    
    	HANDLE hOut = ::GetStdHandle(STD_OUTPUT_HANDLE);
    
    	// number of console fonts
    	DWORD num_fonts = GetNumberOfConsoleFonts();
    	if (num_fonts ==0)
    	{
    		std::cerr << "No fonts found" << std::endl;
    		return 1;
    	}
    
    	std::vector<CONSOLE_FONT> fonts(num_fonts);
    	GetConsoleFontInfo(hOut, 0, num_fonts, &fonts[0]);
    
    	for (DWORD n = 0; n < num_fonts; ++n)
    	{
    		fonts[n].dim = GetConsoleFontSize(hOut, fonts[n].index);
    
    		SetConsoleFont(hOut, fonts[n].index);
    		::InvalidateRect(hwnd, 0, FALSE);
    		::UpdateWindow(hwnd);
    		std::cout << "Found font X("<<fonts[n].dim.X<<") Y("<<fonts[n].dim.Y << ")\n";
    		std::cin.get();
    
        
    
    char CM[9999];
    char PAATH[9999];
    system("color 0e");
    ::GetCurrentDirectory(50,PAATH);
    while (1)
    {
          cout<<"______________________________________________________________________________"<<endl;
          cout<<endl<<PAATH<<"> ";
          cin.getline(CM, 9999);
          cout<<endl;
          if (!stricmp(CM, "close"))
    {
                           return 0;
    }
          
          if (!stricmp(CM, "exit"))
    {
                           return 0;
    }
          
          
    
          if ( !stricmp(CM, "thanks"))
    {
             cout<<endl<<"You're welcome"<<endl;
             goto LULZ;
    }
    
          if (!stricmp(CM, "cd"))
    {
                           cout<<endl<<"Path: ";
                           cin.getline(PAATH, 9999);
                           cout<<endl;
                           ::SetCurrentDirectory(PAATH);
                           cout<<"Path Changed to: "<<PAATH<<endl;
                           goto LULZ;
    }
    
    
          
          
          
          else
    {
          system(CM);
    }
          LULZ:;
          
    } 
          return 0;
    }
    }
    I got 4 errors again, build log here:
    Code:
    Build Log      Build started: Project: CMDTEST, Configuration: Debug|Win32
     Command Lines      Creating temporary file "c:\Users\bradszy\Documents\Visual Studio 2008\Projects\CMDTEST\CMDTEST\Debug\RSP00000C34166004.rsp" with contents
    [
    /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Gm /EHsc /RTC1 /MDd /Fo"Debug\\" /Fd"Debug\vc90.pdb" /W3 /c /ZI /TP ".\CMDTEST.cpp"
    ]
    Creating command line "cl.exe @"c:\Users\bradszy\Documents\Visual Studio 2008\Projects\CMDTEST\CMDTEST\Debug\RSP00000C34166004.rsp" /nologo /errorReport:prompt"
     Output Window      Compiling...
    CMDTEST.cpp
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(154) : warning C4005: 'DM_BITSPERPEL' : macro redefinition
            c:\program files\microsoft sdks\windows\v6.0a\include\wingdi.h(2165) : see previous definition of 'DM_BITSPERPEL'
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(155) : warning C4005: 'DM_PELSWIDTH' : macro redefinition
            c:\program files\microsoft sdks\windows\v6.0a\include\wingdi.h(2166) : see previous definition of 'DM_PELSWIDTH'
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(156) : warning C4005: 'DM_PELSHEIGHT' : macro redefinition
            c:\program files\microsoft sdks\windows\v6.0a\include\wingdi.h(2167) : see previous definition of 'DM_PELSHEIGHT'
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(157) : warning C4005: 'DM_DISPLAYFLAGS' : macro redefinition
            c:\program files\microsoft sdks\windows\v6.0a\include\wingdi.h(2168) : see previous definition of 'DM_DISPLAYFLAGS'
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(158) : warning C4005: 'DM_DISPLAYFREQUENCY' : macro redefinition
            c:\program files\microsoft sdks\windows\v6.0a\include\wingdi.h(2169) : see previous definition of 'DM_DISPLAYFREQUENCY'
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(2370) : error C2011: 'HHOOK__' : 'struct' type redefinition
            c:\program files\microsoft sdks\windows\v6.0a\include\windef.h(209) : see declaration of 'HHOOK__'
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(3115) : error C2143: syntax error : missing ';' before ''
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(3115) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(3305) : error C2061: syntax error : identifier 'PCVOID'
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(3435) : warning C4273: 'FrameRgn' : inconsistent dll linkage
            c:\program files\microsoft sdks\windows\v6.0a\include\wingdi.h(3175) : see previous definition of 'FrameRgn'
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(3560) : warning C4273: 'GetWindowExtEx' : inconsistent dll linkage
            c:\program files\microsoft sdks\windows\v6.0a\include\wingdi.h(3644) : see previous definition of 'GetWindowExtEx'
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(3891) : warning C4273: 'WinExec' : inconsistent dll linkage
            c:\program files\microsoft sdks\windows\v6.0a\include\winbase.h(4675) : see previous definition of 'WinExec'
    c:\program files\microsoft sdks\windows\v6.0a\include\imm.h(408) : warning C4005: 'MOD_ALT' : macro redefinition
            c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(2135) : see previous definition of 'MOD_ALT'
    c:\program files\microsoft sdks\windows\v6.0a\include\imm.h(409) : warning C4005: 'MOD_CONTROL' : macro redefinition
            c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(2136) : see previous definition of 'MOD_CONTROL'
    c:\program files\microsoft sdks\windows\v6.0a\include\imm.h(410) : warning C4005: 'MOD_SHIFT' : macro redefinition
            c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(2137) : see previous definition of 'MOD_SHIFT'
    c:\program files\microsoft sdks\windows\v6.0a\include\imm.h(412) : warning C4005: 'MOD_LEFT' : macro redefinition
            c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(2142) : see previous definition of 'MOD_LEFT'
    c:\program files\microsoft sdks\windows\v6.0a\include\imm.h(413) : warning C4005: 'MOD_RIGHT' : macro redefinition
            c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(2141) : see previous definition of 'MOD_RIGHT'
    c:\program files\microsoft sdks\windows\v6.0a\include\imm.h(415) : warning C4005: 'MOD_ON_KEYUP' : macro redefinition
            c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(2140) : see previous definition of 'MOD_ON_KEYUP'
    c:\program files\microsoft sdks\windows\v6.0a\include\imm.h(416) : warning C4005: 'MOD_IGNORE_ALL_MODIFIER' : macro redefinition
            c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(2139) : see previous definition of 'MOD_IGNORE_ALL_MODIFIER'
     Results      Build log was saved at "file://c:\Users\bradszy\Documents\Visual Studio 2008\Projects\CMDTEST\CMDTEST\Debug\BuildLog.htm"
    CMDTEST - 4 error(s), 15 warning(s)
    :/
    OS: Windows XP Home Edition SP3, Windows 7 Ultimate Beta Build 7000
    LANGUAGES: C++, VB6
    SKILL: Novice/Intermediate

  14. #29
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    after removing
    #define _WIN32_WINNT 0x0500
    and replacing Get/SetCurrentDirectory with Get/SetCurrentDirectoryA

    I got only this:
    Code:
    1>test.cpp(81) : warning C4127: conditional expression is constant
    1>test.cpp(87) : warning C4996: 'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _stricmp. See online help for details.
    1>        c:\program files\microsoft visual studio 9.0\vc\include\string.h(215) : see declaration of 'stricmp'
    1>test.cpp(92) : warning C4996: 'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _stricmp. See online help for details.
    1>        c:\program files\microsoft visual studio 9.0\vc\include\string.h(215) : see declaration of 'stricmp'
    1>test.cpp(99) : warning C4996: 'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _stricmp. See online help for details.
    1>        c:\program files\microsoft visual studio 9.0\vc\include\string.h(215) : see declaration of 'stricmp'
    1>test.cpp(105) : warning C4996: 'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _stricmp. See online help for details.
    1>        c:\program files\microsoft visual studio 9.0\vc\include\string.h(215) : see declaration of 'stricmp'
    1>test.cpp(65) : warning C4702: unreachable code
    I do not get your warnings from win header files - so I suppose your installation of VS is somehow messed up
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  15. #30
    Registered User bradszy's Avatar
    Join Date
    Jan 2008
    Posts
    114
    Is there a place I can get a good copy of winuser.h?
    Because that's where my errors are coming from.
    I tried what you said and got 8 errors...

    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(2370) : error C2011: 'HHOOK__' : 'struct' type redefinition
    c:\program files\microsoft sdks\windows\v6.0a\include\windef.h(209) : see declaration of 'HHOOK__'
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(3115) : error C2143: syntax error : missing ';' before ''
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(3115) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(3152) : error C2143: syntax error : missing ';' before ''
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(3152) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(3154) : error C2143: syntax error : missing ';' before ''
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(3154) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    c:\program files\microsoft visual studio 9.0\vc\include\winuser.h(3305) : error C2061: syntax error : identifier 'PCVOID'
    All from winuser.h.
    Last edited by bradszy; 04-26-2008 at 05:43 AM.
    OS: Windows XP Home Edition SP3, Windows 7 Ultimate Beta Build 7000
    LANGUAGES: C++, VB6
    SKILL: Novice/Intermediate

Page 2 of 3 FirstFirst 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Adventures in labyrinth generation.
    By guesst in forum Game Programming
    Replies: 8
    Last Post: 10-12-2008, 01:30 PM
  2. Invalid conversion from 'void*' to 'BYTE' help
    By bikr692002 in forum C++ Programming
    Replies: 9
    Last Post: 02-22-2006, 10:27 AM
  3. Defining the size of the console...
    By twomers in forum C++ Programming
    Replies: 1
    Last Post: 12-21-2005, 10:35 AM
  4. Increase Font Size Or Bold???
    By stickman in forum C++ Programming
    Replies: 10
    Last Post: 08-27-2004, 05:26 PM
  5. Console Size
    By Punkture in forum C Programming
    Replies: 2
    Last Post: 05-08-2003, 05:25 PM

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