Exemplo n.º 1
0
        public static void SendMessage(IntPtr hwnd, String message)
        {
            var messageBytes = Encoding.Unicode.GetBytes(message); /* ANSII encoding */
            var data         = new UnsafeNative.COPYDATASTRUCT {
                dwData = IntPtr.Zero,
                lpData = message,
                cbData = messageBytes.Length + 1 /* +1 because of \0 string termination */
            };

            if (UnsafeNative.SendMessage(hwnd, WM_COPYDATA, IntPtr.Zero, ref data) != 0)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }
        }
Exemplo n.º 2
0
        public static void Main(String[] args)
        {
            var proc        = Process.GetCurrentProcess();
            var processName = proc.ProcessName.Replace(".vshost", "");
            // NOTE: poor performance !
            var runningProcess = Process.GetProcesses()
                                 .FirstOrDefault(x => (x.ProcessName == processName || x.ProcessName == proc.ProcessName || x.ProcessName == proc.ProcessName + ".vshost") && x.Id != proc.Id);

            if (runningProcess == null)
            {
                var app = new App();
                app.InitializeComponent();
                var window = new MainWindow();
                MainWindow.HandleParameter(args);
                app.Run(window);
                return; // In this case we just proceed on loading the program
            }

            if (args.Length > 0)
            {
                UnsafeNative.SendMessage(runningProcess.MainWindowHandle, String.Join(" ", args));
            }
        }