Attach window to window of another process

后端 未结 3 1954
北海茫月
北海茫月 2020-12-09 14:18

My WPF application has more than one window, I want to attach some of these windows to a window of another process. My problem is that once I attach my window it becomes inv

3条回答
  •  时光取名叫无心
    2020-12-09 15:13

    I found that I could do this without even using the setParent call. I used HwndSource class as follows:

    MyWindow window = new MyWindow();
    window.ShowActivated = true;
    
    HwndSourceParameters parameters = new HwndSourceParameters();
    
    parameters.WindowStyle = 0x10000000 | 0x40000000;
    parameters.SetPosition(0, 0);
    parameters.SetSize((int)window.Width, (int)window.Height);
    parameters.ParentWindow = newParent;
    parameters.UsesPerPixelOpacity = true;
    HwndSource src = new HwndSource(parameters);
    
    src.CompositionTarget.BackgroundColor = Colors.Transparent;
    src.RootVisual = (Visual)window.Content;
    

    This is working great now without any problems.

提交回复
热议问题