Thread: How to get both win32 and command prompt interface in the same application?

  1. #1
    Registered User Swarvy's Avatar
    Join Date
    Apr 2008
    Location
    United Kingdom
    Posts
    195

    How to get both win32 and command prompt interface in the same application?

    I've made a few games etc using the windows API, but I was wondering, how exactly do you get a win32 interface combined with a command prompt interface in the same application. It seems like a strange question, I know, but I want both part of the same program because, I want to have the flexibility offered by win32, but at the same time use the command prompt box for error output and basic low level command input etc.

    How do I get both interfaces to appear in the same application at the same time?

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    The easiest thing to do is to create a console application and give it a message pump. Use the Windows API as you normally would.

    gg

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    55
    Look up AllocConsole() on MSDN.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by nucleon View Post
    Look up AllocConsole() on MSDN.
    I found the following when trying to do the same:
    Code:
    	int hConHandle;
    	intptr_t lStdHandle;
    	AllocConsole();
    	lStdHandle = (intptr_t) GetStdHandle(STD_OUTPUT_HANDLE);
    
    	hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
    	fp = _fdopen( hConHandle, "w" );
    	*stdout = *fp;
    	setvbuf( stdout, NULL, _IONBF, 0 );
    
    	// redirect unbuffered STDIN to the console
    
    	lStdHandle = (intptr_t) GetStdHandle(STD_INPUT_HANDLE);
    	hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
    	fp = _fdopen( hConHandle, "r" );
    	*stdin = *fp;
    	setvbuf( stdin, NULL, _IONBF, 0 );
    
    	// redirect unbuffered STDERR to the console
    
    	lStdHandle = (intptr_t) GetStdHandle(STD_ERROR_HANDLE);
    	hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
    	fp = _fdopen( hConHandle, "w" );
    	*stderr = *fp;
    	setvbuf( stderr, NULL, _IONBF, 0 );
    --
    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.

  5. #5
    Registered User
    Join Date
    Jan 2007
    Posts
    89
    You can also check out this video on creating a data logger.

  6. #6
    Registered User Swarvy's Avatar
    Join Date
    Apr 2008
    Location
    United Kingdom
    Posts
    195
    Quote Originally Posted by eaane74 View Post
    You can also check out this video on creating a data logger.
    Wow, I'm watching that video at the moment, and had a look at the site where it came from, and that is a good find. Lots of very useful information there. Thanks a bunch.

Popular pages Recent additions subscribe to a feed