简体   繁体   中英

Problem in hiding the taskbar using c#

i am using the below class to hid the task bar. but the problem is, after hiding there is no focus in that place. Its something like blocked. How to overcome this. Thanks.

public class Taskbar
{
    [DllImport("user32.dll")]
    public static extern int FindWindow(string className, string windowText);
    [DllImport("user32.dll")]
    public static extern int ShowWindow(int hwnd, int command);

    public const int SW_HIDE = 0;
    public const int SW_SHOW = 1;

    public int _taskbarHandle;
    protected static int Handle
    {
        get
        {
            return FindWindow("Shell_TrayWnd", "");
        }
    }

    public Taskbar()
    {
        _taskbarHandle = FindWindow("Shell_TrayWnd", "");
    }

    public static void Show()
    {
        ShowWindow(Handle, SW_SHOW);
    }

    public static void Hide()
    {
        ShowWindow(Handle, SW_HIDE);
    }
}

Are you trying to run a full screen application? If yes then read How To Cover the Task Bar with a Window and How To Make a Windows Form App Truly Full Screen (and Hide Taskbar) in C#

From the same article, you can use this code to run true full screen application

public class WinApi
{
    [DllImport(”user32.dll”, EntryPoint = “GetSystemMetrics”)]
    public static extern int GetSystemMetrics(int which);

    [DllImport(”user32.dll”)]
    public static extern void
        SetWindowPos(IntPtr hwnd, IntPtr hwndInsertAfter,
                     int X, int Y, int width, int height, uint flags);        

    private const int SM_CXSCREEN = 0;
    private const int SM_CYSCREEN = 1;
    private static IntPtr HWND_TOP = IntPtr.Zero;
    private const int SWP_SHOWWINDOW = 64; // 0×0040

    public static int ScreenX
    {
        get { return GetSystemMetrics(SM_CXSCREEN);}
    }

    public static int ScreenY
    {
        get { return GetSystemMetrics(SM_CYSCREEN);}
    }

    public static void SetWinFullScreen(IntPtr hwnd)
    {
        SetWindowPos(hwnd, HWND_TOP, 0, 0, ScreenX, ScreenY, SWP_SHOWWINDOW);
    }
}

Use this code:

public class FullScreenEngine
{
    // Fields
    private IntPtr _hWndInputPanel;
    private IntPtr _hWndSipButton;
    private IntPtr _hWndTaskBar;
    private Rectangle _desktopArea;

    public FullScreenEngine()
    {
        Init();
    }

    public bool SetFullScreen(bool mode)
    {
        try
        {
            if (mode)
            {
                if (_hWndTaskBar.ToInt64() != 0L)
                {
                    ShowWindow(_hWndTaskBar, SW_HIDE);
                }
                if (_hWndInputPanel.ToInt64() != 0L)
                {
                    ShowWindow(_hWndInputPanel, SW_HIDE);
                }
                if (_hWndSipButton.ToInt64() != 0L)
                {
                    ShowWindow(_hWndSipButton, SW_HIDE);
                }
                WorkArea.SetWorkArea(new RECT(Screen.PrimaryScreen.Bounds));
            }
            else
            {
                if (_hWndTaskBar.ToInt64() != 0L)
                {
                    ShowWindow(_hWndTaskBar, SW_SHOW);
                }
                if (_hWndInputPanel.ToInt64() != 0L)
                {
                    //ShowWindow(_hWndInputPanel, SW_SHOW);
                }
                if (_hWndSipButton.ToInt64() != 0L)
                {
                    ShowWindow(_hWndSipButton, SW_SHOW);
                }
                WorkArea.SetWorkArea(new RECT(_desktopArea));
            }
        }
        catch (Exception)
        {
            return false;
        }
        return true;
    }

    private bool Init()
    {
        try
        {
            _desktopArea = Screen.PrimaryScreen.WorkingArea;
            _hWndInputPanel = FindWindowW("SipWndClass", null);
            _hWndSipButton = FindWindowW("MS_SIPBUTTON", null);
            _hWndTaskBar = FindWindowW("HHTaskBar", null);
        }
        catch (Exception)
        {
            return false;
        }
        return true;
    }

    private const uint SW_HIDE = 0;
    private const uint SW_SHOW = 1;

    [DllImport("coredll.dll")]
    private static extern int ShowWindow(IntPtr hwnd, uint command);

    [DllImport("coredll.dll")]
    private static extern IntPtr FindWindowW(string lpClassName, string lpWindowName);

    // Nested Types
    public struct RECT
    {
        public int Left;
        public int Top;
        public int Right;
        public int Bottom;

        public RECT(Rectangle rect) : this()
        {
            Left = rect.Left;
            Right = rect.Left+rect.Width;
            Top = rect.Top;
            Bottom = rect.Top + rect.Height;
        }
    }

    private static class WorkArea
    {
        [DllImport("coredll.dll")]
        private static extern bool SystemParametersInfo(uint uAction, uint uparam, ref RECT rect, uint fuWinIni);

        private const uint WM_SETTINGCHANGE = 0x1a;
        const uint SPI_GETWORKAREA = 48;
        const uint SPI_SETWORKAREA = 47;

        public static bool SetWorkArea(RECT rect)
        {
            return SystemParametersInfo(SPI_SETWORKAREA, 0, ref rect, WM_SETTINGCHANGE);
        }

        public static RECT GetWorkArea()
        {
            var rect = new RECT();
            SystemParametersInfo(SPI_GETWORKAREA, 0, ref rect, 0);
            return rect;
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM