Home » Community » Forums » General Programming » Win32 - Console simulation with edit box
  Intel sponsors gamedev.net search:   
[Control Panel] [Register] [Bookmarks] [Who's Online] [Active Topics] [Stats] [FAQ] [Search]

Add Forum to Favorites |  Send Topic To a Friend | View Forum FAQ | Track this topic


 Last Thread Next Thread 
 Win32 - Console simulation with edit box
Post New Topic  Post Reply 
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!

 User Rating: 1023   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

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.



 User Rating: 1676   |  Rate This User  Send Private MessageView ProfileView JournalView GD Showcase Entries Report this Post to a Moderator | Link

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

 User Rating: 1157   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

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).

 User Rating: 1264   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

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.

 User Rating: 1023   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

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.


 User Rating: 1356   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

I've found the solution in the Quake3 source code (win_syscon.c).

HWND hWndEdit; //command history edit box handle
TCHAR *szBuff; //command history text buffer

...

//Scroll down to the last line
SendMessage( hWndEdit, EM_LINESCROLL, 0, 0xffff );
//Put the caret in view
SendMessage( hWndEdit, EM_SCROLLCARET, 0, 0 );
//Insert text at the end
SendMessage( hWndEdit, EM_REPLACESEL, 0, (LPARAM)szBuff );




And yadango, thanks for your advice with SeriousSam SDK. I've found
a lot of useful code there.

 User Rating: 1023   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

All times are ET (US)

Post Reply
 Last Thread Next Thread 
Forum Rules:
You may not post new threads
You may post replies
You may not edit your posts
You may not use HTML in your posts
Jump To:
Administrative Options: