using System; using System.Drawing; using System.Runtime.InteropServices; using System.Windows.Forms; namespace DENEME { public partial class Form1 : Form { public Form1() { InitializeComponent(); } [DllImport("USER32.DLL", CharSet = CharSet.Unicode)] public static extern IntPtr FindWindow(String lpClassName, String lpWindowName); [DllImport("USER32.DLL")] public static extern bool SetForegroundWindow(IntPtr hWnd); public static void bringToFront(string title) { IntPtr handle = FindWindow(null, title); if (handle == IntPtr.Zero) { } else { // SetForegroundWindow(handle); } //PerformRightClick(handle, new Point(20, 15)); PerformRightClick(handle, new Point(25, 15)); } private void button1_Click(object sender, EventArgs e) { bringToFront("Rmos - Alpemix V4.5"); } [DllImport("user32.dll")] static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow); [StructLayout(LayoutKind.Sequential)] struct POINT { public int X; public int Y; } [DllImport("user32.dll")] static extern bool ClientToScreen(IntPtr hWnd, ref POINT lpPoint); [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo); //Mouse actions private const int MOUSEEVENTF_LEFTDOWN = 0x02; private const int MOUSEEVENTF_LEFTUP = 0x04; private const int MOUSEEVENTF_RIGHTDOWN = 0x08; private const int MOUSEEVENTF_RIGHTUP = 0x10; static void PerformRightClick(IntPtr hwnd, Point p) { POINT point = new POINT() { X = p.X, Y = p.Y }; ClientToScreen(hwnd, ref point); Cursor.Position = new Point(point.X, point.Y); uint X = (uint)Cursor.Position.X; uint Y = (uint)Cursor.Position.Y; mouse_event(MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP, X, Y, 0, 0); mouse_event(MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP, X, Y, 0, 0); } } } |