📜 ⬆️ ⬇️

Hiding the Start button, taskbar, watch

With the help of several Windows API functions , you can hide the Start button, the taskbar, or some of its elements. I did this before using Visual Basic 6.0, Delphi, C ++, Visual Basic .NET on Windows 98 / Me / XP. Let's try to do it now using C # on Windows 7. This example has no practical value, it can only be a joke. But nevertheless, an example can serve as a good demonstration of the possibilities that hide the system functions of Windows.

A bit of theory. Very often, programmers want to access the standard interface elements of the Windows Desktop. For novice programmers, it will be interesting to know that the taskbar and the Start button are windows (the name of the operating system itself). Therefore, all we need is to get the window's descriptor, and then use the appropriate functions to hide or show this window.


To get a window handle, you need to know the name of the class.
')
For the taskbar, this is the Shell_TrayWnd class.
for the Start Button - Button
for notification area - TrayNotifyWnd
for the system clock area - TrayClockWClass


We will need all several functions for such a daunting task.
[DllImport("user32.dll")] private static extern IntPtr FindWindow(string ClassName, string WindowName); [DllImport("user32.dll")] private static extern IntPtr FindWindowEx( IntPtr hwndParent, IntPtr hwndChildAfter, string className, string windowName); [DllImport("user32.dll")] private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] static extern bool SetWindowPos( IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, SetWindowPosFlags uFlags); 


Now we will declare several variables for each element.

 private IntPtr TaskbarHWnd; //    private IntPtr StartButtonHWnd; //    private IntPtr TrayNotifyHWnd; //    private IntPtr ClockHwnd; //     


Preliminary preparations are ready. You can start hiding / showing the taskbar items

Task bar

To hide the taskbar, you need to find its handle and hide the window using the ShowWindow function .

 //    .     //     TaskbarHWnd = FindWindow("Shell_TrayWnd", null); // /   if (TaskbarHWnd != IntPtr.Zero) { ShowWindow(TaskbarHWnd, show ? SW_SHOW : SW_HIDE); } show = !show; 

Start button

It should be noted that the previous code is hidden only the taskbar, and the START button at the same time remains visible. Although earlier in Windows 98 / XP, the START button was part of the taskbar and was hidden with it (if you remember, it really was a rectangular button). To hide the button itself, you will have to call a couple of functions again:

 StartButtonHWnd = FindWindow("Button", null); if (StartButtonHWnd != IntPtr.Zero) { //ShowWindow(StartButtonHWnd, show ? SW_SHOW : SW_HIDE); //   Windows XP SetWindowPos(StartButtonHWnd, IntPtr.Zero, 0, 0, 0, 0, show ? SetWindowPosFlags.SWP_SHOWWINDOW : SetWindowPosFlags.SWP_HIDEWINDOW); } 


As you can see, this time we use another function, SetWindowPos , to hide the button, since ShowWindow now does not hide it, as it was before. It is worth noting that when you click again, the START button does not appear independently on the screen. It is necessary to move the mouse pointer to the place where the START is located, and the button will be drawn again. Probably, you can call any function that would force the button to be drawn on the screen, but I did not bother with it. If you find a solution, send it to me.

Accordingly, you can hide only the START button, without touching the taskbar itself.
Notification area

The notification area hides on the same principle as the taskbar.

 TaskbarHWnd = FindWindow("Shell_TrayWnd", null); TrayNotifyHWnd = FindWindowEx(TaskbarHWnd, IntPtr.Zero, "TrayNotifyWnd", null); //    ShowWindow(TrayNotifyHWnd, show ? SW_HIDE : SW_SHOW); show = !show; 


Clock

In the previous example, we hid the notification area along with the watch. To hide only the watch, without touching the notification area, you need to try a little. First we find the notification area descriptor, and then we find its child window TrayClockWClass

 TaskbarHWnd = FindWindow("Shell_TrayWnd", null); TrayNotifyHWnd = FindWindowEx(TaskbarHWnd, IntPtr.Zero, "TrayNotifyWnd", null); //    ClockHwnd = FindWindowEx(TrayNotifyHWnd, IntPtr.Zero, "TrayClockWClass", null); //    ShowWindow(ClockHwnd, show ? SW_HIDE : SW_SHOW); show = !show; 

image

Source: https://habr.com/ru/post/181049/


All Articles