784 } while (n != max_argc); |
784 } while (n != max_argc); |
785 |
785 |
786 return n; |
786 return n; |
787 } |
787 } |
788 |
788 |
789 #ifndef ATTACH_PARENT_PROCESS |
|
790 #define ATTACH_PARENT_PROCESS ((DWORD)-1) |
|
791 #endif |
|
792 |
|
793 void CreateConsole(void) |
789 void CreateConsole(void) |
794 { |
790 { |
795 HANDLE hand; |
791 HANDLE hand; |
796 CONSOLE_SCREEN_BUFFER_INFO coninfo; |
792 CONSOLE_SCREEN_BUFFER_INFO coninfo; |
797 BOOL (WINAPI *AttachConsole)(DWORD); |
|
798 |
793 |
799 if (_has_console) return; |
794 if (_has_console) return; |
800 |
795 |
801 _has_console = true; |
796 _has_console = true; |
802 |
797 |
803 /* Attach to an existing console if one exists. Unfortunately this function |
798 AllocConsole(); |
804 * only exists on WindowsXP or higher, so for all other users out there: |
|
805 * you're stuck with an additional console even if you started openttd from |
|
806 * the command line */ |
|
807 if (!LoadLibraryList((Function*)&AttachConsole, "kernel32.dll\0AttachConsole\0") || |
|
808 !AttachConsole(ATTACH_PARENT_PROCESS)) |
|
809 AllocConsole(); |
|
810 |
799 |
811 hand = GetStdHandle(STD_OUTPUT_HANDLE); |
800 hand = GetStdHandle(STD_OUTPUT_HANDLE); |
812 GetConsoleScreenBufferInfo(hand, &coninfo); |
801 GetConsoleScreenBufferInfo(hand, &coninfo); |
813 coninfo.dwSize.Y = 500; |
802 coninfo.dwSize.Y = 500; |
814 SetConsoleScreenBufferSize(hand, coninfo.dwSize); |
803 SetConsoleScreenBufferSize(hand, coninfo.dwSize); |