jk1350583442 2016-09-01 07:57 采纳率: 0%
浏览 1009
已结题

figure 嵌入wpf,编译提示找不到资源

public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}

    private void HostElement_Loaded(object sender, RoutedEventArgs e)
    {
        ControlHost listControl = new ControlHost(200,300);
        HostElement.Child = listControl;
    }
}

public class ControlHost : HwndHost
{

    // private const int WS_CHILD = 0x40000000;
    [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("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
    private static extern uint GetWindowLong(IntPtr hwnd, int nIndex);

    [DllImport("user32.dll", EntryPoint = "DestroyWindow", CharSet = CharSet.Unicode)]
    internal static extern bool DestroyWindow(IntPtr hwnd);

    IntPtr hwndControl;
    IntPtr hwndHost;
    int hostHeight, hostWidth;
    [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "FindWindow")]
    public static extern IntPtr FindWindow(
              string lpClassName,
              string lpWindowName
             );

    public ControlHost(double height, double width)
    {
        hostHeight = (int)height;
        hostWidth = (int)width;
    }

    protected override HandleRef BuildWindowCore(HandleRef hwndParent)
    {
        hwndControl = IntPtr.Zero;
        hwndHost = IntPtr.Zero;

        Class1 test = new Class1();
        MWArray m = 1, n = 2;
        test.test(m, n);

        Thread.Sleep(1000);

        hwndControl = FindWindow(null, "Figure 1");//Figure 1 是弹出的Figure的名字
        uint oldStyle = GetWindowLong(hwndControl, GWL_STYLE);

        SetWindowLong(hwndControl, GWL_STYLE, (WS_DLGFRAME | WS_CHILD)); // WS_DLGFRAME 是创建一个无标题的窗口     
        //将 嵌入的Figure的父窗口设置为HwndHost 
        SetParent(hwndControl, hwndParent.Handle);

        return new HandleRef(this, hwndControl);
    }

    protected override IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
    {
        handled = false;
        return IntPtr.Zero;
    }

    protected override void DestroyWindowCore(HandleRef hwnd)
    {
        DestroyWindow(hwnd.Handle);
    }
    public IntPtr hwndListBox
    {
        get { return hwndControl; }
    }

    internal const int
     WS_CHILD = 0x40000000,
     WS_VISIBLE = 0x10000000,
     LBS_NOTIFY = 0x00000001,
     HOST_ID = 0x00000002,
     LISTBOX_ID = 0x00000001,
     WS_VSCROLL = 0x00200000,
     WS_BORDER = 0x00800000,
     GWL_STYLE = -16,
     WS_DLGFRAME = 0x00400000;
}

}

  • 写回答

1条回答 默认 最新

  • dabocaiqq 2017-02-08 20:26
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥15 python天天向上类似问题,但没有清零
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?