我正在开发一些运行命令并打开一个MATLAB窗口来绘制图形的应用程序,我需要捕获这个新窗口并在启动它的父窗口窗体中显示它。实际上,MATLAB会打开这个新窗口,但是无论如何要抓住它并将它放在窗口中?谢谢如何在父窗口窗体中显示一个窗口?
0
A
回答
0
我相信你想要的东西就像一个Iframe对象,你把新内容加载到那个容器中,但它感觉它是同一个应用程序的一部分。不幸的是,除非MathLab对象提供了一些可以从应用程序本身使用的ActiveX对象,否则就不能使用它。你可以做的事情是模拟外部exe是使用Win32 API的应用程序的一部分。看看这有助于:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace CarPC
{
public partial class MainForm
{
#region Methods/Consts for Embedding a Window
[DllImport("user32.dll", EntryPoint = "GetWindowThreadProcessId", SetLastError = true,
CharSet = CharSet.Unicode, ExactSpelling = true,
CallingConvention = CallingConvention.StdCall)]
private static extern long GetWindowThreadProcessId(long hWnd, long lpdwProcessId);
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", SetLastError = true)]
private static extern long SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll", EntryPoint = "GetWindowLongA", SetLastError = true)]
private static extern long GetWindowLong(IntPtr hwnd, int nIndex);
[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport("user32.dll", SetLastError = true)]
private static extern long SetWindowPos(IntPtr hwnd, long hWndInsertAfter, long x, long y, long cx, long cy, long wFlags);
[DllImport("user32.dll", SetLastError = true)]
private static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint);
[DllImport("user32.dll", EntryPoint = "PostMessageA", SetLastError = true)]
private static extern bool PostMessage(IntPtr hwnd, uint Msg, int wParam, int lParam);
private const int SWP_NOOWNERZORDER = 0x200;
private const int SWP_NOREDRAW = 0x8;
private const int SWP_NOZORDER = 0x4;
private const int SWP_SHOWWINDOW = 0x0040;
private const int WS_EX_MDICHILD = 0x40;
private const int SWP_FRAMECHANGED = 0x20;
private const int SWP_NOACTIVATE = 0x10;
private const int SWP_ASYNCWINDOWPOS = 0x4000;
private const int SWP_NOMOVE = 0x2;
private const int SWP_NOSIZE = 0x1;
private const int GWL_STYLE = (-16);
private const int WS_VISIBLE = 0x10000000;
private const int WM_CLOSE = 0x10;
private const int WS_CHILD = 0x40000000;
private const int WS_MAXIMIZE = 0x01000000;
#endregion
#region Variables
private Panel gpsPanel;
private IntPtr gpsHandle;
private Process gpsProcess = null;
private ProcessStartInfo gpsPSI = new ProcessStartInfo();
#endregion
private void SetupGPSPanel()
{
//Panel to Contain Controls
this.gpsPanel = new Panel();
this.gpsPanel.Location = new Point(this.LeftBarRight, this.TopBarBottom);
this.gpsPanel.Size = new Size(this.Size.Width - this.LeftBarRight, this.Size.Height - this.TopBarBottom);
this.gpsPanel.Visible = false;
gpsPSI.FileName = "notepad.exe";
gpsPSI.Arguments = "";
gpsPSI.WindowStyle = ProcessWindowStyle.Maximized;
gpsProcess = System.Diagnostics.Process.Start(gpsPSI);
gpsProcess.WaitForInputIdle();
gpsHandle = gpsProcess.MainWindowHandle;
SetParent(gpsHandle, this.gpsPanel.Handle);
SetWindowLong(gpsHandle, GWL_STYLE, WS_VISIBLE + WS_MAXIMIZE);
MoveWindow(gpsHandle, 0,0, this.gpsPanel.Width, this.gpsPanel.Height, true);
this.Controls.Add(gpsPanel);
}
}
}
0
0
你可以简单地建立自己的Matlab的项目作为净或COM对象的组件。所以,你会构建和打包像这样的组件:
- 选择组件的类型建(.NET或COM)
- 加入Matlab代码文件和MEX-文件被作为公共方法来访问你的零件。
- 指定一个定义生成的类型安全API的.Net接口。
- 设置建筑和包装的属性。
- 建立,然后测试你的组件,以确保它的功能。
- 为程序员或最终用户打包组件和MCR。
一旦你完成了这些上面的步骤,你就可以访问Matlab的组件从Visual Studio中的任何其他对象的组成部分。然后,您可以从Matlab和.Net本机传递对象,没有任何问题。
由于数据已被转换;所以它会像任何其他组件一样进行交互。
然后,您可以通过将组件拖动到Windows窗体上进行简单的交互或界面,并像其他任何MDI
一样对待它。
MatlabComponentFrm m = new MatlabComponentFrm();
m.MdiParent = this;
m.Show();
很简单的例子。这在我看来是最简单的。否则,您可以导入或主机可执行文件。你有很多方法可以实现这一点。希望有帮助。
相关问题
- 1. 如何使一个弹出窗口中的URL显示在父窗口上?
- 2. 如何在父窗口顶部显示弹出窗口?
- 3. 在PyQt的一个窗口中显示另一个窗口
- 4. C#在窗口窗体中有一个窗口的多个GUI
- 5. 如何在同一窗口中显示窗体输出并隐藏窗体
- 6. 从另一个子窗口显示一个新的子窗口,但居中它在父窗口
- 7. 在父窗口中显示弹出窗口输入文本值?
- 8. 父窗口点击时,如何在父窗口前面添加父窗口
- 9. 子窗口如何在父窗口调用一个函数?
- 10. 如何父窗口的子窗口
- 11. WPF。如何从另一个窗口隐藏/显示主窗口
- 12. Silverlight子窗口父窗口
- 13. 父窗口和子窗口
- 14. 在父窗口所在的屏幕上显示子窗口
- 15. 如何在显示主窗口之前显示登录窗口
- 16. 在GNOME窗口列表中突出显示一个窗口
- 17. Facebook应用程序在窗口中显示一个窗口
- 18. 窗口不显示在窗口菜单
- 19. 如何知道子窗口父窗口销毁窗口
- 20. 如何知道窗口是子窗口还是父窗口?
- 21. 如何使用COM互操作在窗口窗口中显示Excel窗口
- 22. 如何从JavaScript中的子弹出窗口在父窗口中显示警报?
- 23. 如何通过在父窗口上单击按钮来显示子窗口时禁用父窗口
- 24. 如何在父窗口关闭时从子窗口访问父窗口方法?
- 25. 如何在VSTO AddIn的Excel窗口中心显示窗体窗体
- 26. 如何手动在其父rad窗上显示子rad窗口?
- 27. 哪个窗口字体显示窗口关闭按钮?
- 28. 如何从另一个(父母)打开fancybox窗口,打开第二个窗口后如何保留父窗口?
- 29. 如何在QT中显示主窗口中的另一个窗口
- 30. 显示窗口
您是否正在像'MDI儿童形式'那样对待窗口?我不完全确定你的意思是*抓住它并把它放在我的窗口*中。什么类型的窗口? – Greg
我想你正在开发的应用程序是使用Windows窗体的权利? – Marco