3つの異なるアプリケーションを作成しました
アプリケーション 1: 「Hello Word」を表示する 1 つの Window(MainWindow) を持つ WPF アプリケーションです。
アプリケーション 2: WPF アプリケーションです このアプリケーションは、アプリケーション 1 の MainWindow のインスタンスを作成します。
MainWindow window = new MainWindow();
//And it will store it's window handle to some file
string filePath = @"c:\windowHandle.txt";
var windowInteropHelper = new WindowInteropHelper(window);
File.WriteAllText(filePath, windowInteropHelper.EnsureHandle().ToString());
アプリケーション 3: これも WPF アプリケーションで、「アプリケーション 1 を表示」と「アプリケーション 1 を非表示」という 2 つのボタンがあります。
private void show_Click(object sender, RoutedEventArgs e)
{
ShowWindow(GetWindowHandle(), 5);
}
private void hide_Click(object sender, RoutedEventArgs e)
{
ShowWindow(GetWindowHandle(), 0);
}
private int GetWindowHandle()
{
string handle = File.ReadAllText(@"C:\windowHandle.txt");
return Convert.ToInt32(handle);
}
[DllImport("user32.dll")]
private static extern int ShowWindow(int hwnd, int nCmdShow);
次に、アプリケーション 2 とアプリケーション 3 を起動します。アプリケーション 3 から [アプリケーション 1 を表示] ボタンをクリックすると、ウィンドウ (アプリケーション 1) が黒い背景で表示されます。「Hello world」は表示されません。ウィンドウのタイトルが表示されますが、ウィンドウの残りの部分は黒です。
誰かがそれを修正する方法を知っているなら? 私にお知らせください。
私の質問に関して質問がある場合はお知らせください:)。