隐藏一个桌面窗口或禁用关闭按钮- Windows桌面应用程序



我正在创建一个运行在Windows 8.1 Pro上的Windows桌面应用程序。

在编程上,我可以使用这个属性最小化它:
WindowState.Minimized;

是否有一种方法可以完全隐藏它,或者禁止用户关闭它?

我尝试了所有这些StackOverflow解决方案,但是

它们对我不起作用。

I tried with

private const int GWL_STYLE = -16;
private const int WS_SYSMENU = 0x80000;
[DllImport("user32.dll", SetLastError = true)]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

var hwnd = new WindowInteropHelper(this).Handle;
SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_SYSMENU);

然后我尝试将下面的方法添加到我的windows类

protected override void OnClosing(CancelEventArgs e)
{
   base.OnClosing(e);
   e.Cancel = true;
}

        WindowStyle = WindowStyle.None;

还是运气不好。

我怎样才能得到它?

我正在使用VS2015和WPF

只需在xaml-

中将ShowInTaskBar属性设置为False
ShowInTaskbar="False"

在c#代码中,只需隐藏程序初始化时的窗口:

  public MainWindow()
    {
        InitializeComponent();
        this.Hide();
    }

古德勒克。

最新更新