Click here to Skip to main content
15,886,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hey, i would like to emblem a game build on Unity 3D (i have the .exe and the data folder) in my application made on Visual Studio using C#.

More detailed, i would like something like this : Image Here <img src="http://i.imgur.com/ZpCK1lU.png" height="300" width="430">

I did that using this code :

C#
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WindowsApplication1
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private AppControl.ApplicationControl applicationControl1;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.applicationControl1 = new AppControl.ApplicationControl();
            this.SuspendLayout();
            // 
            // applicationControl1
            // 
            this.applicationControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
            | System.Windows.Forms.AnchorStyles.Left) 
            | System.Windows.Forms.AnchorStyles.Right)));
            this.applicationControl1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.applicationControl1.ExeName = "notepad";
            this.applicationControl1.Location = new System.Drawing.Point(24, 24);
            this.applicationControl1.Name = "applicationControl1";
            this.applicationControl1.Size = new System.Drawing.Size(698, 445);
            this.applicationControl1.TabIndex = 0;
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(750, 511);
            this.Controls.Add(this.applicationControl1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

        private void Form1_Load(object sender, EventArgs e)
        {
            applicationControl1.ExeName = Environment.CurrentDirectory + "\\RLE_Beta10.exe";
        }
	}
}


It works perfect with some applications but with my application and calculator for example it does not work as it should, it does not run the application emblem-ed but it runs it normally.

So, anyone knows how to fix it ?
Posted

1 solution

I don't know what this AppControl.ApplicationControl component is. The SetParent API can be used to "embed" external application "into" an other form, like this:
C#
public partial class Form1 : Form
    {
        [DllImport("user32.dll", SetLastError = true)]
        static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Process p = new Process();
            p.StartInfo.FileName = "Notepad.exe";
            p.Start();
            Thread.Sleep(50);
            SetParent(p.MainWindowHandle, this.Handle);
        }
    }

But a hardware accelerated 3D application will certenly use an overlay, which can not be hosted this way.
 
Share this answer
 
Comments
Member 8688768 13-Jan-15 13:32pm    
AppControl is just component build by someone anyways. Your code works but not on my 3D application. Thanks for answering.

Is there any way i can host a 3d application ?
Zoltán Zörgő 13-Jan-15 14:09pm    
I doubt. As I wrote that is working differently. You could try to find and use the handle of the overlay form instead of the main form (WinSpy++ could help you).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900