C#在Windows 7中隐藏任务栏

C#在Windows 7中隐藏任务栏,c#,windows-7,fullscreen,taskbar,user32,C#,Windows 7,Fullscreen,Taskbar,User32,我正试图用C#隐藏Windows 7任务栏。我查看了帖子和页面,但按照所有说明操作后,我在底部看到了一个纯黑色的条。 我最终得到了一个任务栏类,如下所示: using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; using System.Diagnostics; public static class Taskbar { [DllIm

我正试图用C#隐藏Windows 7任务栏。我查看了帖子和页面,但按照所有说明操作后,我在底部看到了一个纯黑色的条。 我最终得到了一个任务栏类,如下所示:

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;

public static class Taskbar
{
    [DllImport("user32.dll")]
    private static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);
    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    private static extern bool EnumThreadWindows(int threadId, EnumThreadProc pfnEnum, IntPtr lParam);
    [DllImport("user32.dll", SetLastError = true)]
    private static extern System.IntPtr FindWindow(string lpClassName, string lpWindowName);
    [DllImport("user32.dll", SetLastError = true)]
    private static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);
    [DllImport("user32.dll")]
    private static extern int ShowWindow(IntPtr hwnd, int nCmdShow);
    [DllImport("user32.dll")]
    private static extern uint GetWindowThreadProcessId(IntPtr hwnd, out int lpdwProcessId);

    private const int SW_HIDE = 0;
    private const int SW_SHOW = 5;

    private const string VistaStartMenuCaption = "Start";
    private static IntPtr vistaStartMenuWnd = IntPtr.Zero;
    private delegate bool EnumThreadProc(IntPtr hwnd, IntPtr lParam);

    public static void Show()
    {
        SetVisibility(true);
    }

    public static void Hide()
    {
        SetVisibility(false);
    }

    public static bool Visible
    {
        set { SetVisibility(value); }
    }

    private static void SetVisibility(bool show)
    {
        IntPtr taskBarWnd = FindWindow("Shell_TrayWnd", null);

        IntPtr startWnd = FindWindowEx(taskBarWnd, IntPtr.Zero, "Button", "Start");
        if (startWnd == IntPtr.Zero)
        {
            startWnd = FindWindow("Button", null);

            if (startWnd == IntPtr.Zero)
            {
                startWnd = GetVistaStartMenuWnd(taskBarWnd);
            }
        }

        ShowWindow(taskBarWnd, show ? SW_SHOW : SW_HIDE);
        ShowWindow(startWnd, show ? SW_SHOW : SW_HIDE);
    }

    private static IntPtr GetVistaStartMenuWnd(IntPtr taskBarWnd)
    {
        int procId;
        GetWindowThreadProcessId(taskBarWnd, out procId);

        Process p = Process.GetProcessById(procId);
        if (p != null)
        {
            foreach (ProcessThread t in p.Threads)
            {
                EnumThreadWindows(t.Id, MyEnumThreadWindowsProc, IntPtr.Zero);
            }
        }
        return vistaStartMenuWnd;
    }

    private static bool MyEnumThreadWindowsProc(IntPtr hWnd, IntPtr lParam)
    {
        StringBuilder buffer = new StringBuilder(256);
        if (GetWindowText(hWnd, buffer, buffer.Capacity) > 0)
        {
            Console.WriteLine(buffer);
            if (buffer.ToString() == VistaStartMenuCaption)
            {
                vistaStartMenuWnd = hWnd;
                return false;
            }
        }
        return true;
    }
}
我已拍摄了问题的屏幕截图:

先谢谢你

你试过这个吗

而且

发件人:

Shell32.dll的4.71及更高版本增加了修改任务栏内容的功能。从应用程序中,您现在可以添加、删除和激活任务栏按钮。激活项目不会激活窗口;它在任务栏上显示按下的项目


任务栏修改功能在组件对象模型(COM)对象(CLSID_TaskbarList)中实现,该对象公开了ITaskbarList接口(IID_ITaskbarList)。您必须调用ITaskbarList::HrInit方法来初始化对象。然后,您可以使用ITaskbarList界面的方法修改任务栏的内容。

对我来说,全屏显示您的应用程序更有意义。像这样戳任务栏的内部肯定会引起麻烦


用户可能会对失去任务栏感到恼火。任务栏属于用户而不是应用程序。

如果您有WPF窗口,请将其WindowsStyle设置为None,并将其最大化,它将覆盖整个屏幕(覆盖任务栏)。如果您使用Windows窗体,也可以使用类似的功能。

谢谢。最初我使用Windows窗体,但我意识到WPF要好得多,而且你的建议非常有效!比所有这些更简单、更干净[DLLImport(“user32”)]!我最初的(不起作用的)解决方案是在一页代码上完成的。你也可以在WinForms中完成。这只是一个全屏窗口。我知道,但(至少在我的电脑上)任务栏偶尔会在烦人的时候随机出现+∞ 对于我知道的非常有用的截图,我已经删除了它。