diff --git a/Configuration/LockManager.cs b/Configuration/LockManager.cs index d5258c06..0014049e 100644 --- a/Configuration/LockManager.cs +++ b/Configuration/LockManager.cs @@ -1,9 +1,10 @@ -using System; +using System; using System.ComponentModel; using System.Diagnostics; using System.IO; using System.Threading; using TweetDuck.Core.Utils; +using TweetLib.Communication; namespace TweetDuck.Configuration{ sealed class LockManager{ @@ -137,7 +138,7 @@ public bool Unlock(){ public bool RestoreLockingProcess(int failTimeout){ if (lockingProcess != null){ if (lockingProcess.MainWindowHandle == IntPtr.Zero){ // restore if the original process is in tray - NativeMethods.PostMessage(NativeMethods.HWND_BROADCAST, Program.WindowRestoreMessage, new UIntPtr((uint)lockingProcess.Id), IntPtr.Zero); + Comms.BroadcastMessage(Program.WindowRestoreMessage, (uint)lockingProcess.Id, 0); if (WindowsUtils.TrySleepUntil(() => CheckLockingProcessExited() || (lockingProcess.MainWindowHandle != IntPtr.Zero && lockingProcess.Responding), failTimeout, RetryDelay)){ return true; diff --git a/Core/Controls/ControlExtensions.cs b/Core/Controls/ControlExtensions.cs index c8b02846..dda9871e 100644 --- a/Core/Controls/ControlExtensions.cs +++ b/Core/Controls/ControlExtensions.cs @@ -1,8 +1,9 @@ -using System; +using System; using System.Drawing; using System.Linq; using System.Windows.Forms; using TweetDuck.Core.Utils; +using TweetLib.Communication; namespace TweetDuck.Core.Controls{ static class ControlExtensions{ @@ -70,7 +71,7 @@ public static bool AlignValueToTick(this TrackBar trackBar){ public static void SetElevated(this Button button){ button.Text = " "+button.Text; button.FlatStyle = FlatStyle.System; - NativeMethods.SendMessage(button.Handle, NativeMethods.BCM_SETSHIELD, new UIntPtr(0), new IntPtr(1)); + Comms.SendMessage(button.Handle, NativeMethods.BCM_SETSHIELD, 0, 1); } public static void EnableMultilineShortcuts(this TextBox textBox){ diff --git a/Core/Utils/NativeMethods.cs b/Core/Utils/NativeMethods.cs index b1ab111d..aa19e561 100644 --- a/Core/Utils/NativeMethods.cs +++ b/Core/Utils/NativeMethods.cs @@ -8,7 +8,6 @@ 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; @@ -65,16 +64,7 @@ private struct MSLLHOOKSTRUCT{ [DllImport("gdi32.dll")] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool BitBlt(IntPtr hdc, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, uint dwRop); - - [DllImport("user32.dll")] - public static extern IntPtr SendMessage(IntPtr hWnd, uint msg, UIntPtr wParam, IntPtr lParam); - [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")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool ShowScrollBar(IntPtr hWnd, int wBar, bool bShow); diff --git a/Program.cs b/Program.cs index f99f72b3..f2053f42 100644 --- a/Program.cs +++ b/Program.cs @@ -1,4 +1,4 @@ -using CefSharp; +using CefSharp; using System; using System.Diagnostics; using System.Globalization; @@ -14,6 +14,7 @@ using TweetDuck.Core.Utils; using TweetDuck.Data; using TweetDuck.Updates; +using TweetLib.Communication; namespace TweetDuck{ static class Program{ @@ -70,9 +71,9 @@ private static void Main(){ Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - WindowRestoreMessage = NativeMethods.RegisterWindowMessage("TweetDuckRestore"); - SubProcessMessage = NativeMethods.RegisterWindowMessage("TweetDuckSubProcess"); - VideoPlayerMessage = NativeMethods.RegisterWindowMessage("TweetDuckVideoPlayer"); + WindowRestoreMessage = Comms.RegisterMessage("TweetDuckRestore"); + SubProcessMessage = Comms.RegisterMessage("TweetDuckSubProcess"); + VideoPlayerMessage = Comms.RegisterMessage("TweetDuckVideoPlayer"); if (!WindowsUtils.CheckFolderWritePermission(StoragePath)){ FormMessage.Warning("Permission Error", "TweetDuck does not have write permissions to the storage folder: "+StoragePath, FormMessage.OK); diff --git a/TweetDuck.csproj b/TweetDuck.csproj index c76715e7..807ab681 100644 --- a/TweetDuck.csproj +++ b/TweetDuck.csproj @@ -351,6 +351,10 @@ <Project>{278b2d11-402d-44b6-b6a1-8fa67db65565}</Project> <Name>TweetDuck.Video</Name> </ProjectReference> + <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> diff --git a/TweetDuck.sln b/TweetDuck.sln index 178226c5..ee5b5c76 100644 --- a/TweetDuck.sln +++ b/TweetDuck.sln @@ -12,6 +12,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TweetLib.Audio", "lib\Tweet EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TweetDuck.Video", "video\TweetDuck.Video\TweetDuck.Video.csproj", "{278B2D11-402D-44B6-B6A1-8FA67DB65565}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TweetLib.Communication", "lib\TweetLib.Communication\TweetLib.Communication.csproj", "{72473763-4B9D-4FB6-A923-9364B2680F06}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x86 = Debug|x86 @@ -38,6 +40,10 @@ Global {278B2D11-402D-44B6-B6A1-8FA67DB65565}.Debug|x86.Build.0 = Debug|x86 {278B2D11-402D-44B6-B6A1-8FA67DB65565}.Release|x86.ActiveCfg = Release|x86 {278B2D11-402D-44B6-B6A1-8FA67DB65565}.Release|x86.Build.0 = Release|x86 + {72473763-4B9D-4FB6-A923-9364B2680F06}.Debug|x86.ActiveCfg = Debug|x86 + {72473763-4B9D-4FB6-A923-9364B2680F06}.Debug|x86.Build.0 = Debug|x86 + {72473763-4B9D-4FB6-A923-9364B2680F06}.Release|x86.ActiveCfg = Release|x86 + {72473763-4B9D-4FB6-A923-9364B2680F06}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/lib/TweetLib.Communication/Comms.cs b/lib/TweetLib.Communication/Comms.cs new file mode 100644 index 00000000..2a52a57f --- /dev/null +++ b/lib/TweetLib.Communication/Comms.cs @@ -0,0 +1,34 @@ +using System; +using TweetLib.Communication.Utils; + +namespace TweetLib.Communication{ + public static class Comms{ + public static void SendMessage(IntPtr hWnd, uint msg, uint wParam, int lParam){ + NativeMethods.SendMessage(hWnd, msg, new UIntPtr(wParam), new IntPtr(lParam)); + } + + public static void SendMessage(IntPtr hWnd, uint msg, UIntPtr wParam, IntPtr lParam){ + NativeMethods.SendMessage(hWnd, msg, wParam, lParam); + } + + public static void PostMessage(IntPtr hWnd, uint msg, uint wParam, int lParam){ + NativeMethods.PostMessage(hWnd, msg, new UIntPtr(wParam), new IntPtr(lParam)); + } + + public static void PostMessage(IntPtr hWnd, uint msg, UIntPtr wParam, IntPtr lParam){ + NativeMethods.PostMessage(hWnd, msg, wParam, lParam); + } + + public static void BroadcastMessage(uint msg, uint wParam, int lParam){ + NativeMethods.PostMessage(NativeMethods.HWND_BROADCAST, msg, new UIntPtr(wParam), new IntPtr(lParam)); + } + + public static void BroadcastMessage(uint msg, UIntPtr wParam, IntPtr lParam){ + NativeMethods.PostMessage(NativeMethods.HWND_BROADCAST, msg, wParam, lParam); + } + + public static uint RegisterMessage(string name){ + return NativeMethods.RegisterWindowMessage(name); + } + } +} diff --git a/lib/TweetLib.Communication/Properties/AssemblyInfo.cs b/lib/TweetLib.Communication/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..761f32b1 --- /dev/null +++ b/lib/TweetLib.Communication/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("TweetDuck Communication Library")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("TweetDuck Communication Library")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("72473763-4b9d-4fb6-a923-9364b2680f06")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/lib/TweetLib.Communication/TweetLib.Communication.csproj b/lib/TweetLib.Communication/TweetLib.Communication.csproj new file mode 100644 index 00000000..622ead6a --- /dev/null +++ b/lib/TweetLib.Communication/TweetLib.Communication.csproj @@ -0,0 +1,43 @@ +<?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>{72473763-4B9D-4FB6-A923-9364B2680F06}</ProjectGuid> + <OutputType>Library</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>TweetLib.Communication</RootNamespace> + <AssemblyName>TweetLib.Communication</AssemblyName> + <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion> + <FileAlignment>512</FileAlignment> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'"> + <DebugSymbols>true</DebugSymbols> + <OutputPath>bin\x86\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <DebugType>full</DebugType> + <PlatformTarget>x86</PlatformTarget> + <ErrorReport>prompt</ErrorReport> + <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'"> + <OutputPath>bin\x86\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <Optimize>true</Optimize> + <DebugType>none</DebugType> + <PlatformTarget>x86</PlatformTarget> + <ErrorReport>prompt</ErrorReport> + <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> + </PropertyGroup> + <ItemGroup> + <Reference Include="System" /> + <Reference Include="System.Core" /> + </ItemGroup> + <ItemGroup> + <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/subprocess/NativeMethods.cs b/lib/TweetLib.Communication/Utils/NativeMethods.cs similarity index 70% rename from subprocess/NativeMethods.cs rename to lib/TweetLib.Communication/Utils/NativeMethods.cs index d11e512b..9c43c77a 100644 --- a/subprocess/NativeMethods.cs +++ b/lib/TweetLib.Communication/Utils/NativeMethods.cs @@ -1,9 +1,12 @@ using System; using System.Runtime.InteropServices; -namespace TweetDuck.Browser{ +namespace TweetLib.Communication.Utils{ static class NativeMethods{ public static readonly IntPtr HWND_BROADCAST = new IntPtr(0xFFFF); + + [DllImport("user32.dll")] + public static extern IntPtr SendMessage(IntPtr hWnd, uint msg, UIntPtr wParam, IntPtr lParam); [DllImport("user32.dll")] public static extern bool PostMessage(IntPtr hWnd, uint msg, UIntPtr wParam, IntPtr lParam); diff --git a/subprocess/Program.cs b/subprocess/Program.cs index 0fda1108..ddc61cc4 100644 --- a/subprocess/Program.cs +++ b/subprocess/Program.cs @@ -1,7 +1,8 @@ -using System; +using System; using System.Diagnostics; using CefSharp; using CefSharp.BrowserSubprocess; +using TweetLib.Communication; namespace TweetDuck.Browser{ static class Program{ @@ -26,7 +27,7 @@ public override void OnBrowserCreated(CefBrowserWrapper wrapper){ base.OnBrowserCreated(wrapper); using(Process me = Process.GetCurrentProcess()){ - NativeMethods.PostMessage(NativeMethods.HWND_BROADCAST, NativeMethods.RegisterWindowMessage("TweetDuckSubProcess"), new UIntPtr((uint)me.Id), new IntPtr(wrapper.BrowserId)); + Comms.BroadcastMessage(Comms.RegisterMessage("TweetDuckSubProcess"), (uint)me.Id, wrapper.BrowserId); } } } diff --git a/subprocess/TweetDuck.Browser.csproj b/subprocess/TweetDuck.Browser.csproj index 3de41b00..238a375d 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> @@ -31,10 +31,15 @@ <Reference Include="System" /> </ItemGroup> <ItemGroup> - <Compile Include="NativeMethods.cs" /> <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" diff --git a/video/TweetDuck.Video/FormPlayer.cs b/video/TweetDuck.Video/FormPlayer.cs index 6a9118cc..9ea951f0 100644 --- a/video/TweetDuck.Video/FormPlayer.cs +++ b/video/TweetDuck.Video/FormPlayer.cs @@ -2,6 +2,7 @@ using System.Drawing; using System.Runtime.InteropServices; using System.Windows.Forms; +using TweetLib.Communication; using WMPLib; namespace TweetDuck.Video{ @@ -132,7 +133,7 @@ private void timerSync_Tick(object sender, EventArgs e){ private void timerData_Tick(object sender, EventArgs e){ timerData.Stop(); - NativeMethods.PostMessage(NativeMethods.HWND_BROADCAST, Program.VideoPlayerMessage, new UIntPtr((uint)trackBarVolume.Value), ownerHandle); + Comms.BroadcastMessage(Program.VideoPlayerMessage, new UIntPtr((uint)trackBarVolume.Value), ownerHandle); } private void progressSeek_MouseDown(object sender, MouseEventArgs e){ diff --git a/video/TweetDuck.Video/NativeMethods.cs b/video/TweetDuck.Video/NativeMethods.cs index 7a8fe738..caac6a47 100644 --- a/video/TweetDuck.Video/NativeMethods.cs +++ b/video/TweetDuck.Video/NativeMethods.cs @@ -3,15 +3,7 @@ namespace TweetDuck.Video{ static class NativeMethods{ - public static readonly IntPtr HWND_BROADCAST = new IntPtr(0xFFFF); - private const int GWL_HWNDPARENT = -8; - - [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")] [return: MarshalAs(UnmanagedType.Bool)] diff --git a/video/TweetDuck.Video/Program.cs b/video/TweetDuck.Video/Program.cs index 86e1f767..4e1de6f7 100644 --- a/video/TweetDuck.Video/Program.cs +++ b/video/TweetDuck.Video/Program.cs @@ -1,6 +1,7 @@ using System; using System.Globalization; using System.Windows.Forms; +using TweetLib.Communication; namespace TweetDuck.Video{ static class Program{ @@ -13,7 +14,7 @@ static class Program{ public const int CODE_USER_REQUESTED = 6; private static uint? message; - public static uint VideoPlayerMessage => message ?? (message = NativeMethods.RegisterWindowMessage("TweetDuckVideoPlayer")).Value; + public static uint VideoPlayerMessage => message ?? (message = Comms.RegisterMessage("TweetDuckVideoPlayer")).Value; [STAThread] private static int Main(string[] args){ diff --git a/video/TweetDuck.Video/TweetDuck.Video.csproj b/video/TweetDuck.Video/TweetDuck.Video.csproj index 172af0e7..8789622d 100644 --- a/video/TweetDuck.Video/TweetDuck.Video.csproj +++ b/video/TweetDuck.Video/TweetDuck.Video.csproj @@ -74,5 +74,11 @@ <ItemGroup> <Content Include="Resources\icon.ico" /> </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\..\lib\TweetLib.Communication\TweetLib.Communication.csproj"> + <Project>{72473763-4b9d-4fb6-a923-9364b2680f06}</Project> + <Name>TweetLib.Windows</Name> + </ProjectReference> + </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> </Project> \ No newline at end of file