mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-08 20:34:05 +02:00
Move native methods to a NativeMethods class
This commit is contained in:
parent
3a66fa28ab
commit
03a93ad3f3
@ -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";
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
});
|
||||
}
|
||||
|
56
Core/Utils/NativeMethods.cs
Normal file
56
Core/Utils/NativeMethods.cs
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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");
|
||||
|
13
Program.cs
13
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();
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user