diff --git a/Configuration/LockManager.cs b/Configuration/LockManager.cs index 0014049e..b1c4314e 100644 --- a/Configuration/LockManager.cs +++ b/Configuration/LockManager.cs @@ -4,7 +4,6 @@ using System.IO; using System.Threading; using TweetDuck.Core.Utils; -using TweetLib.Communication; namespace TweetDuck.Configuration{ sealed class LockManager{ @@ -136,13 +135,11 @@ public bool Unlock(){ // Locking process public bool RestoreLockingProcess(int failTimeout){ - if (lockingProcess != null){ - if (lockingProcess.MainWindowHandle == IntPtr.Zero){ // restore if the original process is in tray - Comms.BroadcastMessage(Program.WindowRestoreMessage, (uint)lockingProcess.Id, 0); + if (lockingProcess != null && lockingProcess.MainWindowHandle == IntPtr.Zero){ // restore if the original process is in tray + NativeMethods.BroadcastMessage(Program.WindowRestoreMessage, (uint)lockingProcess.Id, 0); - if (WindowsUtils.TrySleepUntil(() => CheckLockingProcessExited() || (lockingProcess.MainWindowHandle != IntPtr.Zero && lockingProcess.Responding), failTimeout, RetryDelay)){ - return true; - } + if (WindowsUtils.TrySleepUntil(() => CheckLockingProcessExited() || (lockingProcess.MainWindowHandle != IntPtr.Zero && lockingProcess.Responding), failTimeout, RetryDelay)){ + return true; } } diff --git a/Core/Utils/NativeMethods.cs b/Core/Utils/NativeMethods.cs index 631a98b8..5f1c6368 100644 --- a/Core/Utils/NativeMethods.cs +++ b/Core/Utils/NativeMethods.cs @@ -8,6 +8,7 @@ namespace TweetDuck.Core.Utils{ [SuppressMessage("ReSharper", "FieldCanBeMadeReadOnly.Local")] [SuppressMessage("ReSharper", "MemberCanBePrivate.Local")] static class NativeMethods{ + public static readonly IntPtr HWND_BROADCAST = new IntPtr(0xFFFF); public static readonly IntPtr HOOK_HANDLED = new IntPtr(-1); public const int HWND_TOPMOST = -1; @@ -51,6 +52,12 @@ private struct MSLLHOOKSTRUCT{ [DllImport("user32.dll", EntryPoint = "SetWindowPos")] private static extern bool SetWindowPos(int hWnd, int hWndOrder, int x, int y, int width, int height, uint flags); + [DllImport("user32.dll")] + public static extern bool PostMessage(IntPtr hWnd, uint msg, UIntPtr wParam, IntPtr lParam); + + [DllImport("user32.dll")] + public static extern uint RegisterWindowMessage(string messageName); + [DllImport("user32.dll")] private static extern bool GetLastInputInfo(ref LASTINPUTINFO info); @@ -96,13 +103,18 @@ public static void SetFormDisabled(Form form, bool disabled){ } } + public static void BroadcastMessage(uint msg, uint wParam, int lParam){ + PostMessage(HWND_BROADCAST, msg, new UIntPtr(wParam), new IntPtr(lParam)); + } + public static int GetMouseHookData(IntPtr ptr){ return Marshal.PtrToStructure<MSLLHOOKSTRUCT>(ptr).mouseData >> 16; } public static int GetIdleSeconds(){ - LASTINPUTINFO info = new LASTINPUTINFO(); - info.cbSize = LASTINPUTINFO.Size; + LASTINPUTINFO info = new LASTINPUTINFO{ + cbSize = LASTINPUTINFO.Size + }; if (!GetLastInputInfo(ref info)){ return 0; diff --git a/Program.cs b/Program.cs index 934e2128..68c0c931 100644 --- a/Program.cs +++ b/Program.cs @@ -14,7 +14,6 @@ using TweetDuck.Core.Utils; using TweetDuck.Data; using TweetDuck.Updates; -using TweetLib.Communication; namespace TweetDuck{ static class Program{ @@ -70,8 +69,8 @@ private static void Main(){ Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - WindowRestoreMessage = Comms.RegisterMessage("TweetDuckRestore"); - SubProcessMessage = Comms.RegisterMessage("TweetDuckSubProcess"); + WindowRestoreMessage = NativeMethods.RegisterWindowMessage("TweetDuckRestore"); + SubProcessMessage = NativeMethods.RegisterWindowMessage("TweetDuckSubProcess"); if (!WindowsUtils.CheckFolderWritePermission(StoragePath)){ FormMessage.Warning("Permission Error", "TweetDuck does not have write permissions to the storage folder: "+StoragePath, FormMessage.OK); diff --git a/lib/TweetLib.Communication/Comms.cs b/lib/TweetLib.Communication/Comms.cs deleted file mode 100644 index 8d80f67a..00000000 --- a/lib/TweetLib.Communication/Comms.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using TweetLib.Communication.Utils; - -namespace TweetLib.Communication{ - public static class Comms{ - public static void BroadcastMessage(uint msg, uint wParam, int lParam){ - NativeMethods.PostMessage(NativeMethods.HWND_BROADCAST, msg, new UIntPtr(wParam), new IntPtr(lParam)); - } - - public static uint RegisterMessage(string name){ - return NativeMethods.RegisterWindowMessage(name); - } - } -} diff --git a/lib/TweetLib.Communication/TweetLib.Communication.csproj b/lib/TweetLib.Communication/TweetLib.Communication.csproj index 0542899e..675bdfb0 100644 --- a/lib/TweetLib.Communication/TweetLib.Communication.csproj +++ b/lib/TweetLib.Communication/TweetLib.Communication.csproj @@ -36,9 +36,7 @@ </ItemGroup> <ItemGroup> <Compile Include="DuplexPipe.cs" /> - <Compile Include="Utils\NativeMethods.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> - <Compile Include="Comms.cs" /> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> </Project> \ No newline at end of file diff --git a/lib/TweetLib.Communication/Utils/NativeMethods.cs b/lib/TweetLib.Communication/Utils/NativeMethods.cs deleted file mode 100644 index 24cf524f..00000000 --- a/lib/TweetLib.Communication/Utils/NativeMethods.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Runtime.InteropServices; - -namespace TweetLib.Communication.Utils{ - static class NativeMethods{ - public static readonly IntPtr HWND_BROADCAST = new IntPtr(0xFFFF); - - [DllImport("user32.dll")] - public static extern bool PostMessage(IntPtr hWnd, uint msg, UIntPtr wParam, IntPtr lParam); - - [DllImport("user32.dll")] - public static extern uint RegisterWindowMessage(string messageName); - } -} diff --git a/subprocess/Program.cs b/subprocess/Program.cs index 523da573..fd81de54 100644 --- a/subprocess/Program.cs +++ b/subprocess/Program.cs @@ -2,7 +2,7 @@ using System.Diagnostics; using CefSharp; using CefSharp.BrowserSubprocess; -using TweetLib.Communication; +using System.Runtime.InteropServices; namespace TweetDuck.Browser{ static class Program{ @@ -30,9 +30,17 @@ public override void OnBrowserCreated(CefBrowserWrapper wrapper){ base.OnBrowserCreated(wrapper); using(Process me = Process.GetCurrentProcess()){ - Comms.BroadcastMessage(Comms.RegisterMessage("TweetDuckSubProcess"), (uint)me.Id, wrapper.BrowserId); + PostMessage(HWND_BROADCAST, RegisterWindowMessage("TweetDuckSubProcess"), new UIntPtr((uint)me.Id), new IntPtr(wrapper.BrowserId)); } } } + + private static readonly IntPtr HWND_BROADCAST = new IntPtr(0xFFFF); + + [DllImport("user32.dll")] + private static extern bool PostMessage(IntPtr hWnd, uint msg, UIntPtr wParam, IntPtr lParam); + + [DllImport("user32.dll")] + private static extern uint RegisterWindowMessage(string messageName); } } diff --git a/subprocess/TweetDuck.Browser.csproj b/subprocess/TweetDuck.Browser.csproj index 238a375d..1d1d36f9 100644 --- a/subprocess/TweetDuck.Browser.csproj +++ b/subprocess/TweetDuck.Browser.csproj @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> +<?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> @@ -34,12 +34,6 @@ <Compile Include="Program.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> </ItemGroup> - <ItemGroup> - <ProjectReference Include="..\lib\TweetLib.Communication\TweetLib.Communication.csproj"> - <Project>{72473763-4b9d-4fb6-a923-9364b2680f06}</Project> - <Name>TweetLib.Communication</Name> - </ProjectReference> - </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <PropertyGroup> <PostBuildEvent>call "$(DevEnvDir)..\..\VC\Auxiliary\Build\vcvars32.bat"