School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
Welcome to Dream.In.Code
Become an Expert!

Join 340,163 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 4,044 people online right now. Registration is fast and FREE... Join Now!



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

Is it possible to open a completely foreign software inside your Windo Rate Topic: -----

#1 papuccino1  Icon User is offline

  • His name was Robert Paulson.
  • Icon
  • View blog
  • Group: Greeters
  • Posts: 1,121
  • Joined: 02-March 08


Dream Kudos: 50

Posted 09 June 2009 - 05: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 - 05:33 PM

Was This Post Helpful? 0
  • +
  • -


#2 bodom658  Icon User is offline

  • Villiage Idiom
  • Icon
  • View blog
  • Group: Contributors
  • Posts: 832
  • Joined: 22-February 08


Dream Kudos: 325

Posted 09 June 2009 - 05: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.
  • Icon
  • View blog
  • Group: Greeters
  • Posts: 1,121
  • Joined: 02-March 08


Dream Kudos: 50

Posted 09 June 2009 - 05: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 online

  • Jasper
  • Icon
  • View blog
  • Group: Admins
  • Posts: 3,482
  • Joined: 08-December 08


Dream Kudos: 975

Expert In: .NET Framework

Posted 09 June 2009 - 05: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.
  • Icon
  • View blog
  • Group: Greeters
  • Posts: 1,121
  • Joined: 02-March 08


Dream Kudos: 50

Posted 09 June 2009 - 05:48 PM

I mean a different software. Something like this:

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

#6 Core  Icon User is online

  • Jasper
  • Icon
  • View blog
  • Group: Admins
  • Posts: 3,482
  • Joined: 08-December 08


Dream Kudos: 975

Expert In: .NET Framework

Posted 09 June 2009 - 05: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.
  • Icon
  • View blog
  • Group: Greeters
  • Posts: 1,121
  • Joined: 02-March 08


Dream Kudos: 50

Posted 09 June 2009 - 05: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
  • PipPip
  • Group: Members
  • Posts: 119
  • Joined: 15-November 07


Dream Kudos: 0

Posted 09 June 2009 - 08: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 - 08:36 PM

Was This Post Helpful? 0
  • +
  • -

#10 lesPaul456  Icon User is offline

  • D.I.C Regular
  • Icon
  • Group: Authors
  • Posts: 362
  • Joined: 16-April 09


Dream Kudos: 175

Posted 10 June 2009 - 07: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 - 09:49 AM

Was This Post Helpful? 1
  • +
  • -

#11 papuccino1  Icon User is offline

  • His name was Robert Paulson.
  • Icon
  • View blog
  • Group: Greeters
  • Posts: 1,121
  • Joined: 02-March 08


Dream Kudos: 50

Posted 10 June 2009 - 07: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 Regular
  • Icon
  • Group: Authors
  • Posts: 362
  • Joined: 16-April 09


Dream Kudos: 175

Posted 10 June 2009 - 07: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
  • PipPip
  • Group: Members
  • Posts: 119
  • Joined: 15-November 07


Dream Kudos: 0

Posted 10 June 2009 - 07: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.
  • Icon
  • View blog
  • Group: Greeters
  • Posts: 1,121
  • Joined: 02-March 08


Dream Kudos: 50

Posted 10 June 2009 - 08:16 AM

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

#15 lesPaul456  Icon User is offline

  • D.I.C Regular
  • Icon
  • Group: Authors
  • Posts: 362
  • Joined: 16-April 09


Dream Kudos: 175

Posted 10 June 2009 - 08: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 - 08:36 AM

Was This Post Helpful? 0
  • +
  • -

#16 papuccino1  Icon User is offline

  • His name was Robert Paulson.
  • Icon
  • View blog
  • Group: Greeters
  • Posts: 1,121
  • Joined: 02-March 08


Dream Kudos: 50

Posted 10 June 2009 - 10: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
  • +
  • -

#17 lesPaul456  Icon User is offline

  • D.I.C Regular
  • Icon
  • Group: Authors
  • Posts: 362
  • Joined: 16-April 09


Dream Kudos: 175

Posted 10 June 2009 - 11:22 AM

Glad I could help!

I have yet to come up with a solution to prevent the application from moving. I'll look into it later today.

I forgot to mention something earlier; It seems this code doesn't work right with applications created using the .Net Framework, only Win32 applications. I only really use this code, as I mentioned, for games created using the DarkGDK, since they are Win32 apps.

I plan on looking into a solution to hosting .Net applications as well, but this may take some time.

Anyway, if I find a way to keep the window stationary, I'll be sure to post back.
Was This Post Helpful? 0
  • +
  • -

#18 lesPaul456  Icon User is offline

  • D.I.C Regular
  • Icon
  • Group: Authors
  • Posts: 362
  • Joined: 16-April 09


Dream Kudos: 175

Posted 10 June 2009 - 03:28 PM

I figured out how to prevent the user from moving the window.

First, you need to add two more native methods:
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);

[DllImport("user32.dll")]
public static extern bool RemoveMenu(IntPtr hMenu, uint uPosition, uint uFlags);



Next, you need to get the windows menu:
IntPtr hWnd = GetSystemMenu(process.MainWindowHandle, false);



And now we stop the user from moving the window:
RemoveMenu(hWnd, 0xF010, 0x00000000 | 0x00001000);



That's it! Hope this helps!
Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month