从任务栏隐藏启动最小化的应用程序图标

从任务栏隐藏启动最小化的应用程序图标

我需要隐藏从任务栏最小化启动的应用程序图标,例如,当您启动最小化的程序时,如何隐藏从任务栏启动的应用程序?我说的不是右侧带有 ^ 的托盘图标,而是中间的任务栏。

答案1

隐藏任务栏按钮隐藏或显示任务栏上的窗口。

这使用了 Windows 10 中的内置编译器 - 有三个 VB.NET 编译器和三个 C# 编译器

正常的窗口(带有系统菜单的标题栏)会显示在任务栏上。想要显示在任务栏上但不符合要求的窗口可以设置 AppWindow 的扩展窗口样式。要从任务栏中删除窗口,需要隐藏窗口、强制将其添加到任务栏的 AppWindow 扩展样式被删除,并应用工具面板窗口的扩展样式。然后显示窗口。新窗口将没有标题栏图标。

这不适用于 UWP 应用程序,仅适用于 Win32 应用程序和控制台。

如果您在最小化窗口上运行此程序,则无法激活该窗口。如果需要,请参阅为窗口分配热键。如果您在非最小化程序上运行此程序,然后最小化该程序,则会出现 Windows 3.11 最小化桌面图标。

只需将每个文本文件复制到同一文件夹中,然后双击批处理文件即可制作程序。


@Echo Off
Echo HideTaskbarBtn.bat
Echo This file compiles HideTaskbarBtn.vb to HideTaskbarBtn.exe
Echo HideTaskbarBtn.exe hides or shows a window'a button on the taskbar
Echo To use 
Echo     HideTaskbarBtn Hide <Window Title>
Echo     HideTaskbarBtn Show <Window Title>
Echo E.G.
Echo     HideTaskbarBtn Hide Untitled - Notepad
Echo     HideTaskbarBtn Show Untitled - Notepad
Echo -----------------------------------------------------
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /target:winexe /out:"%~dp0\HideTaskbarBtn.exe" "%~dp0\HideTaskbarBtn.vb" 
pause

'HideTaskbarBtn.vb
Imports System
Imports System.IO
Imports System.Runtime.InteropServices
Imports Microsoft.Win32

Public Module TopMost
    Public Declare UNICODE Function FindWindowW Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
    Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As IntPtr, ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer
    Public Declare Function SetWindowLongPtrW Lib "user32" (ByVal hwnd As IntPtr, ByVal Index As Integer, ByVal NewValue As Integer) As Integer
    Public Declare Function GetWindowLongPtrW Lib "user32" (ByVal hwnd As IntPtr, ByVal Index As Integer) As Integer
    Public Declare Function GetParent Lib "user32.dll" (ByVal hwnd As Intptr) As IntPtr

    Public Const WS_EX_APPWINDOW = &h40000
    Public Const WS_EX_TOOLWINDOW = &h80
    Public Const WS_MINIMIZEBOX = &h20000
    Public Const GWL_EXSTYLE = -20
    Public Const GWL_STYLE = -16

    Public Const HWND_TOPMOST = -1
    Public Const HWND_NOTOPMOST = -2
    Public Const SWP_NOMOVE = &H2
    Public Const SWP_NOSIZE = &H1
    Public Const SWP_SHOWWINDOW = &H40
    Public Const SWP_HIDEWINDOW = &H80
    Public Const SWP_NOOWNERZORDER = &H200      '  Don't do owner Z ordering
    Public Const SWP_NOREDRAW = &H8
    Public Const SWP_NOREPOSITION = &H200
    Public Const SWP_NOZORDER = &H4

    Sub Main()
        On Error Resume Next
        Dim hWindows as IntPtr
        Dim CmdLine as String
        Dim Ret as Integer
        Dim ExStyle as Integer
        Dim Style as Integer
        CmdLine = Mid(Command(),6)
        hwindows = FindWindowW(vbNullString, CmdLine)
        If hwindows = 0 then
            Msgbox(Cmdline & " cannot be found.")
        Else
            If LCase(Left(Command(), 4)) = LCase("Hide") then
                Ret = GetWindowLongPtrW(hWindows, GWL_EXSTYLE)
                ExStyle = Ret
                'Test AppWindow is set and if so remove it
                If (ExStyle And WS_EX_APPWINDOW) = WS_EX_APPWINDOW then ExStyle = ExStyle - WS_EX_APPWINDOW
                If (ExStyle And WS_EX_TOOLWINDOW) <> WS_EX_TOOLWINDOW then ExStyle = ExStyle + WS_EX_TOOLWINDOW
                Ret = SetWindowPos(hwindows, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE + SWP_NOZORDER + SWP_HIDEWINDOW)
                Ret = GetWindowLongPtrW(hWindows, GWL_EXSTYLE)
                'SetWindowLongPtr does not clear GetLastError if sucessful.
                err.clear
                Ret = SetWindowLongPtrW(hWindows, GWL_EXSTYLE, ExStyle)
                If (Ret = 0 And err.LastDLLError <> 0) Then MsgBox("SetWindowLongPtrW is " & Err.LastDllError)
                err.clear
'               Ret = SetWindowLongPtrW(hWindows, GWL_STYLE, Style)
'               If (Ret = 0 And err.LastDLLError <> 0) Then MsgBox("SetWindowLongPtrW is " & Err.LastDllError)
                Ret = SetWindowPos(hwindows, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE + SWP_NOZORDER + SWP_SHOWWINDOW)
                If Ret = 0 Then MsgBox("Set Pos Error is " & Err.LastDllError)
            ElseIf LCase(Left(Command(), 4)) = LCase("Show") then
                Ret = GetWindowLongPtrW(hWindows, GWL_EXSTYLE)
                'Test AppWindow is set and if so remove it
                ExStyle = Ret
                If (ExStyle And WS_EX_APPWINDOW) <> WS_EX_APPWINDOW then ExStyle = ExStyle + WS_EX_APPWINDOW
                If (ExStyle And WS_EX_TOOLWINDOW) = WS_EX_TOOLWINDOW then ExStyle = ExStyle - WS_EX_TOOLWINDOW
                Ret = SetWindowPos(hwindows, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE + SWP_NOZORDER + SWP_HIDEWINDOW)
                If Ret = 0 Then MsgBox("Set Pos Error is " & Err.LastDllError)
                err.clear
                Ret = SetWindowLongPtrW(hWindows, GWL_EXSTYLE, ExStyle)
                If (Ret = 0 And err.LastDLLError <> 0) Then MsgBox("SetWindowLongPtrW is " & Err.LastDllError)
                Ret = SetWindowPos(hwindows, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE + SWP_NOZORDER + SWP_SHOWWINDOW)
                If Ret = 0 Then MsgBox("Set Pos Error is " & Err.LastDllError)
            Else
                Msgbox("Command line not recognised")
            End If
        End If
    End Sub
End Module

https://winsourcecode.blogspot.com/2021/04/this-uses-inbuilt-compilers-in-windows.html


使用

    HideTaskbarBtn Hide Untitled - Notepad

相关内容