public static bool SendMessage(IntPtr handle, string args) { if (handle == IntPtr.Zero) { handle = FindWindow(null, MainFormName); if (handle == IntPtr.Zero) { return(false); } } WindowsMessageHelper.CopyDataStruct cds = new WindowsMessageHelper.CopyDataStruct(); try { cds.cbData = (args.Length + 1) * 2; cds.lpData = WindowsMessageHelper.LocalAlloc(0x40, cds.cbData); Marshal.Copy(args.ToCharArray(), 0, cds.lpData, args.Length); cds.dwData = (IntPtr)1; WindowsMessageHelper.SendMessage(handle, WindowsMessageHelper.WM_COPYDATA, IntPtr.Zero, ref cds); return(true); } catch { return(false); } finally { cds.Dispose(); } }
private static void HandleCommand(IntPtr handle) { var commandLineArgs = Environment.GetCommandLineArgs(); if (commandLineArgs.Length > 1 && commandLineArgs[1].StartsWith(WindowsMessageHelper.COMMAND_PREFIX)) { // It is a Jump List command. string temp = commandLineArgs[1].Split(':').LastOrDefault(); int commandNumber; if (int.TryParse(temp, out commandNumber)) { WindowsMessageHelper.SendMessage(handle, commandNumber); } } else { var args = string.Join(" ", commandLineArgs.Skip(1).ToArray()); WindowsMessageHelper.SendMessage(handle, args); } }