win32.c
changeset 4571 4194aa48c9cd
parent 4370 c7bd128b1670
child 4572 e6e17d286de7
equal deleted inserted replaced
4570:61a551bc82ef 4571:4194aa48c9cd
   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 
   789 void CreateConsole(void)
   793 void CreateConsole(void)
   790 {
   794 {
   791 	HANDLE hand;
   795 	HANDLE hand;
   792 	CONSOLE_SCREEN_BUFFER_INFO coninfo;
   796 	CONSOLE_SCREEN_BUFFER_INFO coninfo;
       
   797 	BOOL (WINAPI *AttachConsole)(DWORD);
   793 
   798 
   794 	if (_has_console) return;
   799 	if (_has_console) return;
   795 
   800 
   796 	_has_console = true;
   801 	_has_console = true;
   797 
   802 
   798 	AllocConsole();
   803 	/* Attach to an existing console if one exists. Unfortunately this function
       
   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();
   799 
   810 
   800 	hand = GetStdHandle(STD_OUTPUT_HANDLE);
   811 	hand = GetStdHandle(STD_OUTPUT_HANDLE);
   801 	GetConsoleScreenBufferInfo(hand, &coninfo);
   812 	GetConsoleScreenBufferInfo(hand, &coninfo);
   802 	coninfo.dwSize.Y = 500;
   813 	coninfo.dwSize.Y = 500;
   803 	SetConsoleScreenBufferSize(hand, coninfo.dwSize);
   814 	SetConsoleScreenBufferSize(hand, coninfo.dwSize);