求助,怎样编写windows窗口程序内嵌unity3d的窗口

求助,怎样编写windows窗口程序内嵌unity3d的窗口,第1张

首先要将unity3d的工程发布成网页版,然后有两种方式实现你要的目标:

用Visual Studio编写一个软件(用C#、VB、VC++各种语言都可以),在窗体中放一个WebBrowser控件,然后将WebBrowser控件的url属性设置为需要显示的页面文件(嵌入了unity3d文件)的路径,这样看起来就是一个独立的软件了。

原理同上,安装了unitywebplayer插件后,在窗体中放一个UnityWebPlayer Control控件(要添加COM组件到工具箱),将控件的src属性设为你需要显示的unity3d文件路径,这样也可以成为一个独立运行的软件,还可以通过组件的SendMessage方法与场景交互。效果如下:

问一句,你是调用还是直接嵌入?下面是直接嵌入的,你改改,这是我以前用到的

using System;

using SystemCollections;

using SystemComponentModel;

using SystemDrawing;

using SystemData;

using SystemWindowsForms;

using SystemRuntimeInteropServices;

namespace WinWordControl

{

public class DocumentInstanceException : Exception

{}

public class ValidDocumentException : Exception

{}

public class WordInstanceException : Exception

{}

public class WinWordControl : SystemWindowsFormsUserControl

{

[DllImport("user32dll")]

public static extern int FindWindow(string strclassName, string strWindowName);

[DllImport("user32dll")]

static extern int SetParent( int hWndChild, int hWndNewParent);

[DllImport("user32dll", EntryPoint="SetWindowPos")]

static extern bool SetWindowPos(

int hWnd, // handle to window

int hWndInsertAfter, // placement-order handle

int X, // horizontal position

int Y, // vertical position

int cx, // width

int cy, // height

uint uFlags // window-positioning options

);

[DllImport("user32dll", EntryPoint="MoveWindow")]

static extern bool MoveWindow(

int爃Wnd,

int X,

int Y,

int爊Width,

int爊Height,

bool燽Repaint

);

const int SWP_DRAWFRAME = 0x20;

const int SWP_NOMOVE = 0x2;

const int SWP_NOSIZE = 0x1;

const int SWP_NOZORDER = 0x4;

private WordDocument document;

private static WordApplicationClass wd = null;

public static int wordWnd = 0;

private static string filename = null;

private static bool deactivateevents = false;

/// <summary>

/// needed designer variable

/// </summary>

private SystemComponentModelContainer components = null;

public WinWordControl()

{

InitializeComponent();

}

/// <summary>

/// cleanup Ressources

/// </summary>

protected override void Dispose( bool disposing )

{

CloseControl();

if( disposing )

{

if( components != null )

componentsDispose();

}

baseDispose( disposing );

}

#region Component Designer generated code

/// <summary>

/// !do not alter this code! It's designer code

/// </summary>

private void InitializeComponent()

{

//

// WinWordControl

//

thisName = "WinWordControl";

thisSize = new SystemDrawingSize(440, 336);

thisResize += new SystemEventHandler(thisOnResize);

}

#endregion

/// <summary>

/// Preactivation

/// It's usefull, if you need more speed in the main Program

/// so you can preload Word

/// </summary>

public void PreActivate()

{

if(wd == null) wd = new WordApplicationClass();

}

/// <summary>

/// Close the current Document in the control --> you can

/// load a new one with LoadDocument

/// </summary>

public void CloseControl()

{

/

this code is to reopen Word

/

try

{

deactivateevents = true;

object dummy=null;

documentClose(ref dummy, ref dummy, ref dummy);

documentApplicationQuit(ref dummy, ref dummy, ref dummy);

deactivateevents = false;

}

catch

{

}

}

/// <summary>

/// catches Word's close event

/// starts a Thread that send a ESC to the word window ;)

/// </summary>

/// <param name="doc"></param>

/// <param name="test"></param>

private void OnClose(WordDocument doc, ref bool chancel)

{

if(!deactivateevents)

{

chancel=true;

}

}

/// <summary>

/// catches Word's open event

/// just close

/// </summary>

/// <param name="doc"></param>

private void OnOpenDoc(WordDocument doc)

{

OnNewDoc(doc);

}

/// <summary>

/// catches Word's newdocument event

/// just close

/// </summary>

/// <param name="doc"></param>

private void OnNewDoc(WordDocument doc)

{

if(!deactivateevents)

{

deactivateevents=true;

object dummy = null;

docClose(ref dummy,ref dummy,ref dummy);

deactivateevents=false;

}

}

/// <summary>

/// catches Word's quit event

/// normally it should not fire, but just to be shure

/// safely release the internal Word Instance

/// </summary>

private void OnQuit()

{

//wd=null;

}

先对父窗体进行属性设置,设置IsMdiContainer的值为true;然后在从父窗体转向子窗体时,添加一句代码:ssgMdiParent = this;,其中,ssg为子窗体创建的对象名。

下面的代码可以强行把一个空白的记事本放到自己的窗体上运行,就像王老虎抢亲一样:

Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Sub Form_Load()

SetParent FindWindow(vbNullString, "无标题 - 记事本"), MeHWnd

MeWindowState = 2

End Sub

运行本程序之前请先启动记事本。

设置一个button按钮,将其click事件添加如下代码:

SystemDiagnosticsProcessStart(@“E:\……”);

双引号里面是你的安装路径,找到路径文件夹里的启动图标,将路径复制即可。

以上就是关于求助,怎样编写windows窗口程序内嵌unity3d的窗口全部的内容,包括:求助,怎样编写windows窗口程序内嵌unity3d的窗口、c# 嵌入一个外部程序 如何让这个外部程序窗口最大化、c#的form窗体中如何嵌套外部应用程序的窗体等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/10104712.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-05
下一篇 2023-05-05

发表评论

登录后才能评论

评论列表(0条)

保存