wpf 隐藏windows任务栏栏
时间: 2023-08-12 20:09:23 浏览: 248
你可以使用以下代码来隐藏 Windows 任务栏栏:
```csharp
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
namespace WpfApp
{
public partial class MainWindow : Window
{
[DllImport("user32.dll")]
private static extern IntPtr FindWindow(string className, string windowName);
[DllImport("user32.dll")]
private static extern int ShowWindow(IntPtr hWnd, int nCmdShow);
private const int SW_HIDE = 0;
private const int SW_SHOW = 5;
public MainWindow()
{
InitializeComponent();
}
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
// 获取当前窗口的句柄
IntPtr hWnd = new WindowInteropHelper(this).Handle;
// 隐藏任务栏
ShowWindow(FindWindow("Shell_TrayWnd", ""), SW_HIDE);
ShowWindow(FindWindow("Button", ""), SW_HIDE);
}
}
}
```
这段代码通过调用 Windows API 来隐藏任务栏。在 `OnSourceInitialized` 方法中,我们获取当前窗口的句柄,并使用 `ShowWindow` 函数来隐藏任务栏。
阅读全文