Beispiel #1
0
        private static IntPtr HandleMessages(IntPtr handle, int message, IntPtr wParameter, IntPtr lParameter, ref Boolean handled)
        {
            if (handle != MainWindow.WindowHandle)
            {
                return(IntPtr.Zero);
            }

            var data = UnsafeNative.GetMessage(message, lParameter);

            if (data != null)
            {
                if (Application.Current.MainWindow == null)
                {
                    return(IntPtr.Zero);
                }

                if (Application.Current.MainWindow.WindowState == WindowState.Minimized)
                {
                    Application.Current.MainWindow.WindowState = WindowState.Normal;
                }

                UnsafeNative.SetForegroundWindow(new WindowInteropHelper(Application.Current.MainWindow).Handle);

                var args = data.Split(' ');
                HandleParameter(args);
                handled = true;
            }

            return(IntPtr.Zero);
        }
Beispiel #2
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());
            }
        }
Beispiel #3
0
        public static void Main(string[] args)
        {
            App app = new App();

            app.InitializeComponent();
            My.Application.GetSettings();

            var proc           = Process.GetCurrentProcess();
            var processName    = proc.ProcessName.Replace(".vshost", "");
            var runningProcess = Process.GetProcesses()
                                 .FirstOrDefault(x => (x.ProcessName == processName || x.ProcessName == proc.ProcessName || x.ProcessName == proc.ProcessName + ".vshost") && x.Id != proc.Id);


            bool newInstance = true; //false

            if (args.Count() > 0)
            {
                if (args[0].ToLower().StartsWith("prj="))
                {
                    My.Application.Prj_No = args[0].ToUpper().Replace("PRJ=", "");
                }
                if (args.Count() > 1 && args[1].ToLower().StartsWith("new"))
                {
                    newInstance = true;
                }
            }

            if (runningProcess == null | newInstance)
            {
                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));
            }
        }
Beispiel #4
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     UnsafeNative.SendMessage(WindowHandle, "ÄääÖÖ*##**(/4324=ß?? ᾁώ");
 }