Console help

Started by
7 comments, last by JasonA 21 years, 7 months ago
Hi guys! I need a lot of help please =P I have a working 2D game engine, and I'm pretty happy with it but basically doing output in DirectX is a pain in the butt. So, I realized what I need is a console! The only problem is I'm starting the console up with the DialogBox () macro and the dialog becomes the main focus, so the game window loses focus until i exit out of the console =(. Obviously, that ain't supposed to happen! I want the game to run normally, and the console will just be in the background outputting messages to its Read-Only Edit Box everytime it gets a message. Anyways, enough talking, here's the console code (very short) I have: (By the way, the console is just a dialog box,IDD_CONSOLE, with a read-only edit box IDC_CONSOLEOUTPUT) and a input box (unimplemented) IDC_CONSOLEINPUT).) Note: My game engine runs in windowed mode not fullscreen. // I N C L U D E S ///////////////////////////////////// // tells Windows not to give us MFC stuff #define WIN32_LEAN_AND_MEAN #include <windows.h> // various string manipulation #include <stdio.h> // for implementing void function (...) #include <stdarg.h> // G L O B A L S /////////////////////////////////////// HWND g_consoleHDlg; // console text to be printed to window char consoleText[102400]; // F U N C T I O N S /////////////////////////////////// int ConsoleInit (HWND hwnd) { DialogBox(NULL, (LPCTSTR)IDD_CONSOLE, hwnd, (DLGPROC)ConsoleProc); // this code right here doesn't change the focus SetForegroundWindow (hwnd); return 1; } int AddConsoleMessage (char *message, ...) { char out[1024]; va_list body; va_start (body, message); vsprintf (out, message, body); va_end (body); sprintf (consoleText,out); return SetDlgItemText (g_consoleHDlg, IDC_CONSOLEOUTPUT, consoleText); } LRESULT CALLBACK ConsoleProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: g_consoleHDlg = hDlg; AddConsoleMessage ("testing"); return TRUE; case WM_CLOSE: EndDialog(hDlg, LOWORD(wParam)); return TRUE; } return FALSE; } #endif //CONSOLE_H [edited by - JasonA on September 14, 2002 12:12:45 AM] [edited by - JasonA on September 15, 2002 2:20:32 AM]
Jason Arorajason@pubism.comhttp://www.pubism.com
Advertisement
If you don''t want your program to pause whilst you display the console, I beleive you can use a ''Modal'' Dialog box. This is done in a similar way to the DialogBox method, Except it does not pause the program waiting for the function to return.

Look up in WinSDK about ''modal'' dialog boxes

--Josh

''My two cents''
Actually its the other way around. Modal dialog boxes are the type that dont let anything else happen untill you get rid of them. The opposite are modeless dialog boxes. These will coexist with your application, allowing it to continue running. A google search for "modeless dialog box" turns up several helpful pages if you decide to go this route.

Alternativly, have you considered building a console directly into your engine using directx? Its quite simple to do, there is an article here on Gamedev that talks about them:
http://www.gamedev.net/banman/banman.asp?ZoneID=1&Task=Get&X=1032096055638


Alan
"There will come a time when you believe everything is finished. That will be the beginning." -Louis L'Amour
Thanks!!!
Thanks for all the input guys. AlanKemp you''re right it''s modeless dialog box, and now my game can coexist with the console! By the way, I have seen the article on how to build the console directly into my engine; it''s very cool, but I mainly will use the console for debugging.
By the way, if anyone''s interested all I had to change was this MACRO call, DialogBox(NULL, (LPCTSTR)IDD_CONSOLE, hwnd, (DLGPROC)ConsoleProc);, to CreateDialog (NULL, (LPCTSTR)IDD_CONSOLE, hwnd, (DLGPROC)ConsoleProc); and in the console callback function in the WM_INITDIALOG case I had to show the dialog: ShowWindow (g_consoleHDlg, SW_SHOW);
Jason Arorajason@pubism.comhttp://www.pubism.com
Okay... I''m having a very annoying problem:

sprintf (consoleText, "first line \n second line");
SetDlgItemText (g_consoleHDlg, IDC_CONSOLEOUTPUT, consoleText);

so basically you would expect the output to be:
first line
second line

BUT this is what i get:
first line[]second line
([]- the solid block which means character not found)

And, I made sure to make the properties on the dialog box include Multiline.

PLEASE HELP!!
Jason Arorajason@pubism.comhttp://www.pubism.com
As far as I know, dialogs cannot hold more than one line. What you want is a Window that looks like a dialog. I''m not even a WinAPI n00b, so I can''t guarentee my suggestion will work.
/*-=-=-=-=-=-=-=-=-=-=-=-= trae@illicitstudios.com=-=-=-=-=-=-=-=-=-=-=-=-*/
IIRC there is a flag called "multi-line" in the dialoog editor. It seems like you need to check that...



Dunno if this will help you but I''ve written (well, re-written - I''ve forgotten where I got the base from) a console class that I use for my graphics programs. It opens a dos console looking thing and uses streams to print stuff to it (ie cout).
To use it, simply include the header and call console.open(300,300); and then you can print to it using console << "Test: " << some_var << ":" << some_othervar << "\n";
You can also change the colors of it if you want (read the source, I forgot how off the top of my head - I just use the default).
Note: endl doesn''t work so you have to use \n. Never bothered me enough to fix it.
You can get the code at http://quake.condemned.com/console.zip
Try using \n\r instead of just \n.

This topic is closed to new replies.

Advertisement