首页 > 解决方案 > 使用 windowHandle 显示 WPFHidden 窗口

问题描述

我创建了一个 WPF 窗口并向其添加了一些控件。现在我将获取窗口句柄并隐藏窗口。

我将创建单独的应用程序(控制台)并使用windowHandle 下面的 api 来显示窗口

[DllImport("User32")]

private static extern int ShowWindow(int hwnd, int nCmdShow);


但问题是窗口带有黑色背景。不显示控件。

任何人都可以帮助如何完成它。(使用窗口句柄显示 WPF 窗口)

WPF 窗口代码

var windowInteropHelper = new WindowInteropHelper(this);
int tempHandle = (int)windowInteropHelper.Handle;
string filePath = @"C:\windowHandleLog.txt";
if (File.Exists(filePath))
{
    File.Delete(filePath);
}
File.AppendAllText(filePath, tempHandle.ToString());
this.Hide();

控制台应用程序代码:

string filePath = @"C:\windowHandleLog.txt";
string handle = File.ReadAllText(filePath);
int windowHandle = Convert.ToInt32(handle);
ShowWindow(windowHandle, SW_SHOW);

之前的 Wpf 窗口

之后的 Wpf 窗口

标签: c#wpfwindow-handles

解决方案


推荐阅读