using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using drew; using System.Runtime.InteropServices; using System.IO; using System.Threading; using System.Diagnostics;namespace 窗体应用程序 { public partial class Form1 : Form { #region //Windows API [DllImport("user32.dll")] public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("user32.dll")] public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent); [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern int MoveWindow(IntPtr hWnd, int x, int y, int nWidth, int nHeight, bool BRePaint); const int GWL_STYLE = -16; const int WS_CAPTION = 0x00C00000; const int WS_THICKFRAME = 0x00040000; const int WS_SYSMENU = 0X00080000; [DllImport("user32")] private static extern int GetWindowLong(System.IntPtr hwnd, int nIndex); [DllImport("user32")] private static extern int SetWindowLong(System.IntPtr hwnd, int index, int newLong); [DllImport("user32")] private static extern int InvalidateRect(System.IntPtr hwnd, object rect, bool bErase); /// <summary>最大化窗口,最小化窗口,正常大小窗口 /// nCmdShow:0隐藏,3最大化,6最小化,5正常显示 /// </summary> [DllImport("user32.dll", EntryPoint = "ShowWindow")] public static extern int ShowWindow(IntPtr hwnd, int nCmdShow); #endregion public delegate void UpdateUI();//委托用于更新UI Thread startload;//线程用于matlab窗体处理 IntPtr figure1;//图像句柄 public Form1() { InitializeComponent(); }
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using drew;
using System.Runtime.InteropServices;
using System.IO;
using System.Threading;
using System.Diagnostics;namespace 窗体应用程序
{
public partial class Form1 : Form
{
#region //Windows API
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int MoveWindow(IntPtr hWnd, int x, int y, int nWidth, int nHeight, bool BRePaint); const int GWL_STYLE = -16;
const int WS_CAPTION = 0x00C00000;
const int WS_THICKFRAME = 0x00040000;
const int WS_SYSMENU = 0X00080000;
[DllImport("user32")]
private static extern int GetWindowLong(System.IntPtr hwnd, int nIndex); [DllImport("user32")]
private static extern int SetWindowLong(System.IntPtr hwnd, int index, int newLong);
[DllImport("user32")]
private static extern int InvalidateRect(System.IntPtr hwnd, object rect, bool bErase);
/// <summary>最大化窗口,最小化窗口,正常大小窗口
/// nCmdShow:0隐藏,3最大化,6最小化,5正常显示
/// </summary>
[DllImport("user32.dll", EntryPoint = "ShowWindow")]
public static extern int ShowWindow(IntPtr hwnd, int nCmdShow);
#endregion
public delegate void UpdateUI();//委托用于更新UI
Thread startload;//线程用于matlab窗体处理
IntPtr figure1;//图像句柄
public Form1()
{
InitializeComponent();
}
private void button4_Click(object sender, EventArgs e)
{
string text = textBox1.Text;
if(text == "")
{
return;
}
Process.Start("iexplore", text);
} private void button1_Click(object sender, EventArgs e)
{
//通过一个进程打开指定的文件
ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(@"D:\项目\刮板修复\Recesurface and save point\Recesurface and save point\bin\Debug\Recesurface and save point.exe");
//创建进程对象
Process p = new Process();
p.StartInfo = psi;
p.Start();
//Console.ReadKey();
}
private void button5_Click(object sender, EventArgs e)
{
Class1 te = new Class1();
//te.drew();
//多线程处理程序
Thread th = new Thread(te.drew);
th.IsBackground = true;
th.Start();
figure1 = IntPtr.Zero;
//实例化线程,用来初次调用matlab,并把图像窗体放到winform
startload = new Thread(startload_run);
//开始线程
startload.Start();
} private void Form1_Load(object sender, EventArgs e)
{
textBox1.Text = "192.168.1.10";
Control.CheckForIllegalCrossThreadCalls = false;
this.DoubleBuffered = true;//设置本窗体
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲 }
void startload_run()
{
//循环查找figure1窗体
while (figure1 == IntPtr.Zero)
{
//查找matlab的Figure 1窗体
figure1 = FindWindow("SunAwtFrame", "Figure 1");
}
//跨线程,用委托方式执行
UpdateUI update = delegate
{
//设置matlab图像窗体的父窗体为panel
SetParent(figure1,panel1.Handle);
//获取窗体原来的风格
var style = GetWindowLong(figure1, GWL_STYLE);
//设置新风格,去掉标题,不能通过边框改变尺寸
SetWindowLong(figure1, GWL_STYLE, style & ~WS_CAPTION & ~WS_THICKFRAME);
//移动到panel里合适的位置并重绘
MoveWindow(figure1, 0, 0, 400 + 0, 300 + 0, true);
};
panel1.Invoke(update);
//再移动一次,防止显示错误
//Thread.Sleep(100);
//MoveWindow(figure1, 0, 0, panel1.Width + 20, panel1.Height + 40, true);
}
}
}上面是我所有的源码,有没有人帮我看一下