views:

107

answers:

2

I'm currently working on a game and relaly want to add an external console to it (right now it's built into the main game window).

What I would really like is to create a new Window which acts as the console with maybe a text box in the bottom to add new commands into it and a larger text box on top which outputs information.

I'm using DirectX and not all that sure how I would go about doing this. Do I create a new window from C++? If so how would I go about doing it with the given recquirements (and I'd really prefer the window I create not to be iN CLR). Would communicating between the main application window and the console window be a problem? I wouldn't mind using actual windows form objects to make this happen (in fact I'd prefer it that way as it would give copy+paste advantages and the like).

I'd like the option that is the most flexible, perhaps so i can add multicoloured text and the like into the console window.

Appreciate any help on this =)

+2  A: 

First advice: search for a library that offers what you want. Perhaps SDL (http://www.libsdl.org/) or QT (www.qtsoftware.com).

Or you do it by hand: CreateWindowEx is your starting point. The rest is a lot of reading about Windows Programming. Charles Petzold may be your friend here.

Tobias Langner
+1  A: 

A lot depends on your compiler. If you are using Visual Studio (Non-express) you can do this fairly easily by creating a dialog template. You can then use CreateDialogIndirect to create the thing. You'd probably want to use a RichEdit control embedded in the dialog (The RichEdit control is not a simple one though ... so if you just want plain text you'd find it a LOT easier using a standard Edit control) for what you are after. You can then pass messages using SendDlgItemMessage to the rich edit to put the text in the RichEdit control.

If you can't use the dialog template builder it will be a lot more complicated. As Tobias points out you will need to use CreateWindow(Ex) to create the dialog and then CreateWindow the rich edit control inside. From there you should still be able to use SendDlgItemMessage to fill the RichEdit control, however.

Either way you will need to handle the plethora of windows messages. Every time the user clicks or even moves their mouse over the window you will get a windows message. You don't have to process them all but you will need to figure out what messages you DO need to handle and then handle them. Admittedly using a simple edit control it would be pretty easy to spam text to the edit control. You can set the control's text content simply by using the SetWindowText function (which internally sends a WM_SETTEXT message).

Goz