forked from Oliviaophia/SmartTaskbar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stop taskbar default hiding behavior.
- Loading branch information
1 parent
e07f5ea
commit 78ab275
Showing
24 changed files
with
360 additions
and
3 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using System.Threading; | ||
using EasyHook; | ||
|
||
namespace SmartTaskbar.Hook | ||
{ | ||
public class InjectionEntryPoint : IEntryPoint | ||
{ | ||
private readonly ServerInterface _server; | ||
|
||
public InjectionEntryPoint(RemoteHooking.IContext context, | ||
string channelName) | ||
{ | ||
_server = RemoteHooking.IpcConnectClient<ServerInterface>(channelName); | ||
_server.Ping(); | ||
} | ||
|
||
public void Run(RemoteHooking.IContext context, | ||
string channelName) | ||
{ | ||
_server.Ping(); | ||
var postMessageHook = LocalHook.Create( | ||
LocalHook.GetProcAddress("user32.dll", "PostMessageW"), | ||
new PostMessageDelegate(PostMessageHook), | ||
this); | ||
postMessageHook.ThreadACL.SetExclusiveACL(new[] {0}); | ||
RemoteHooking.WakeUpProcess(); | ||
try | ||
{ | ||
while (true) | ||
{ | ||
Thread.Sleep(1000); | ||
|
||
if (!Mutex.TryOpenExisting("{959d3545-aa5c-42a8-a327-6e2c079daa94}", out _)) | ||
break; | ||
|
||
_server.Ping(); | ||
} | ||
} | ||
finally | ||
{ | ||
postMessageHook?.Dispose(); | ||
LocalHook.Release(); | ||
} | ||
} | ||
|
||
#region GetProcessId | ||
|
||
/// <summary> | ||
/// Retrieves the identifier of the thread that created the specified window and, optionally, the identifier of the | ||
/// process that created the window. | ||
/// </summary> | ||
/// <param name="hWnd">A handle to the window.</param> | ||
/// <param name="lpdwProcessId"> | ||
/// A pointer to a variable that receives the process identifier. If this parameter is not | ||
/// NULL, GetWindowThreadProcessId copies the identifier of the process to the variable; otherwise, it does not. | ||
/// </param> | ||
/// <returns>The return value is the identifier of the thread that created the window.</returns> | ||
[DllImport("user32.dll")] | ||
public static extern int GetWindowThreadProcessId(IntPtr hWnd, out int lpdwProcessId); | ||
|
||
#endregion | ||
|
||
#region PostMessage | ||
|
||
/// Return Type: BOOL->int | ||
/// hWnd: HWND->HWND__* | ||
/// Msg: UINT->unsigned int | ||
/// wParam: WPARAM->UINT_PTR->unsigned int | ||
/// lParam: LPARAM->LONG_PTR->int | ||
[DllImport("user32.dll", EntryPoint = "PostMessageW")] | ||
[return: MarshalAs(UnmanagedType.Bool)] | ||
internal static extern bool PostMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam); | ||
|
||
[UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)] | ||
[return: MarshalAs(UnmanagedType.Bool)] | ||
private delegate bool PostMessageDelegate(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam); | ||
|
||
private static bool PostMessageHook(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam) | ||
{ | ||
try | ||
{ | ||
if (hWnd == FindWindow("Shell_TrayWnd", null) | ||
&& msg == 0x05D1) | ||
return false; | ||
|
||
return PostMessage(hWnd, msg, wParam, lParam); | ||
} | ||
catch { return false; } | ||
} | ||
|
||
|
||
[DllImport("user32.dll", CharSet = CharSet.Unicode)] | ||
internal static extern IntPtr FindWindow(string strClassName, string strWindowName); | ||
|
||
#endregion | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
Sources/SmartTaskbar.Win10.Hook/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System.Reflection; | ||
using System.Runtime.InteropServices; | ||
|
||
// 有关程序集的一般信息由以下 | ||
// 控制。更改这些特性值可修改 | ||
// 与程序集关联的信息。 | ||
[assembly: AssemblyTitle("SmartTaskbar.Win10.Hook")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("SmartTaskbar.Win10.Hook")] | ||
[assembly: AssemblyCopyright("Copyright © 2022")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// 将 ComVisible 设置为 false 会使此程序集中的类型 | ||
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 | ||
//请将此类型的 ComVisible 特性设置为 true。 | ||
[assembly: ComVisible(false)] | ||
|
||
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID | ||
[assembly: Guid("537c876f-dd20-4a8a-83fa-d87f2f6f20cb")] | ||
|
||
// 程序集的版本信息由下列四个值组成: | ||
// | ||
// 主版本 | ||
// 次版本 | ||
// 生成号 | ||
// 修订号 | ||
// | ||
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 | ||
//通过使用 "*",如下所示: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.4.3.0")] | ||
[assembly: AssemblyFileVersion("1.4.3.0")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System; | ||
|
||
namespace SmartTaskbar.Hook | ||
{ | ||
public class ServerInterface : MarshalByRefObject | ||
{ | ||
public void Ping() { } | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
Sources/SmartTaskbar.Win10.Hook/SmartTaskbar.Win10.Hook.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{537C876F-DD20-4A8A-83FA-D87F2F6F20CB}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>SmartTaskbar.Hook</RootNamespace> | ||
<AssemblyName>SmartTaskbar.Hook</AssemblyName> | ||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<Deterministic>true</Deterministic> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="EasyHook, Version=2.7.7097.0, Culture=neutral, PublicKeyToken=4b580fca19d0b0c5, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\EasyHook.2.7.7097\lib\net40\EasyHook.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Runtime.Remoting" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="InjectionEntryPoint.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="ServerInterface.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Content Include="EasyHook32.dll"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</Content> | ||
<Content Include="EasyHook32Svc.exe"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</Content> | ||
<Content Include="EasyHook64.dll"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</Content> | ||
<Content Include="EasyHook64Svc.exe"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</Content> | ||
<Content Include="EasyLoad32.dll"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</Content> | ||
<Content Include="EasyLoad64.dll"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</Content> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="EasyHook" version="2.7.7097" targetFramework="net48" /> | ||
</packages> |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System; | ||
using System.IO; | ||
using System.Reflection; | ||
using System.Runtime.Remoting; | ||
using System.Runtime.Remoting.Channels.Ipc; | ||
using EasyHook; | ||
using SmartTaskbar.Hook; | ||
|
||
namespace SmartTaskbar | ||
{ | ||
public static class HookHelper | ||
{ | ||
private static int _targetPid; | ||
private static string _channelName; | ||
|
||
private static readonly string InjectionLibrary = | ||
Path.Combine( | ||
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) | ||
?? throw new InvalidOperationException(), | ||
"SmartTaskbar.Hook.dll"); | ||
|
||
private static IpcServerChannel _channel; | ||
|
||
public static void ReleaseHook() | ||
{ | ||
if (_channel is null) return; | ||
|
||
_channel.StopListening(null); | ||
|
||
_channel = null; | ||
_channelName = null; | ||
} | ||
|
||
public static void SetHook() | ||
{ | ||
if (_channel != null) | ||
return; | ||
|
||
_targetPid = TaskbarHelper.GetExplorerId(); | ||
|
||
if (_targetPid == 0) | ||
return; | ||
|
||
_channel = RemoteHooking.IpcCreateServer<ServerInterface>(ref _channelName, WellKnownObjectMode.Singleton); | ||
|
||
RemoteHooking.Inject( | ||
_targetPid, | ||
InjectionLibrary, | ||
InjectionLibrary, | ||
_channelName); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.