Matlab窗体Figure嵌入到WPF
萌新一只,想着把遇到的问题和大家分享一下。
matlab的代码如下,
[x,y] = meshgrid(-2:0.1:2);
z = y.*exp(-x.^2-y.^2);
figure(1)
surf(x,y,z)
saveas(gcf,'温度曲面', 'jpg');
output_args=1;
c#的程序如下,
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
//将matlab的figure嵌入到wpf中
public class ControlHost : HwndHost //派生HwndHost
{
[DllImport("user32.dll")]
private static extern int SetParent(IntPtr hWndChild, IntPtr hWndParent);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern uint SetWindowLong(IntPtr hwnd, int nIndex, uint newLong);
[DllImport