diff --git a/Core/Controls/RichTextLabel.cs b/Core/Controls/RichTextLabel.cs index cb52e143..0e8c279c 100644 --- a/Core/Controls/RichTextLabel.cs +++ b/Core/Controls/RichTextLabel.cs @@ -1,5 +1,6 @@ using System; using System.Windows.Forms; +using TweetDck.Core.Utils; namespace TweetDck.Core.Controls{ public partial class RichTextLabel : RichTextBox{ @@ -27,7 +28,7 @@ protected override CreateParams CreateParams{ get{ CreateParams createParams = base.CreateParams; - if (Program.LoadLibrary("msftedit.dll") != IntPtr.Zero){ + if (NativeMethods.LoadLibrary("msftedit.dll") != IntPtr.Zero){ createParams.ClassName = "RICHEDIT50W"; } diff --git a/Core/FormNotification.cs b/Core/FormNotification.cs index 0e4fb0a8..d6b28b72 100644 --- a/Core/FormNotification.cs +++ b/Core/FormNotification.cs @@ -7,6 +7,7 @@ using TweetDck.Configuration; using TweetDck.Core.Handling; using TweetDck.Resources; +using TweetDck.Core.Utils; namespace TweetDck.Core{ sealed partial class FormNotification : Form{ @@ -222,7 +223,7 @@ private void MoveToVisibleLocation(){ } if (needsReactivating){ - Program.SetWindowPos(Handle.ToInt32(),-1,Left,Top,Width,Height,0x0010); // HWND_TOPMOST, SWP_NOACTIVATE + NativeMethods.SetFormPos(this,NativeMethods.HWND_TOPMOST,NativeMethods.SWP_NOACTIVATE); } } diff --git a/Core/Handling/TweetDeckBridge.cs b/Core/Handling/TweetDeckBridge.cs index bc71cd50..40dadef4 100644 --- a/Core/Handling/TweetDeckBridge.cs +++ b/Core/Handling/TweetDeckBridge.cs @@ -126,10 +126,9 @@ public void ClickUploadImage(int offsetX, int offsetY){ Point prevPos = Cursor.Position; Cursor.Position = form.PointToScreen(new Point(offsetX,offsetY)); - Program.mouse_event(SystemInformation.MouseButtonsSwapped ? 0x08 : 0x02,Cursor.Position.X,Cursor.Position.Y,0,0); // MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_LEFTDOWN - Program.mouse_event(SystemInformation.MouseButtonsSwapped ? 0x10 : 0x04,Cursor.Position.X,Cursor.Position.Y,0,0); // MOUSEEVENTF_RIGHTUP | MOUSEEVENTF_LEFTUP - + NativeMethods.SimulateMouseClick(NativeMethods.MouseButton.Left); Cursor.Position = prevPos; + form.OnImagePastedFinish(); }); } diff --git a/Core/Utils/NativeMethods.cs b/Core/Utils/NativeMethods.cs new file mode 100644 index 00000000..9ad1d5a5 --- /dev/null +++ b/Core/Utils/NativeMethods.cs @@ -0,0 +1,56 @@ +using System; +using System.Runtime.InteropServices; +using System.Windows.Forms; + +namespace TweetDck.Core.Utils{ + static class NativeMethods{ + public const int HWND_TOPMOST = -1; + public const uint SWP_NOACTIVATE = 0x0010; + + public const int MOUSEEVENTF_LEFTDOWN = 0x02; + public const int MOUSEEVENTF_LEFTUP = 0x04; + public const int MOUSEEVENTF_RIGHTDOWN = 0x08; + public const int MOUSEEVENTF_RIGHTUP = 0x10; + + public enum MouseButton{ + Left, Right + } + + [DllImport("kernel32.dll", CharSet = CharSet.Auto)] + public static extern IntPtr LoadLibrary(string name); + + [DllImport("Shell32.dll")] + public static extern int SHChangeNotify(int eventId, int flags, IntPtr item1, IntPtr item2); + + [DllImport("user32.dll", EntryPoint = "SetWindowPos")] + public static extern bool SetWindowPos(int hWnd, int hWndOrder, int x, int y, int width, int height, uint flags); + + [DllImport("user32.dll")] + public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo); + + public static void SetFormPos(Form form, int hWndOrder, uint flags){ + SetWindowPos(form.Handle.ToInt32(),hWndOrder,form.Left,form.Top,form.Width,form.Height,flags); + } + + public static void SimulateMouseClick(MouseButton button){ + int flagHold, flagRelease; + + switch(button){ + case MouseButton.Left: + flagHold = SystemInformation.MouseButtonsSwapped ? MOUSEEVENTF_RIGHTDOWN : MOUSEEVENTF_LEFTDOWN; + flagRelease = SystemInformation.MouseButtonsSwapped ? MOUSEEVENTF_RIGHTUP : MOUSEEVENTF_LEFTUP; + break; + + case MouseButton.Right: + flagHold = SystemInformation.MouseButtonsSwapped ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_RIGHTDOWN; + flagRelease = SystemInformation.MouseButtonsSwapped ? MOUSEEVENTF_LEFTUP : MOUSEEVENTF_RIGHTUP; + break; + + default: return; + } + + mouse_event(flagHold,Cursor.Position.X,Cursor.Position.Y,0,0); + mouse_event(flagRelease,Cursor.Position.X,Cursor.Position.Y,0,0); + } + } +} diff --git a/Migration/MigrationManager.cs b/Migration/MigrationManager.cs index 3078c771..809c99bd 100644 --- a/Migration/MigrationManager.cs +++ b/Migration/MigrationManager.cs @@ -8,6 +8,7 @@ using Microsoft.Win32; using TweetDck.Core.Other; using TweetDck.Migration.Helpers; +using TweetDck.Core.Utils; namespace TweetDck.Migration{ static class MigrationManager{ @@ -143,7 +144,7 @@ private static bool BeginMigration(MigrationDecision decision, Action<Exception> } } - Program.SHChangeNotify(0x8000000,0x1000,IntPtr.Zero,IntPtr.Zero); // refreshes desktop + NativeMethods.SHChangeNotify(0x8000000,0x1000,IntPtr.Zero,IntPtr.Zero); // refreshes desktop // uninstall in the background string guid = ProgramRegistrySearch.FindByDisplayName("TweetDeck"); diff --git a/Program.cs b/Program.cs index 500945fd..0e0ae641 100644 --- a/Program.cs +++ b/Program.cs @@ -2,7 +2,6 @@ using System.Diagnostics; using System.Globalization; using System.IO; -using System.Runtime.InteropServices; using System.Text; using System.Windows.Forms; using CefSharp; @@ -38,18 +37,6 @@ public static string LogFile{ } } - [DllImport("kernel32.dll", CharSet = CharSet.Auto)] - public static extern IntPtr LoadLibrary(string name); - - [DllImport("Shell32.dll")] - public static extern int SHChangeNotify(int eventId, int flags, IntPtr item1, IntPtr item2); - - [DllImport("user32.dll", EntryPoint = "SetWindowPos")] - public static extern bool SetWindowPos(int hWnd, int hWndOrder, int x, int y, int width, int height, uint flags); - - [DllImport("user32.dll")] - public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo); - [STAThread] private static void Main(){ Application.EnableVisualStyles(); diff --git a/TweetDck.csproj b/TweetDck.csproj index 0c5a7cf1..7ee86a37 100644 --- a/TweetDck.csproj +++ b/TweetDck.csproj @@ -139,6 +139,7 @@ <DependentUpon>TrayIcon.cs</DependentUpon> </Compile> <Compile Include="Core\Utils\BrowserUtils.cs" /> + <Compile Include="Core\Utils\NativeMethods.cs" /> <Compile Include="Core\Utils\UpdateInfo.cs" /> <Compile Include="Migration\FormMigrationQuestion.cs"> <SubType>Form</SubType>