Exemple #1
0
        //static Win32APIs.COPYDATASTRUCT data;

        public static void SendMsgData(String message, String processOrWindowName, Boolean isSendToOnlyOne = false)
        {
            Win32APIs.COPYDATASTRUCT data = new Win32APIs.COPYDATASTRUCT();

            data.dwData = (IntPtr)(1024 + 604);

            data.cbData = (uint)message.Length * sizeof(char);

            data.lpData = message;

            IntPtr handle;

            try
            {
                Process[] process = Process.GetProcessesByName(processOrWindowName);

                if (process.Length == 0)
                {
                    handle = Win32APIs.FindWindow(null, processOrWindowName);
                    if (handle.ToInt32() > 0)
                    {
                        Win32APIs.SendMessage(handle, Win32APIs.WM_COPYDATA, IntPtr.Zero, ref data);
                    }
                }
                else
                {
                    for (int i = 0; i < process.Length; i++)
                    {
                        handle = process[i].MainWindowHandle;
                        if (handle.ToInt32() > 0)
                        {
                            Win32APIs.SendMessage(handle, Win32APIs.WM_COPYDATA, IntPtr.Zero, ref data);
                            if (isSendToOnlyOne)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            catch {
                handle = Win32APIs.FindWindow(null, processOrWindowName);
                if (handle.ToInt32() > 0)
                {
                    Win32APIs.SendMessage(handle, Win32APIs.WM_COPYDATA, IntPtr.Zero, ref data);
                }
            }
            if (Logger != null)
            {
                try
                {
                    TextWriter writer = TextWriter.Synchronized(Logger);
                    writer.WriteLine(message);
                }
                catch (ObjectDisposedException) { }
            }
        }
Exemple #2
0
 public static bool GetKeyState(Keys key)
 {
     if ((Win32APIs.GetKeyState((int)key) & 0xffff) != 0)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemple #3
0
        public static IntPtr SendMessage(String processName, UInt32 Msg, UInt32 wParam = 0, Boolean isSendToOnlyOne = false, Win32APIs.COPYDATASTRUCT lParam = (new Win32APIs.COPYDATASTRUCT()))
        {
            Win32APIs.COPYDATASTRUCT data = lParam;
            IntPtr blankHandle            = Win32APIs.FindWindow(null, "___NO_IT'S NOT A WINDOW___");
            IntPtr handle;
            IntPtr result = IntPtr.Zero;

            try
            {
                Process[] process = Process.GetProcessesByName(processName);

                if (process.Length == 0)
                {
                    handle = Win32APIs.FindWindow(null, processName);
                    if (handle != blankHandle && handle.ToInt32() > 0)
                    {
                        Win32APIs.SendMessage(handle, Msg, (IntPtr)wParam, ref data);
                    }
                }
                else
                {
                    for (int i = 0; i < process.Length; i++)
                    {
                        handle = process[i].MainWindowHandle;
                        if (handle != blankHandle && handle.ToInt32() > 0)
                        {
                            result = Win32APIs.SendMessage(handle, Msg, (IntPtr)wParam, ref data);
                            if (isSendToOnlyOne)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            catch
            {
                handle = Win32APIs.FindWindow(null, processName);
                if (handle != blankHandle && handle.ToInt32() > 0)
                {
                    result = Win32APIs.SendMessage(handle, Msg, (IntPtr)wParam, ref data);
                }
            }
            return(result);
        }
Exemple #4
0
 public static void KeyToggleOn(Keys key)
 {
     Win32APIs.keybd_event((byte)key, (byte)0, 2, 0);
     Win32APIs.keybd_event((byte)key, (byte)0, 0, 0);
 }