• 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

    • I guess companies have numbers that don't necessarily match your assessment.
    • I agree that all capabilities of the card should be reviewed, but there is a very important difference between reviewing what multiframe generation is and does for you, and simply claiming a card has 200+ FPS just because MFG is on. You are probably well aware that frame generation is getting a lot of hate, which I feel like is partly unfair to it. However, Nvidia has used frame generation to tell outright lies about their products, most notably claiming that a 5070 is as powerful as a 4090. Its easy to hate something when it is being used to make dishonest statements like that. I'm not a big fan of the popular term "fake frames" just because I feel like it is overly negative, but I do think it is important to make some kind of distinction between game engine frames and filler frames.
    • What is the replacement or successor to it right now?
    • iPhone 17 Pro Max could have the biggest battery ever on an iPhone by Devesh Beri Leaks around how the iPhone 17 Pro lineup is going to look may have left fans hesitant about what Apple is planning for its next flagship, but not every rumor paints a gloomy picture. In fact, one area where the iPhone 17 Pro Max could truly stand out is its battery; rumors say it is to have the biggest battery ever seen in an iPhone. Let's be honest, battery life has long been a weak point for iPhones. No matter how efficient Apple's A-series chipsets are said to be, users often find their devices running out of juice quicker than expected. Much of the blame could be put on the relatively small battery sizes Apple has chosen over the years, especially when compared to the competition. Many rival brands now give their large-screen devices, those with displays bigger than 6.5 inches, batteries of at least 5000mAh. In contrast, Apple's largest iPhones have lagged behind in this department, with the iPhone 16 Pro Max coming in at 4676mAh. It seems like it is set to change with the iPhone 17 Pro Max, as a prominent leaker, Instant Digital, revealed that the battery of the iPhone 17 Pro Max will finally reach the 5000mAh mark. How big a change would it be? To put it in perspective, the iPhone 17 Pro Max's battery would be about 6.9% bigger than the iPhone 16 Pro Max, 13.1% more than the iPhone 15 Pro Max, and 15.7% more than the iPhone 14 Pro Max. If these rumors are accurate, the iPhone 17 Pro Max may finally address one of the most common complaints about Apple's flagship devices, but then again, Apple would still be lagging as most of the brands, specially the Chinese ones have already moved to the battery limits of 6000mAh and some have even touched 7000mAh. This rumor comes after the observation that Apple's struggles with AI may prompt it to transition Siri to either OpenAI or Anthropic's AI capabilities. Image source: Digit.in
  • Recent Achievements

    • Week One Done
      Devesh Beri earned a badge
      Week One Done
    • Week One Done
      956400 earned a badge
      Week One Done
    • First Post
      loose_observer earned a badge
      First Post
    • Week One Done
      BeeJay_Balu earned a badge
      Week One Done
    • Week One Done
      filminutz earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      465
    2. 2
      ATLien_0
      159
    3. 3
      +FloatingFatMan
      149
    4. 4
      Nick H.
      66
    5. 5
      +thexfile
      62
  • Tell a friend

    Love Neowin? Tell a friend!