zachman123 Posted May 6, 2005 Share Posted May 6, 2005 I've been wondering this for a while now, is it possible to somehow display a DOS command window inside a form? Link to comment Share on other sites More sharing options...
0 AndreasV Posted May 6, 2005 Share Posted May 6, 2005 A DOS command window or a console window? two different things. If you want the console window, you could pipe the input and output with an internal buffer which you show in a funky editbox? Link to comment Share on other sites More sharing options...
0 zachman123 Posted May 6, 2005 Author Share Posted May 6, 2005 I've been wondering this for a while now, is it possible to somehow display a DOS command window inside a form? 585882760[/snapback] Thanks for the console tip though too. Link to comment Share on other sites More sharing options...
0 AndreasV Posted May 6, 2005 Share Posted May 6, 2005 DOS command is not gonna work, because that runs in the 16 bit emulation layer (WoW). Link to comment Share on other sites More sharing options...
0 zachman123 Posted May 6, 2005 Author Share Posted May 6, 2005 O.k., I think I see. Even on Windows XP though? Doesn't XP use pseudo-dos, not actually emulate dos? Link to comment Share on other sites More sharing options...
0 AndreasV Posted May 6, 2005 Share Posted May 6, 2005 No. There are 16 bit DOS windows, which run in the emulation layer en there are console windows (start->run type cmd and hit enter to see one). Console windows are actually 32 bits applications which simply don't have a GUI output, but use the good old commandline/console interface. Link to comment Share on other sites More sharing options...
0 zachman123 Posted May 6, 2005 Author Share Posted May 6, 2005 I see. Thanks anyways though for the info. Link to comment Share on other sites More sharing options...
0 smurfiness Posted May 7, 2005 Share Posted May 7, 2005 You can embed an existing command line window inside one of your windows using a bit of trickery with the FindWindow, SetParent and MoveWindow Win32 API functions. This is C# 2005 code, but it should work equally well in 2002 or 2003. The only thing you need to watch is that you have the EXACT text of the command window in the call to FindWindow. Using this code as a template, it wouldn't be terribly difficult to start up a command window from your app and then hijack that instead of a command window started from the shell. public partial class Form1 : Form { [DllImport("user32.dll")] private static extern IntPtr FindWindow(String className, String WindowName); [DllImport("user32.dll")] private static extern IntPtr SetParent(IntPtr childWindow, IntPtr newParent); [DllImport("user32.dll")] private static extern bool MoveWindow(IntPtr hwnd, int x, int y, int width, int height, bool repaint); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { IntPtr hwnd = FindWindow(null, "C:\\WINDOWS\\system32\\cmd.exe"); if (hwnd == IntPtr.Zero) MessageBox.Show("Got null handle"); else { SetParent(hwnd, this.Handle); MoveWindow(hwnd, 0, 0, this.Width, this.Height, false); } } } Link to comment Share on other sites More sharing options...
0 AndreasV Posted May 7, 2005 Share Posted May 7, 2005 C:\\WINDOWS\\system32\\cmd.exe <- that's not A DOS window, but a console window (32bits). Link to comment Share on other sites More sharing options...
0 zachman123 Posted May 7, 2005 Author Share Posted May 7, 2005 (edited) Well that's actually what I was going for. Now for an even less likely question.... Would it be possible to recieve the text in the cmd.exe window using a message or something? edit: Never mind, this http://www.codeguru.com/Csharp/Csharp/cs_m...icle.php/c8503/ appears to be almost what I need. Edited May 7, 2005 by zachman123 Link to comment Share on other sites More sharing options...
0 AndreasV Posted May 7, 2005 Share Posted May 7, 2005 So you didn't want a DOS command window at all? Talk about misleading me :p .. A console window is gonna work yes.. Just pipe it's input/output. Link to comment Share on other sites More sharing options...
0 Patrick_ Posted May 7, 2005 Share Posted May 7, 2005 You could also just open up a command prompt in the background and output its output to your program. :D I know the VB.NET code if you would like it. Link to comment Share on other sites More sharing options...
0 smurfiness Posted May 8, 2005 Share Posted May 8, 2005 C:\\WINDOWS\\system32\\cmd.exe <- that's not A DOS window, but a console window (32bits). 585886875[/snapback] Right, but what he wanted was a command prompt (not, say a DOS game or something). Whether it's a DOS command prompt or a Windows command prompt really isn't THAT important, since you could use the same technique to embed either. Link to comment Share on other sites More sharing options...
0 zachman123 Posted May 8, 2005 Author Share Posted May 8, 2005 I thought by console window you meant the programs console window :D Anyways, I've got it all worked out. BTW if you're wondering what this is for... 1. I want to be able to have a nice, good looking DOS/Command/Console (heh) window on my desktop. And 2. Just got a 4x20 lcd and I want to use it to show DOS/Command/Console output on it (I know 20 charactors isn't that big, but meh, it's just for fun). Thanks to all that helped. edit: On second thought, I'm interested to see what you've got, Patrick_. Feel free to email/im (aim:zachman123,email/msn:zachman123@gmail.com,yahoo:zachdude123@sbcglobal.net. God I need a sig...) or I'll contact you. Link to comment Share on other sites More sharing options...
Question
zachman123
I've been wondering this for a while now, is it possible to somehow display a DOS command window inside a form?
Link to comment
Share on other sites
13 answers to this question
Recommended Posts