Hide the status bar and keep it at the front



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LockWin
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            FormBorderStyle = FormBorderStyle.None;
            WindowState = FormWindowState.Maximized;

            this.BringToFront();
            this.TopMost = true;

            Thread t1 = new Thread(new ThreadStart(TestMethod));
            t1.Start();

            this.FormClosing += Form1_FormClosing;
            this.FormClosed += Form1_FormClosed;

            ClsWin32.HideTask(true);
        }

        void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            ClsWin32.HideTask(false);
        }

        void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
        }

        public delegate void MyInvoke();

        private void TestMethod()
        {
            Thread.Sleep(1000);

            MyInvoke mi = new MyInvoke(MyBringToFront);
            BeginInvoke(mi);
        }

        public void MyBringToFront()
        {
            this.BringToFront();
            this.TopMost = true;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ClsWin32.HideTask(false);
        }
    }


    class ClsWin32
    {
        [DllImport("user32.dll")]
        public static extern bool GetCursorPos(ref Point lpPoint);

        [DllImport("user32.dll", EntryPoint = "FindWindowEx", SetLastError = true)]
        public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

        [DllImport("user32.dll", EntryPoint = "ShowWindow", SetLastError = true)]
        public static extern bool ShowWindow(IntPtr hWnd, uint nCmdShow);

        public static Point GetCursorPos()
        {
            Point point = new Point();
            GetCursorPos(ref point);
            return point;
        }

        public static void HideTask(bool isHide)
        {
            try
            {
                IntPtr trayHwnd = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "Shell_TrayWnd", null);
                IntPtr hStar = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "Button", null);

                if (isHide)
                {
                    ShowWindow(trayHwnd, 0);
                    ShowWindow(hStar, 0);
                }
                else
                {
                    ShowWindow(trayHwnd, 1);
                    ShowWindow(hStar, 1);
                }
            }
            catch { }
        }
    }
}



Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326560638&siteId=291194637