• 0

[C# or any] Embedding a DOS window?


Question

13 answers to this question

Recommended Posts

  • 0

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.

  • 0

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 handle");
            else
            {
                SetParent(hwnd, this.Handle);
                MoveWindow(hwnd, 0, 0, this.Width, this.Height, false);
            }
        }
    }

  • 0

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 by zachman123
  • 0
  AndreasV said:
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.

  • 0

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.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • AMD 25.6.3 driver brings FSR 4 support for GTA V and Monster Hunter Wilds by Pulasthi Ariyasinghe AMD's driver team is busy this June. The company just released its third graphics driver of the month, and this one is focused on expanding support for FidelityFX Super Resolution 4 (FSR 4) upscaling tech. A handful of bug fixes are included in this release, too. AMD Software: Adrenalin Edition 25.6.3 optional driver is finally bringing FSR 4 support for Monster Hunter: Wilds, the Capcom-developed action RPG that released earlier this year. The title is well known for its performance issues, so the FSR update should help RX 9000 series owners get more frames without losing too much graphics fidelity. Next, the driver also delivers FSR 4 for Grand Theft Auto V Enhanced. The expanded and enhanced version of the title featuring ray tracing and other features only hit the PC platform a few months ago, and now, latest-generation Radeon graphics users can use the upscaling tech to improve their frame rates. AMD has also fixed an issue with FSR 4 in this release that made the technology not enable properly on a bunch of games. They include DragonKin: The Banished, Blades of Fire, RoadCraft, The Alters, Star Wars Outlaws, and S.T.A.L.K.E.R. 2: Heart of Chornobyl. A Black Myth: WuKong crash on the RX 7650 GRE GPU and a The Elder Scrolls IV: Oblivion Remastered texture corruption issue on the RX 9070 XT have also been resolved in this release. Here are the known issues that AMD is still working on: Stutter may be observed while playing games with some VR headsets at 80Hz or 90Hz refresh rate on some AMD Radeon™ Graphics Products, such as the Radeon™ RX 7000 series. Users experiencing this issue are recommended to change the refresh rate as a temporary workaround. Intermittent system or application crashes may be observed while playing Cyberpunk 2077 on some AMD Radeon™ Graphics Products, such as the Radeon™ RX 7000 series and Radeon™ RX 9000 series. Intermittent application crash or driver timeout may be observed while playing Monster Hunter Wilds with Radeon™ Anti-Lag and Instant Replay enabled. Stutter may be observed while playing Call of Duty: Warzone Season 03 ‘Verdansk’ map on some AMD Graphics Products. Stutter and lower-than-expected performance may be observed while playing 4K resolution YouTube videos in Chrome. Users experiencing this issue are recommended to play videos in full screen as a temporary workaround. The new AMD Software: Adrenalin Edition 25.6.3 optional update is now available for download from the AMD Software app as well as AMD's own changelog page for the driver.
    • So, basically, Windows 11 is the 'new Windows 7 'cause everyone's ignoring it? Guess my Windows 10 machine and I will just live happily ever after in our secure, familiar bubble... until four months from now. Then we'll figure it out. Probably.
    • Are you sure you are not mis-understanding a use case for Windows 11 where it fails? Your experience does not negate another user's dislike of something. I.E. don't be dismissive just because you haven't experienced something they have. That makes you look bad.
    • How about linking network storage and or external storage and then Explorer becomes a game of waiting and waiting and waiting. Windows 10 was not nearly this bad at that task.
    • People who don't know how to use a computer to its fullest genuinely fascinate me. Nope, not at all. Either you get it or you don't. Not getting it is not a good reason to speak out.
  • Recent Achievements

    • One Year In
      timothytoots earned a badge
      One Year In
    • One Month Later
      CHUNWEI earned a badge
      One Month Later
    • Week One Done
      TIGOSS earned a badge
      Week One Done
    • First Post
      henryj earned a badge
      First Post
    • First Post
      CarolynHelen earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      475
    2. 2
      +FloatingFatMan
      195
    3. 3
      ATLien_0
      163
    4. 4
      Xenon
      79
    5. 5
      Som
      76
  • Tell a friend

    Love Neowin? Tell a friend!