Is it possible to open a completely foreign software inside your Windo

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 6730 Views - Last Post: 10 June 2009 - 04:28 PM Rate Topic: -----

#1 papuccino1  Icon User is offline

  • His name was Robert Paulson.
  • member icon

Reputation: 63
  • View blog
  • Posts: 1,121
  • Joined: 02-March 08

Is it possible to open a completely foreign software inside your Windo

Posted 09 June 2009 - 06:32 PM

I'm having some ideas for my next project and I gotta strike while the iron is hot. Is it possible to have a program open inside your WindowsForm? To be clear, I mean literally a completely different program. Imagine a create a WinForm with two buttons, I click button1 and software X appears inside that WinForms as a child.

Using MDI Form perhaps?

Just wanna know before I start pouring energy into it and then find out it can't be done. :P

This post has been edited by papuccino1: 09 June 2009 - 06:33 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Is it possible to open a completely foreign software inside your Windo

#2 bodom658  Icon User is offline

  • Villiage Idiom
  • member icon

Reputation: 113
  • View blog
  • Posts: 1,123
  • Joined: 22-February 08

Re: Is it possible to open a completely foreign software inside your Windo

Posted 09 June 2009 - 06:37 PM

Perhaps if you can write a shell that can contain an external process and start from there?
Was This Post Helpful? 0
  • +
  • -

#3 papuccino1  Icon User is offline

  • His name was Robert Paulson.
  • member icon

Reputation: 63
  • View blog
  • Posts: 1,121
  • Joined: 02-March 08

Re: Is it possible to open a completely foreign software inside your Windo

Posted 09 June 2009 - 06:42 PM

Woah! That went completely over my head. :P

Would you please elaborate a bit on that, bodom?
Was This Post Helpful? 0
  • +
  • -

#4 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 774
  • View blog
  • Posts: 5,097
  • Joined: 08-December 08

Re: Is it possible to open a completely foreign software inside your Windo

Posted 09 June 2009 - 06:44 PM

Do you mean it's something like a Virtual Macine or an emulator?
Was This Post Helpful? 0
  • +
  • -

#5 papuccino1  Icon User is offline

  • His name was Robert Paulson.
  • member icon

Reputation: 63
  • View blog
  • Posts: 1,121
  • Joined: 02-March 08

Re: Is it possible to open a completely foreign software inside your Windo

Posted 09 June 2009 - 06:48 PM

I mean a different software. Something like this:

Posted Image
Was This Post Helpful? 0
  • +
  • -

#6 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 774
  • View blog
  • Posts: 5,097
  • Joined: 08-December 08

Re: Is it possible to open a completely foreign software inside your Windo

Posted 09 June 2009 - 06:58 PM

That would require the knowledge of low-level and system programming as you'll have to imlement many of the OS calls and operations to run the software inside your program (basically, that is what such software as Wine and Cedega do on Linux).
Was This Post Helpful? 0
  • +
  • -

#7 papuccino1  Icon User is offline

  • His name was Robert Paulson.
  • member icon

Reputation: 63
  • View blog
  • Posts: 1,121
  • Joined: 02-March 08

Re: Is it possible to open a completely foreign software inside your Windo

Posted 09 June 2009 - 06:59 PM

Hm... that's a bit above what I had imagined.

Do you guys have any other ideas on how I could sort of simulate the idea without actually doing it?
Was This Post Helpful? 0
  • +
  • -

#8 fremgenc  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 119
  • Joined: 15-November 07

Re: Is it possible to open a completely foreign software inside your Windo

Posted 09 June 2009 - 09:35 PM

create a form with a transparant background and size it based on the target programs coordinates.


To get a foreign window, need to use winAPI library so you have to import it

you might have to do more research but these winApi functions should get you started


[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);
e


some c# code, you should get the idea
int hwnd=0;
IntPtr hwndChild=IntPtr.Zero;

//Get a handle for the Calculator Application main window

hwnd=FindWindow(null,"Calculator");
if(hwnd == 0)
{
	if(MessageBox.Show("Couldn't find the calculator" + 
					   " application. Do you want to start it?", 
					   "TestWinAPI", 
					   MessageBoxButtons.YesNo)== DialogResult.Yes)
	{
		System.Diagnostics.Process.Start("Calc");
	}
}
else
{
//Call GetWindowPlacement() here, then place your window around it
}


This post has been edited by fremgenc: 09 June 2009 - 09:36 PM

Was This Post Helpful? 0
  • +
  • -

#10 lesPaul456  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 173
  • View blog
  • Posts: 729
  • Joined: 16-April 09

Re: Is it possible to open a completely foreign software inside your Windo

Posted 10 June 2009 - 08:14 AM

Quote

