Archived

This topic is now archived and is closed to further replies.

Codegod

How do I setup a DOS box with a Windows application?

Recommended Posts

Howdy all, I''m writing this simple windowed DirectX application, but I would like to also have a DOS box appear and write logging messages to the DOS box during runtime. How can I do that? Thanks. Eric

Share this post


Link to post
Share on other sites

AllocConsole(); // Allocate the console
HANDLE out;
DWORD count;
out = GetStdHandle( STD_OUTPUT_HANDLE );
WriteConsole( out, "Test", 4, &count, NULL );
FreeConsole();


[edited by - jacksonh on March 22, 2002 5:50:41 PM]

Share this post


Link to post
Share on other sites
Just because it has a text-mode interface, that doesn''t make it DOS. DOS is an operating system.
What you call "DOS box" is called such only when command.com has been invoked, because that''s the command processor for DOS and requires the DOS virtual machine. Otherwise, the text-mode interface window you see is the console—Windows has a legitimate console subsystem that has nothing to do with DOS.

Share this post


Link to post
Share on other sites
You might find this helpful too.


  
#include <windows.h>
#include <stdarg.h>
#include <stdio.h>
/////////////////////////////////////////////////////////////////////////////

// F I L E P R I N T F O R M A T -------------------------------------------

// win32 style replacement for fprintf

INT __cdecl FilePrintFormat(HANDLE hFile, LPCTSTR format, ...)
{
TCHAR szBuffer[1024];
ZeroMemory(&szBuffer, sizeof(szBuffer) );
int retValue = 0;
DWORD cbWritten;
va_list argptr;

if ( hFile != INVALID_HANDLE_VALUE )
{
va_start( argptr, format );
retValue = wvsprintf( szBuffer, format, argptr );
va_end( argptr );
WriteFile( hFile, szBuffer, retValue, &cbWritten, (LPOVERLAPPED)NULL );
}
return retValue;
}

Share this post


Link to post
Share on other sites
quote:
Original post by siaspete
As far as I know, cmd.exe is a Win32 command prompt, not a DOS box.

I'm not entirely sure though, so let the flames begin!




No need for flames - My understanding is that cmd.exe is the NT equivalent to command.com - and so I brought it up. I agree that the proper terminology is 'console window' or 'command prompt' - but just the same, I cut my teeth on DOS 5.0 and still manage to slip up myself on occaission.

// Edit

For the record - the W2K version info for cmd.exe titles itself "Windows NT Command Processor"


[edited by - lessbread on March 23, 2002 5:16:54 PM]

Share this post


Link to post
Share on other sites
Sounds about right. I do think that COMMAND is based on DOS where CMD is NT (like you say).

Output from COMMAND:
Microsoft(R) Windows DOS
(C)Copyright Microsoft Corp 1990-1999.


Output from CMD:
Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.


Hurray!


Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions

Share this post


Link to post
Share on other sites
quote:
Original post by siaspete
Output from CMD:
Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.



Mine prints the same thing. Looks like we''re running the same build.

Interesting to compare the copyrights. cmd.exe dates back to 1985? That seems a wee bit off to me...

Share this post


Link to post
Share on other sites
quote:
Original post by Codegod
How do I set the properties for the console, such as window and buffer sizes??



SetConsoleWindowInfo is an API that sets the console size. If you want to explore using the hwnd to the console - you can get it with something like this:


    
HWND hConWnd = NULL;
TCHAR szTempTitle[] = MY_CON_GUID; // use a GUID

TCHAR szTempString[MAX_PATH];

if( GetConsoleTitle(szTempString, sizeof(szTempString)/sizeof(TCHAR) ) > 0 )
{
SetConsoleTitle(szTempTitle);
hConWnd = FindWindow(TEXT("tty"), szTempTitle);
SetConsoleTitle(szTempString);
}

But you might want to verify that "tty" is the correct classname using a window spy prog or something like that. "tty" was correct on W98 - on W2K its "ConsoleWindowClass"

For changing the buffer the API's are CreateConsoleScreenBuffer, GetConsoleScreenBufferInfo, SetConsoleScreenBufferSize and a few others. Here's a link to a console game that was posted in one of the flipcode totd's last year. The code illustrates several useful console techniques.

JCAB's Console Snake Game

// EDIT - this link points to a lot of useful info - it asks the same question - you might even recognize the code snippet that jacksonh presented above - and goes a bit further with 'freopen' and alt+enter. I even got a little nostalgic looking at it as it was my first post ever at flipcode. How fast time flies...



[edited by - lessbread on March 23, 2002 5:50:55 PM]

Share this post


Link to post
Share on other sites
When you have a Win32 console application, no instance of command.com (the DOS command processor), cmd.exe (the native Win32 command processor), or ntvdm.exe (NT''s virtual DOS machine, necessary for running DOS applications) is spawned, therefore no DOS is involved.

Share this post


Link to post
Share on other sites