Skip to main content
gamedev.net
🔒 Locked

Win32 - Console simulation with edit box

Started by dimovich Mar 10, 2006 at 12:53 AM 5 replies 2.9k views
Original Post
dimovich
dimovich
I'm writting a game under Win32, and have a console window. You can enter commands, change various options from it in "realtime" :) The console window is composed of 2 edit boxes. One for the input line, and the other for the command history. The later one is a multi-line, read-only edit box. My question: how can I add new lines of text to the command history to the bottom (not to the top), and have it automatically scroll vertically. (Well, like in a IRC chat :) ) Thanks!
We're doing this for a living, George. We are not amateurs.
Colin Jeanne
Colin Jeanne
The trick is to use EM_SETSEL to set the selection to after the last character in the edit. Then you can use EM_REPLACESEL with the text you want to add. This will append data to the edit.
vovansim
vovansim
It depends on what you are using for the UI library. Is it MFC? Or some other library? The specific answer will depend on that.

Vovan
Vovan
yadango
yadango
Why use an edit control? Why not render it and program scrolling in yourself? This way your console can have an alpha and pretty flashing colors -- like Serious Sam -- which has one of the most beautifully written consoles in a game (and much of it's GUI source code, from their modding SDK, is free to look at).
dimovich
dimovich
Quote:
Original post by vovansim
It depends on what you are using for the UI library. Is it MFC? Or some other library? The specific answer will depend on that.


I'm using pure Win32.
We're doing this for a living, George. We are not amateurs.
eq
eq
Sorry for hijacking the thread with a new question, they are somewhat related though.
I can't tell from your post if you're running command line applications and have their output redirected to your window (edit box)?

I'm trying to acomplish this.
It's not that hard to capture output that goes to the stdout and stderr, got that working.
All built in commands such as: dir, type etc works fine.
All my custom applications that use conio.h (i.e cprintf) works fine as well.
Program that use printf doesn't work though!
Their output isn't captured by my redirection code!
How do you capture such output?

The easy solution seems to be:
"Why don't you recompile your applications using cprintf?"
The problem is that most of the applications that I use isn't my own and I don't have the source for it.

I've read a lot on the net but I still can't manage to catch all the output.
dimovich
dimovich
I've found the solution in the Quake3 source code (win_syscon.c).

HWND hWndEdit; //command history edit box handleTCHAR *szBuff; //command history text buffer...//Scroll down to the last lineSendMessage( hWndEdit, EM_LINESCROLL, 0, 0xffff );//Put the caret in viewSendMessage( hWndEdit, EM_SCROLLCARET, 0, 0 );//Insert text at the endSendMessage( hWndEdit, EM_REPLACESEL, 0, (LPARAM)szBuff );


And yadango, thanks for your advice with SeriousSam SDK. I've found
a lot of useful code there.
We're doing this for a living, George. We are not amateurs.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.