I'm having some ideas for my next project and I gotta strike while the iron is hot. Is it possible to have a program open inside your WindowsForm? To be clear, I mean literally a completely different program. Imagine a create a WinForm with two buttons, I click button1 and software X appears inside that WinForms as a child.

Using MDI Form perhaps?

Just wanna know before I start pouring energy into it and then find out it can't be done. :P


There is actually a pretty easy way to do this.

First, you need to add a panel to your form. This panel will be used to "host" the application.

Next, you need to the "System.Runtime.InteropServices" and the "System.Diagnostics" namespace to your namespaces:
using System.Diagnostics;
using System.Runtime.InteropServices;



Now, we need setup our WinAPI functions:
[DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hwndChild, IntPtr hwndNewParent);

[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
static extern IntPtr SendMessage(IntPtr hWnd, Int32 Msg, Int32 wParam, Int32 lParam);



Now, inside the button click event, start the process, and set it's parent to the panel. In this example, I will be using notepad:
// Create a new process
Process proc;

// Start the process
proc = Process.Start("notepad.exe");
proc.WaitForInputIdle();

// Set the panel control as the application's parent
SetParent(proc.MainWindowHandle, this.panel1.Handle);

// Maximize application
SendMessage(proc.MainWindowHandle, 274, 61488, 0);



Hope this helps!

**EDIT** In "SendMessage()", 274 and 61488 are commands used to maximize the application. 274 represetns the "WM_SYSCOMMAND" message, which is the message that is sent to a window when the user chooses a command from the window menu. 61488 represents the "SC_MAXIMIZE" wParam, or the type of system command to use. So, by calling "SendMessage()" with these parameters, you are telling the application to maximize itself. **EDIT**

This post has been edited by lesPaul456: 10 June 2009 - 10:49 AM

Was This Post Helpful? 2
  • +
  • -

#11 papuccino1  Icon User is offline

  • His name was Robert Paulson.
  • member icon

Reputation: 63
  • View blog
  • Posts: 1,121
  • Joined: 02-March 08

Re: Is it possible to open a completely foreign software inside your Windo

Posted 10 June 2009 - 08:22 AM

I'll test out your code lesPaul, that look pretty legit! :D

This is great news, I just hope it works how I'm imagining it right now. I'm going to try this out tomorrow. Right now I'm really busy.
Was This Post Helpful? 0
  • +
  • -

#12 lesPaul456  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 173
  • View blog
  • Posts: 729
  • Joined: 16-April 09

Re: Is it possible to open a completely foreign software inside your Windo

Posted 10 June 2009 - 08:29 AM

When you first push the button, it may take a couple seconds to load, so be patient :) .
Was This Post Helpful? 0
  • +
  • -

#13 fremgenc  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 119
  • Joined: 15-November 07

Re: Is it possible to open a completely foreign software inside your Windo

Posted 10 June 2009 - 08:51 AM

lol thats a much better method than the one I suggested.
Was This Post Helpful? 0
  • +
  • -

#14 papuccino1  Icon User is offline

  • His name was Robert Paulson.
  • member icon

Reputation: 63
  • View blog
  • Posts: 1,121
  • Joined: 02-March 08

Re: Is it possible to open a completely foreign software inside your Windo

Posted 10 June 2009 - 09:16 AM

lesPaul, how the hell do you know this?!
Was This Post Helpful? 0
  • +
  • -

#15 lesPaul456  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 173
  • View blog
  • Posts: 729
  • Joined: 16-April 09

Re: Is it possible to open a completely foreign software inside your Windo

Posted 10 June 2009 - 09:35 AM

View Postpapuccino1, on 10 Jun, 2009 - 10:16 AM, said:

lesPaul, how the hell do you know this?!


LOL! I've done a good amount of game programming, in both XNA and MDX. In order to host both of these in a windows forms application, you have do do something similar to this (although similar, the method to host XNA and MDX in a winform app is still very different).

This code has proven particularly useful for hosting games created using the DarkGDK (which uses C++) in C# or VB.Net applications.

This post has been edited by lesPaul456: 10 June 2009 - 09:36 AM

Was This Post Helpful? 0
  • +
  • -

#16 papuccino1  Icon User is offline

  • His name was Robert Paulson.
  • member icon

Reputation: 63
  • View blog
  • Posts: 1,121
  • Joined: 02-March 08

Re: Is it possible to open a completely foreign software inside your Windo

Posted 10 June 2009 - 11:10 AM

lesPaul you're fucking kidding me!? This is exactly what I was looking for!

You're my new favorite person. :D

Now, I just need a way so the window stays put. Using the code above I can move the window around (but only in my form). Who the hell knew C# was this powerful and didn't tell me?! :P

Thanks Paul!
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2